
WCChart - How to create Horiz Line, problem with Displaying Markers
Hello,
I am trying to create a line chart.
What I want:
1.A constant horizontal line at 1.966 accross the entire grid
2.A constant horizontal line at 1.954 accross the entire grid
3.A constant horizontal line at 1.961 accross the entire grid
4.A varying linechart with circle markers
Problem:
I could not find a way to specify a constant horizontal line at a specified
position on the chart.
Tries: Create a constant series at specified values. Problem displaying
markers on one series and not on another. Which ever type is defined last
sets the Marker.Type for the all the series in the chart.
At an attempt to create a markerless horizontal line I first tried to set
the series Type= chChartTypeLine. Markers appeared on the chart anyway.
Then I tried to let the chart type have markers and then set the marker
style to none.Type = chChartTypeLineMarkers .Marker.Style =
chMarkerStyleNone This did not work either I still saw markers on everything
or markers on nothing depending upon order of the series.
Please find the attached snippet that documents the problem. Any help is
much appreciated.
Thanks,
Scott
To run the following snippet: Add the Microsoft Office Components 9.0
1. Open a new project standard.exe
2. add a ChartSpace component
3. Size the ChartSpace component rather large on the form.
4. Select View Code and Add the following code
Private Sub Form_Load()
'Create arrays for the x-values and the y-values
Dim xSnums As Variant, yUprLim As Variant, _
yActual As Variant, yLwrLim As Variant
xSnums = Array("sn001", "sn002", "sn003", _
"sn004", "sn005", "sn006", _
"sn007", "sn008")
'Attempt to create a horizontal line in the chart with a series
yUprLim = Array(1.966, 1.966, 1.966, 1.966, _
1.966, 1.966, 1.966, 1.966)
yActual = Array(1.961, 1.962, 1.963, 1.961, _
1.961, 1.964, 1.959, 1.958)
'Attempt to create a horizontal line in the chart with a series
yLwrLim = Array(1.954, 1.954, 1.954, 1.954, _
1.954, 1.954, 1.954, 1.954)
'Create a new chart
Dim oChart As WCChart
ChartSpace1.Clear
ChartSpace1.Refresh
Set oChart = ChartSpace1.Charts.Add
'Add a title to the chart
oChart.HasTitle = True
oChart.Title.Caption = "VT - Storm Tolerance Tracking"
Dim oSeries As WCSeries
'Add a series to the chart with the xSnum and yUprLim value
'from the arrays and set the series type to a line chart
Set oSeries = oChart.SeriesCollection.Add
With oSeries
'Attempt to create a horizontal line without markers
' .Type = chChartTypeLineMarkers
' .Marker.Style = chMarkerStyleNone
.Type = chChartTypeLine
.Caption = "UprLim 1.966"
.SetData chDimCategories, chDataLiteral, xSnum
.SetData chDimValues, chDataLiteral, yUprLim
.Line.Color = "green"
End With
'Add a series to the chart with the x-values and UprLim value
'from the arrays and set the series type to a line chart
Set oSeries = oChart.SeriesCollection.Add
With oSeries
'Attempt to create a horizontal line without markers
' .Type = chChartTypeLineMarkers
' .Marker.Style = chMarkerStyleNone
.Type = chChartTypeLine
.Caption = "LwrLim 1.961"
.SetData chDimCategories, chDataLiteral, xSnum
.SetData chDimValues, chDataLiteral, yLwrLim
.Type = chChartTypeLine
.Line.Color = "green"
End With
ChartSpace1.Refresh
'Add a series to the chart with the xSnum and y-values
'from the arrays and set the series type to a line chart
Set oSeries = oChart.SeriesCollection.Add
With oSeries
.Type = chChartTypeLineMarkers
.Marker.Style = chMarkerStyleCircle
.Caption = "PartNum: This Operation: That "
.SetData chDimCategories, chDataLiteral, xSnum
.SetData chDimValues, chDataLiteral, yActual
.Line.Color = RGB(255, 75, 1)
.Points(2).Interior.Color = "green"
End With
'Add a value axis to the right of the chart for the second series
oChart.Axes.Add oChart.Axes(chAxisPositionLeft).Scaling, _
chAxisPositionRight, chValueAxis
'Format the Value Axes
oChart.Axes(chAxisPositionLeft).NumberFormat = "0.0000"
oChart.Axes(chAxisPositionLeft).MajorUnit = 0.001
oChart.Axes(chAxisPositionBottom).HasMajorGridlines = True
'Show the legend at the bottom of the chart
oChart.HasLegend = True
oChart.Legend.Position = chLegendPositionBottom
End Sub