steve harris
New Member
- Joined
- Dec 31, 2005
- Messages
- 4
I'm using EXCEL 2007
I want to overlay a line graph over a stock chart so that the line graph is not connected to the HiLoLines of the Stock Chart. It seems to me putting the line graph data into a new ChartGroup object would allow me to do what I need. Here's the code I've tested so far:
Sub gen_stock_chart()
'
' gen_stock_chart Macro
'
Dim i As Long
'
Range("D1:F32").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range("'Sheet1'!$D$1:$F$32")
ActiveChart.ChartType = xlStockHLC
series1 = ActiveChart.SeriesCollection(1).Values
series2 = ActiveChart.SeriesCollection(2).Values
series3 = ActiveChart.SeriesCollection(3).Values
For i = 1 To ActiveChart.SeriesCollection(1).Points.Count
ActiveChart.SeriesCollection(1).Points(i).MarkerStyle = xlMarkerStyleDash
ActiveChart.SeriesCollection(1).Points(i).MarkerBackgroundColor = RGB(128, 128, 128) 'gray
ActiveChart.SeriesCollection(1).Points(i).MarkerForegroundColor = RGB(128, 128, 128) 'gray
ActiveChart.SeriesCollection(2).Points(i).MarkerStyle = xlMarkerStyleDash
ActiveChart.SeriesCollection(2).Points(i).MarkerBackgroundColor = RGB(128, 128, 128) 'gray
ActiveChart.SeriesCollection(2).Points(i).MarkerForegroundColor = RGB(128, 128, 128) 'gray
ActiveChart.SeriesCollection(3).Points(i).MarkerStyle = xlMarkerStyleCircle
ActiveChart.SeriesCollection(3).Points(i).MarkerSize = 4#
ActiveChart.SeriesCollection(3).Points(i).MarkerBackgroundColor = RGB(255, 0, 255) 'purple
ActiveChart.SeriesCollection(3).Points(i).MarkerForegroundColor = RGB(255, 0, 255) 'purple
Next
' This is where the problem lies... using the same ChartGroup connects series4 points with the same line as for the other series.
' Default is ChartGroups(1).HasHiLoLines = TRUE. I turned it FALSE and ALL the lines went away.
' If I could force series4 into ChartGroups(2) I could turn off HiLoLines just for that series.
' Is there a way to do that? Everything I've tried has failed. (All the code here works.)
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(4).Name = "='Sheet1'!$C$1"
ActiveChart.SeriesCollection(4).Values = "='Sheet1'!$C$2:$C$32"
series4 = ActiveChart.SeriesCollection(4).Values
For i = 1 To ActiveChart.SeriesCollection(1).Points.Count
ActiveChart.SeriesCollection(4).Points(i).MarkerStyle = xlMarkerStyleCircle
If series4(i) < series2(i) Or series4(i) > series1(i) Then 'I want these points dis-connected!!!
ActiveChart.SeriesCollection(4).Points(i).MarkerBackgroundColor = RGB(255, 0, 0) 'red
ActiveChart.SeriesCollection(4).Points(i).MarkerForegroundColor = RGB(255, 0, 0) 'red
Else
ActiveChart.SeriesCollection(4).Points(i).MarkerBackgroundColor = RGB(0, 255, 0) 'green
ActiveChart.SeriesCollection(4).Points(i).MarkerForegroundColor = RGB(0, 255, 0) 'green
End If
Next
End Sub
I want to overlay a line graph over a stock chart so that the line graph is not connected to the HiLoLines of the Stock Chart. It seems to me putting the line graph data into a new ChartGroup object would allow me to do what I need. Here's the code I've tested so far:
Sub gen_stock_chart()
'
' gen_stock_chart Macro
'
Dim i As Long
'
Range("D1:F32").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range("'Sheet1'!$D$1:$F$32")
ActiveChart.ChartType = xlStockHLC
series1 = ActiveChart.SeriesCollection(1).Values
series2 = ActiveChart.SeriesCollection(2).Values
series3 = ActiveChart.SeriesCollection(3).Values
For i = 1 To ActiveChart.SeriesCollection(1).Points.Count
ActiveChart.SeriesCollection(1).Points(i).MarkerStyle = xlMarkerStyleDash
ActiveChart.SeriesCollection(1).Points(i).MarkerBackgroundColor = RGB(128, 128, 128) 'gray
ActiveChart.SeriesCollection(1).Points(i).MarkerForegroundColor = RGB(128, 128, 128) 'gray
ActiveChart.SeriesCollection(2).Points(i).MarkerStyle = xlMarkerStyleDash
ActiveChart.SeriesCollection(2).Points(i).MarkerBackgroundColor = RGB(128, 128, 128) 'gray
ActiveChart.SeriesCollection(2).Points(i).MarkerForegroundColor = RGB(128, 128, 128) 'gray
ActiveChart.SeriesCollection(3).Points(i).MarkerStyle = xlMarkerStyleCircle
ActiveChart.SeriesCollection(3).Points(i).MarkerSize = 4#
ActiveChart.SeriesCollection(3).Points(i).MarkerBackgroundColor = RGB(255, 0, 255) 'purple
ActiveChart.SeriesCollection(3).Points(i).MarkerForegroundColor = RGB(255, 0, 255) 'purple
Next
' This is where the problem lies... using the same ChartGroup connects series4 points with the same line as for the other series.
' Default is ChartGroups(1).HasHiLoLines = TRUE. I turned it FALSE and ALL the lines went away.
' If I could force series4 into ChartGroups(2) I could turn off HiLoLines just for that series.
' Is there a way to do that? Everything I've tried has failed. (All the code here works.)
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(4).Name = "='Sheet1'!$C$1"
ActiveChart.SeriesCollection(4).Values = "='Sheet1'!$C$2:$C$32"
series4 = ActiveChart.SeriesCollection(4).Values
For i = 1 To ActiveChart.SeriesCollection(1).Points.Count
ActiveChart.SeriesCollection(4).Points(i).MarkerStyle = xlMarkerStyleCircle
If series4(i) < series2(i) Or series4(i) > series1(i) Then 'I want these points dis-connected!!!
ActiveChart.SeriesCollection(4).Points(i).MarkerBackgroundColor = RGB(255, 0, 0) 'red
ActiveChart.SeriesCollection(4).Points(i).MarkerForegroundColor = RGB(255, 0, 0) 'red
Else
ActiveChart.SeriesCollection(4).Points(i).MarkerBackgroundColor = RGB(0, 255, 0) 'green
ActiveChart.SeriesCollection(4).Points(i).MarkerForegroundColor = RGB(0, 255, 0) 'green
End If
Next
End Sub