Go4Expert (http://www.go4expert.com/)
-   Visual Basic ( VB ) (http://www.go4expert.com/forums/visual-basic/)
-   -   Problem plotting xyscatterchart using arrays (http://www.go4expert.com/forums/plotting-xyscatterchart-using-arrays-t22163/)

sharathdude 21May2010 18:08

Problem plotting xyscatterchart using arrays
1 Attachment(s)
Hello everyone

I am trying to plot a Xyscatter chart using arrays inside a chartspace. My code is as follows

Private Sub CommandButton1_Click()

'Create arrays for the x-values and the y-values
'Dim xValues As Variant, yValues1 As Variant, yValues2 As Variant
Dim ext_boom As Integer
Dim xValues(2182), yValues(2182) As Variant

For ext_boom = 1380 To 2182 Step 1
[c53].Value = ext_boom
xValues(ext_boom) = [c62].Value
yValues(ext_boom) = [c63].Value

ChartSpace1.Height = 494
ChartSpace1.Width = 556
Dim chConstants
Dim Spreadsheet1 As OWC10.Spreadsheet

'Set the data source of the chart to the Spreadsheet control.
Set Spreadsheet1 = CreateObject("OWC10.Spreadsheet")
Spreadsheet1.Range("A1", "Z1000") = Sheet1.Range("A1", "Z1000").Value
Set ChartSpace1.DataSource = Spreadsheet1
Set chConstants = ChartSpace1.Constants

'Create a Xy scatter chart chart.
ChartSpace1.Charts(0).Type = chChartTypeScatterLine

'Set oChart = ChartSpace1.Charts.Add
'Add a title to the chart
'oChart.HasTitle = True
'oChart.Title.Caption = "WORK ENVELOPE"

With ChartSpace1.Charts(0)
.SeriesCollection(0).SetData chConstants.chDimSeriesNames, chConstants.chDataBound, "a2"
.SeriesCollection(0).SetData chConstants.chDimValues, chDataLiteral, xValues(2182)
.SeriesCollection(0).SetData chConstants.chDimValues, chDataLiteral, yValues(2182)
.SeriesCollection(0).Line.Color = "black"
.SeriesCollection(0).Line.Weight = xlThin
.SeriesCollection(0).Line.Miter = xlContinuous

'Add a series to the chart with the x-values and y-values
'from the arrays and set the series type to a column chart
'Dim oSeries As WCSeries
'Set oSeries = oChart.SeriesCollection.Add
'With oSeries
'.SetData chDimValues, chDataLiteral, xValues
'.SetData chDimValues, chDataLiteral, yValues
'.Type = chChartTypeScatterLine

End With
End Sub


I get error " The specified chart dimension is not valid for current chart type"
in the line
.SeriesCollection(0).SetData chConstants.chDimValues, chDataLiteral, xValues(2182)

Please help me to correct the code. I am also attaching my workbook

All times are GMT +5.5. The time now is 03:48.