Page 1 of 1

Duplicate a chart

Posted: Tue Feb 24, 2009 5:15 pm
by 10050873
Hello,

On a form at design time i have created a chart with one series.
I would like to create at run time one or several charts with the same series and the same properties than the previous and draw it below the first chart (the series values are not the same).

What is the best way to do that? Is there is a function which could duplicate a chart and its content?

Thank you for help

Regards

Posted: Wed Feb 25, 2009 8:39 am
by yeray
Hi Calou,

I'm afraid there isn't a single function to do this. The simplest way probably is :
- Create your new chart at runtime
- Save your old chart in a tee file
- Import the tee file to the new chart
- Remove all series or clear the data of the new chart
- Verify and copy the original's chart properties that weren't exported to the tee file

If you find problems at any step, please, don't hesitate to let us know.

Posted: Wed Feb 25, 2009 9:39 am
by 10550486
Hello,

You can also do it directly from memory.
For example, in C++ Builder, assuming that vChrt1 is your source chart, this should copy chart properties and data to a new chart:

Code: Select all

  
#include <TeeStore.hpp>
...

  TMemoryStream* pStream = new TMemoryStream;
  SaveChartToStream(vChrt1, pStream, true, true);

  TChart* pTChart = new TChart(this);
  pStream->Position = 0;
  LoadChartFromStream((TCustomChart*)pTChart, pStream);
  pTChart->Parent = this;
  pTChart->Top = vChrt1->Top + vChrt1->Height;
  pTChart->Left = vChrt1->Left;

  delete pStream;