LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default help with chart script and data labels

Below is some code I've written which populates a scatter graph with data
extracted from a different work sheet. What I can't work out is changing
the data label names. The script loops through each plot value (case) and
for each iteration I would have liked to change the data label but not its
value....any suggestions?

Public Sub xyGraphs()

'Declare Variables
Dim rngDataSource As Range
Dim iDataRowsCt As Long
Dim iSrsIx As Integer
Dim chtChart As Chart
Dim srsNew As Series
Dim riskRating As String
Dim riskScore As Integer
Dim cChtTitle, xAxisTitle As String
Dim xAxisMax, xAxisMin As Date
Dim yAxisTitle As String
Dim yAxisMax, yAxisMin As Integer
Dim hColour As Long
Dim hSize As Integer
Dim pointLableCol, cPointScoreCol, cPointRatingCol As Integer
Dim pointProximityCol As Date
Dim lastCol As Integer
Dim lastrow As Long
Dim redScore, closedCol As Integer
Dim todaysDate As Long
Dim plotLabelCol As Integer
Dim plotLabelVal As Integer
todaysDate = Date


'Set up chart title and other options
cChtTitle = Worksheets("register").Range("K21") 'Current Situation
Chart Title
xAxisTitle = Worksheets("register").Range("K22") 'X Axis Title
yAxisTitle = Worksheets("register").Range("K23") 'Y Axis Title
xAxisMax = Worksheets("register").Range("K27") 'X Axis Maximum
xAxisMin = Worksheets("register").Range("K26") 'X Axis Minimum
yAxisMax = Worksheets("register").Range("K25") 'Y Axis Maximum date
yAxisMin = Worksheets("register").Range("K24") 'Y Axix Minimum Date
hColour = 255 'High colour Red
hSize = 10 'High Size
pointLableCol = 8 'Series Lable column in sheet 1
cPointScoreCol = 2 'Series current scores Column
pointProximityCol = 4 'Series Proximity column
cPointRatingCol = 8 'Series current Risk Rating Colunm
redScore = 20 'Score above which point is coloured
BLACK
closedCol = 3 'Risk is Closed
plotLabelCol = 1 'Column with risk label value

'Activate Source Sheet & select all rows & columns with data
Sheets("Register").Activate
lastCol = ActiveSheet.Range("a1").End(xlToRight).Column
lastrow = ActiveSheet.Cells(65536, 1).End(xlUp).Row
ActiveSheet.Range("a1:" &
ActiveSheet.Cells(lastrow,lastCol).Address).Select
Set rngDataSource = Selection
iDataRowsCt = lastrow
If iDataRowsCt = 1 Then
Application.Goto ActiveWorkbook.Sheets(selectSheet).Range("D30:D30" )
'select cell
MsgBox ("Sorry - There is no data on the selected sheet!")
Exit Sub
End If

'Create the Current situation chart
Sheets("RiskMatrix").Activate
ActiveSheet.ChartObjects("Chart 19").Activate ''select chart
Set chtChart = Application.ActiveChart

ActiveChart.ChartArea.ClearContents ''clear current
contents

With chtChart
.ChartType = xlXYScatterLines
For iSrsIx = 2 To iDataRowsCt 'loop starting at row 2

''if score is not 0 and proximity not nul and it's not closed
then
If rngDataSource.Cells(iSrsIx, cPointScoreCol) < 0 _
And rngDataSource.Cells(iSrsIx, closedCol) < "Live - Draft" _
And rngDataSource.Cells(iSrsIx, pointProximityCol) < "" Then

'' Add each series
Set srsNew = .SeriesCollection.NewSeries
With srsNew
riskRating =
rngDataSource.Cells(iSrsIx,cPointRatingCol) ''set the case variable
.Name = rngDataSource.Cells(iSrsIx, pointLableCol)
.Values = rngDataSource.Cells(iSrsIx,cPointScoreCol)
.XValues =
rngDataSource.Cells(iSrsIx,pointProximityCol)
Select Case riskRating
Case "Very Severe"
.MarkerBackgroundColor = hColour
.MarkerForegroundColor = hColour
.MarkerSize = hSize
.MarkerStyle = xlMarkerStyleTriangle
Case "Severe"
.MarkerBackgroundColorIndex = 46
.MarkerForegroundColorIndex = 46
.MarkerSize = hSize
.MarkerStyle = xlMarkerStyleTriangle
Case "Material"
.MarkerBackgroundColorIndex = 44
.MarkerForegroundColorIndex = 44
.MarkerSize = hSize
.MarkerStyle = xlMarkerStyleTriangle
Case "Manageable"
.MarkerBackgroundColorIndex = 4
.MarkerForegroundColorIndex = 4
.MarkerSize = hSize
.MarkerStyle = xlMarkerStyleTriangle
End Select
plotLabelVal =
rngDataSource.Cells(iSrsIx,plotLabelCol)
.Smooth = False
.Shadow = False
End With
End If
Next

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pie Chart Data labels Milind Keer[_2_] Excel Discussion (Misc queries) 0 October 2nd 08 04:31 PM
Chart - Data Labels Darren L New Users to Excel 1 December 20th 07 07:44 PM
Pie Chart Data Labels Jake Charts and Charting in Excel 2 July 10th 07 09:42 AM
Pie Chart Data Labels David Benson Charts and Charting in Excel 0 May 24th 06 10:59 PM
Data labels in Chart Laura New Users to Excel 1 May 25th 05 06:33 PM


All times are GMT +1. The time now is 06:45 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"