C
cougarfighter
I am using a chart object and I want a comobobox or listbox to
activate what the graph shows. I am fairly new to this and I don't
think it should be too hard. I just can't seem to get the values into
the array correctly to display them. Also, if it is possible to
create one with a listbox and allow for multiple selections to be
displayed on the graph that would be preferable.
Thanks,
Andrew
Here's what I am trying to do:
Sub Combobox1_Click()
Call CreateGraph()
End Sub
CreateGraph()
Dim Chart1 As ChChart
Dim Series1 As ChSeries
Dim XValues(1 To 25)
Dim DataValues(1 To 25)
ChartSpace1.Clear
' Add a chart to the ChartSpace
Set Chart1 = ChartSpace1.Charts.Add
' Give it a title
With Chart1
.HasTitle = True
.Title.Caption = Date
End With
For r = 1 To 10
XValues(r) = Cells(r, 1)
Select Case ComboBox1.Value
Case 0
DataValues(r) = Cells(r, 2)
Case 1
DataValues(r) = Cells(r, 3)
Case 3
DataValues(r) = Cells(r, 4)
End Select
Next r
' Create a chart series
Set Series1 = Chart1.SeriesCollection.Add
' Specify chart type and data
With Series1
.Type = chChartTypeLine
.Type = chChartTypeColumnClustered
.SetData chDimCategories, chDataLiteral, XValues
.SetData chDimValues, chDataLiteral, DataValues
End With
End Sub
activate what the graph shows. I am fairly new to this and I don't
think it should be too hard. I just can't seem to get the values into
the array correctly to display them. Also, if it is possible to
create one with a listbox and allow for multiple selections to be
displayed on the graph that would be preferable.
Thanks,
Andrew
Here's what I am trying to do:
Sub Combobox1_Click()
Call CreateGraph()
End Sub
CreateGraph()
Dim Chart1 As ChChart
Dim Series1 As ChSeries
Dim XValues(1 To 25)
Dim DataValues(1 To 25)
ChartSpace1.Clear
' Add a chart to the ChartSpace
Set Chart1 = ChartSpace1.Charts.Add
' Give it a title
With Chart1
.HasTitle = True
.Title.Caption = Date
End With
For r = 1 To 10
XValues(r) = Cells(r, 1)
Select Case ComboBox1.Value
Case 0
DataValues(r) = Cells(r, 2)
Case 1
DataValues(r) = Cells(r, 3)
Case 3
DataValues(r) = Cells(r, 4)
End Select
Next r
' Create a chart series
Set Series1 = Chart1.SeriesCollection.Add
' Specify chart type and data
With Series1
.Type = chChartTypeLine
.Type = chChartTypeColumnClustered
.SetData chDimCategories, chDataLiteral, XValues
.SetData chDimValues, chDataLiteral, DataValues
End With
End Sub