ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Charts with Combobox (https://www.excelbanter.com/excel-programming/387259-charts-combobox.html)

[email protected]

Charts with Combobox
 
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


Jon Peltier

Charts with Combobox
 
Here's a different approach:

http://peltiertech.com/Excel/Charts/ChartByControl.html

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


wrote in message
ups.com...
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




[email protected]

Charts with Combobox
 
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

On Apr 13, 8:48 am, "Jon Peltier"
wrote:
Here's a different approach:

http://peltiertech.com/Excel/Charts/ChartByControl.html

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutionshttp://PeltierTech.com
_______

wrote in message

ups.com...

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





All times are GMT +1. The time now is 11:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com