|
How to save a chart from a button ? |
Posted by Daniel on Aug-07-2013 19:55 |
|
Hi Peter,
I have created a simple pie chart using a pie class that is called in my Form1.
For this I have used the following code :
Dim myChart As New Class01
Dim data()
data = Array(1, 1, 2, 22, 11, 3, 3, 2)
Call myChart.CreateChart(data, vbNullString)
Form3.Show
As you can see attached, the Form3 is the output of my chart. On the bottom side of the
form I have a simple button so that to save the chart displayed above. But now I have
difficulties to use the following command : c.makeChart ("C:\\Daniel\\Desktop\\myChart.png"),
where c is declared in the pie class as Dim c As PieChart.
So, at the moment I am stuck in something like this :
Private Sub saveChart_Click()
Dim c As PieChart
c.makeChart ("C:\\Daniel\\Desktop\\myChart.png")
End Sub
Is there any possibility to save the chart using the click event of the button ? Thank you in
advance.
Regards,
Daniel
PS. The language used is VB6
|
Re: How to save a chart from a button ? |
Posted by Peter Kwan on Aug-07-2013 23:35 |
|
Hi Daniel,
It is not clear to me where is the PieChart in your code, and it is not clear to me why the PieChart would end up inside Form3, and how the chart is displayed in Form3 (is it using BaseChart.makePicture?). I would guess that somewhere in CreateChart, the code must have put the chart or the picture into Form3. So one method is for CreateChart to also put the PieChart object into Form3 (store it in some Form variable inside Form3). In this way, you can obtain the original PieChart object in Form3. If the chart is created using BaseChart.makePicture, another method is to use the standard VB6
SavePicture statement to save the picture to a file. See:
http://msdn.microsoft.com/en-us/library/aa445827(v=vs.60).aspx
Hope this can help.
Regards
Peter Kwan |
Re: How to save a chart from a button ? |
Posted by Daniel on Aug-08-2013 19:38 |
|
Hi Peter,
Thank you for your quick reply. Indeed, the VB SavePicture statement works properly but I
wonder if instead of it I would use the ChartDirector native makeChart function. For a
better understanding I have created a simplified schema of my app and I attached it as
archive. Is this way of calling feasible for you ? I just mention that my chart has to be
displayed outside of the main form ( Form1). Thank you in advance.
Regards,
Daniel
|
Re: How to save a chart from a button ? |
Posted by Peter Kwan on Aug-08-2013 22:22 |
|
Hi Daniel,
Yes. You can use the ChartDirector makeChart function if you like. You just need to store the PieChart object in a location that is accessible from the event handler of your button. Currently, the PieChart is declared as a local object in your function and so is local to your function. You can declare it in global scope if you want to. Then it would be accessible by any code in your project.
Hope this can help.
Regards
Peter Kwan |
|