Copy a complete chart to another one ?

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
moelski
Advanced
Posts: 212
Joined: Mon Apr 23, 2007 12:00 am
Location: Germany
Contact:

Copy a complete chart to another one ?

Post by moelski » Wed Jan 02, 2008 8:14 am

Hi support,

after I get the information from Pep that the templates are not designed for changing the appearance of a chart I started writing my own code. But I wont get it working to copy a chart from one chart to another.

What I wanna do is the following:
I want to load a chart template to a temporary chart which is created by code. Then I copy the data from my original chart to the temp chart. After that I want to overwrite the original chart to the temp chart.

I hope this is the correct way. I read here in the forum that I have to manually assign the series to the data. But I have no idea how to do this.

This is the code I used to create a Chart, load a template to it and copy the data:

Code: Select all

procedure TForm12.dxBarButton3Click(Sender: TObject); 
var 
  tmpChart      : TChart; 
  I             : Word; 
begin 
  tmpChart := TChart.Create(Self); 
  tmpChart.Parent := Self; 

  LoadChartfromFile(TCustomChart(tmpChart), 'Template.tee'); //OpenDialog1.FileName); 

  for I := 0 to Chart1.SeriesCount - 1 do begin 
    tmpChart[I].AssignValues(Chart1[I]); 
  end;
But I have no idea how to copy the tempchart over the org chart and how I have to assign the series to the data.

Could you please give me a simple example how I can realize this? If it is helpfull I can give you a sample application with my code I have written until now.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Jan 02, 2008 11:17 am

Hi Dominik,

You can clone chart series as described here.

You may also be interested on what Marjan suggested here.

Hope this helps!
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

moelski
Advanced
Posts: 212
Joined: Mon Apr 23, 2007 12:00 am
Location: Germany
Contact:

Post by moelski » Wed Jan 02, 2008 2:26 pm

Hi Narcis,

I think that this won´t result in that what I need.

If I use the clone CloneChartSeries methode the wohle series will be copied including properties like the color, thickness, ... (Correct me if I´m wrong). And that´s what I don´t need. In this case the important properties of the loaded template would be destroyed.

Let me explain a little bit more detailed what i want to do:
In general I want to use a stored template file (*.tee) for an available chart. Please have a look at this post : http://www.teechart.net/support/viewtopic.php?t=7108 That´s what I wanna do. And Pep told me that there is no easy way to use a template for a chart without destroying the chart data.

So I started creating a temparay chart:

Code: Select all

  tmpChart := TChart.Create(Self);
  tmpChart.Parent := Self;
Then I loaded a template file to that chart:

Code: Select all

LoadChartfromFile(TCustomChart(tmpChart), 'Template.tee');
Keep in mind that the number of series is exactly the same as in the original chart. And it is the same series type (fastline).

After that I started copying the data from the original Chart to the temporary chart:

Code: Select all

  for I := 0 to Chart1.SeriesCount - 1 do begin
    tmpChart[I].AssignValues(Chart1[I]);
  end;
At this point you it would be no good idea to use CloneChartSeries because it would overwrite some of the properties which where loaded from the template file.

And after this step I have no idea how to continue. Must I assign the data to the series after this step? How can I do this?

And then I have to copy the temporary chart over the original chart. I tried this:

Code: Select all

OrgChart1.Assign(TmpChart);
But that won´t work for me. So how can I do this?

Hopefully you can give me some additional information because it is a really important function for our users.

The result of this whole procedure should be the following:
Use a template file to change the appearance of an existing chart (with data). The template file has the same number and type of series like in the original chart.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Jan 02, 2008 3:14 pm

Hi Dominik,

Ok, thanks for the information. I see Pep suggestion is the same I was thinking. You'd better export your original chart data into any data exporting formats supported as can be shown in the Exporting data at Tutorial 12 - Exporting and Importing Charts. After having loaded the template file you can load original data again as you can see in the All Features\Welcome!\Components\Text Source and All Features\Welcome!\Components\XML Import Source examples in the new features demo.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

moelski
Advanced
Posts: 212
Joined: Mon Apr 23, 2007 12:00 am
Location: Germany
Contact:

Post by moelski » Wed Jan 02, 2008 4:30 pm

Hi Narcis,

ok this is what I did (ChartSave : TStream):

Code: Select all

procedure TForm12.dxBarButton5Click(Sender: TObject);
begin
  ChartSave := TMemoryStream.Create;

 // Chart exportieren in Stream ....
 { nil = all series in Chart1 }
  with TSeriesDataText.Create(Chart1, nil) do
  try
    TextDelimiter:=',' ;  { try also: TeeTabDelimiter }
    IncludeIndex := True;
    SaveToStream(ChartSave);
  finally
    Free;
  end;

  // Chart1 leeren
  Chart1.FreeAllSeries;

  // Template laden
  LoadChartfromFile(TCustomChart(Chart1), 'Template.tee'); //OpenDialog1.FileName);

  // Daten wieder einlesen
  //Series1.Clear;
  SeriesTextSource1.Active := True;
  SeriesTextSource1.Series := Chart1[0];
  SeriesTextSource1.LoadFromStream(ChartSave);
end;
If I execute this code all the data on series "Chart1[0]" is 0. But I take a look into the Stream and the data is available.

Where is my mistake? And is it possible to use this notation:
SeriesTextSource1.Series := Chart1[0]; ??

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Jan 03, 2008 9:10 am

Hi Dominik,

You need to use TextSource like the example I posted here.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply