1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Problem plotting xyscatterchart using arrays

Discussion in 'Visual Basic ( VB )' started by sharathdude, May 21, 2010.

  1. sharathdude

    sharathdude New Member

    May 21, 2010
    Likes Received:
    Trophy Points:
    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

    Attached Files:

Share This Page