wsturdev
asked on
Change MSGraph Chart Type
I have an Access 2003 app that displays MSGraph charts. The chart type as defined on the form is an XY Scatter.
I need to change it dynamically between an XY Scatter and a Bubble 3D. (I know I will have to manipulate the DataSheet that supports the chart.
If the chart is originally defined as a Bubble 3D, and I want to change it to an XY Scatter, then this code works:
GraphObj.ChartType = xlXYScatter
If, however, the chart is originally defined as an XY Scatter, and I want to change it to a 3D Bubble, then this code does NOT work:
GraphObj.ChartType = xlBubble3DEffect
In addition, if it starts as an XY Scatter, and I change it to a 3d Bubble, I cannot change it back. In fact, the chart type is permanently changed on the form.
How can I change it programmatically between an XY Scatter and a 3D Bubble?
I need to change it dynamically between an XY Scatter and a Bubble 3D. (I know I will have to manipulate the DataSheet that supports the chart.
If the chart is originally defined as a Bubble 3D, and I want to change it to an XY Scatter, then this code works:
GraphObj.ChartType = xlXYScatter
If, however, the chart is originally defined as an XY Scatter, and I want to change it to a 3D Bubble, then this code does NOT work:
GraphObj.ChartType = xlBubble3DEffect
In addition, if it starts as an XY Scatter, and I change it to a 3d Bubble, I cannot change it back. In fact, the chart type is permanently changed on the form.
How can I change it programmatically between an XY Scatter and a 3D Bubble?
can you post the codes you are using to change the chartType.
ASKER
I thought I did in my original post.
Here is some slightly expanded code including the creation of the reference to the GraphObj:
Dim GraphObj As Object
Dim DataSheetObj As Object
Set GraphObj = MyForm.MyChart.Object.Appl ication.Ch art
Set DataSheetObj = MyForm.MyChart.Object.Appl ication.Da taSheet
'Code to set chart to XY Scatter
GraphObj.ChartType = xlXYScatter
'Code to set Chart to 3D Bubble
GraphObj.ChartType = xlBubble3DEffect
Here is some slightly expanded code including the creation of the reference to the GraphObj:
Dim GraphObj As Object
Dim DataSheetObj As Object
Set GraphObj = MyForm.MyChart.Object.Appl
Set DataSheetObj = MyForm.MyChart.Object.Appl
'Code to set chart to XY Scatter
GraphObj.ChartType = xlXYScatter
'Code to set Chart to 3D Bubble
GraphObj.ChartType = xlBubble3DEffect
try using the constant values
are you executing the codes in the form where the chart is?
Code to set chart to XY Scatter
GraphObj.ChartType = -4169
'Code to set Chart to 3D Bubble
GraphObj.ChartType = 85
are you executing the codes in the form where the chart is?
Code to set chart to XY Scatter
GraphObj.ChartType = -4169
'Code to set Chart to 3D Bubble
GraphObj.ChartType = 85
ASKER
Same Problem:
-4169 works; 85 does not work.
Run-time Error '1004': Application-defined or object-defined error.
-4169 works; 85 does not work.
Run-time Error '1004': Application-defined or object-defined error.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Okay, I cannot believe, or rather, understand, what I just found out... I inadvertently stumbled into this...
My application has a list of records on the left, each with an item name, an X value, a y value and a comparative size factor, and an "Include in Graph" checkbox.
There is a Graph object on the right that is initially defined as an XY Scatter, but I wanted to give the user the option to switch to a 3D Bubble.
As the user clicks on the "Include in Graph" checkbox for a given record, my logic adds the appropriate values to appropriate cells in the associated DataSheet, so the new values are now plotted in the graph.
I have an option group set up that will let the user flip back and forth between XY Scatter and 3D Bubble.
In all my previous efforts, I was trying to set the type of graph upon arriving at the form, and then build the DataSheet as the user selected records.
To try to understand what was happening, I put breakpoints into my code. So, I set up the form with the initial type of the graph to xlXYScatter, then opened the app in normal view and started clicking on checkboxes. After doing the first one, I hit my first breakpoint and looked at various values. Then I clicked on my second checkbox and again looked at values at the breakpoint.
Then, I absentmindedly clicked on the option group that is intended to change the graph to xlBubble3DEffect. AND THE GRAPH SWITCHED TO 3D BUBBLES!!!!!
Apparently, it is necessary to have some number of points plotted (I know it works with 2 points plotted, and will now test with 1 point) BEFORE switching graph types.
Any ideas why this is?
My application has a list of records on the left, each with an item name, an X value, a y value and a comparative size factor, and an "Include in Graph" checkbox.
There is a Graph object on the right that is initially defined as an XY Scatter, but I wanted to give the user the option to switch to a 3D Bubble.
As the user clicks on the "Include in Graph" checkbox for a given record, my logic adds the appropriate values to appropriate cells in the associated DataSheet, so the new values are now plotted in the graph.
I have an option group set up that will let the user flip back and forth between XY Scatter and 3D Bubble.
In all my previous efforts, I was trying to set the type of graph upon arriving at the form, and then build the DataSheet as the user selected records.
To try to understand what was happening, I put breakpoints into my code. So, I set up the form with the initial type of the graph to xlXYScatter, then opened the app in normal view and started clicking on checkboxes. After doing the first one, I hit my first breakpoint and looked at various values. Then I clicked on my second checkbox and again looked at values at the breakpoint.
Then, I absentmindedly clicked on the option group that is intended to change the graph to xlBubble3DEffect. AND THE GRAPH SWITCHED TO 3D BUBBLES!!!!!
Apparently, it is necessary to have some number of points plotted (I know it works with 2 points plotted, and will now test with 1 point) BEFORE switching graph types.
Any ideas why this is?
ASKER
Oh, and another oddity... Everytime I added a graph point after it switched to bubble chart, the graph got wider by about the width of a bubble!
ASKER
That was it!! Thanks.