Charts with Combobox

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
 
C

cougarfighter

Here's my problem. I am inserting new rows for a new entry. If I use
a normal graph, when I insert a new row it becomes inaccurate.
However, if I use a chart object then I can generate the graph based
on predefined cells and there is no problem with inserting new rows.
I just can't seem to get a list box or combo box to work correctly.

Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top