PC Review


Reply
Thread Tools Rate Thread

Charts with Combobox

 
 
cougarfighter@gmail.com
Guest
Posts: n/a
 
      12th Apr 2007
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

 
Reply With Quote
 
 
 
 
Jon Peltier
Guest
Posts: n/a
 
      13th Apr 2007
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
_______


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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
>



 
Reply With Quote
 
cougarfighter@gmail.com
Guest
Posts: n/a
 
      18th Apr 2007
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" <jonxlmv...@SPAMpeltiertech.com>
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
> _______
>
> <cougarfigh...@gmail.com> wrote in message
>
> news:(E-Mail Removed)...
>
> >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



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to run on all files in a folder but exclude sheets with PivotTable, Pivot Charts and Charts Nasir Microsoft Excel Programming 16 11th Mar 2011 04:13 PM
Aligning tick marks and labels on line charts or scatter charts AdamK Microsoft Excel Discussion 2 18th May 2009 06:20 PM
Copy/Paste Charts; Define Destination of Charts in PowerPoint ryguy7272 Microsoft Excel Programming 2 24th Jan 2008 08:04 PM
Distribute dynamically charts with linked data as stand-alone charts Richard Microsoft Excel Programming 2 31st Mar 2004 05:16 PM
Distribute dynamically charts with linked data as stand-alone charts Richard Microsoft Excel Charting 2 31st Mar 2004 05:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:03 AM.