Page 1 of 1

Duplicate chart with custom axes

Posted: Mon Jan 29, 2018 10:52 am
by 16582575
VCL/FMX TeeChart ver 2017.22.170619, Delphi 10.2 Version 25.0.27659.1188

If there are custom axes on a chart, CloneChart does not copy them. The only way to duplicate such chart appears to be Save it to Stream and Load the stream in the new chart.
if Master is the original chart and clone is its duplicate, I get the following results:
Clone.Assign(Master):
ss_Assign.png
ss_Assign.png (33.82 KiB) Viewed 8734 times

Code: Select all

  CloneChart(clone, master, self, FALSE):
ss_Clone.png
ss_Clone.png (30.57 KiB) Viewed 8732 times
When I use save to/load from stream, I get proper results. A simple project is attached. Use Edit->Copy(Assign), Edit->Copy(Clone) and Edit->Copy(Stream) to see the effects.

Roumen

Re: Duplicate chart with custom axes

Posted: Mon Jan 29, 2018 2:37 pm
by yeray
Hello,

This sounds as the very same ticket #780, isn't it?

Re: Duplicate chart with custom axes

Posted: Mon Jan 29, 2018 4:30 pm
by 16582575
Thank you for the quick reply. I will need to use one of the suggested workarounds. Not sure why I did not find the topic.

It is disappointing that the problem was reported in 2013 and in 2018 CloneChart is not doing what it is supposed to do still...

Best regards
Roumen

Re: Duplicate chart with custom axes

Posted: Tue Jan 30, 2018 10:31 am
by yeray
Hello Roumen,
roumen wrote:It is disappointing that the problem was reported in 2013 and in 2018 CloneChart is not doing what it is supposed to do still...
You are right. I've revised the ticket #780 and just implemented a fix for it.
Since you own the TeeChart sources - and it's pretty simple - you can implement it and (Tee)Recompile them.
At CloneChart method in Chart.pas, add this after the loop where the series are cloned:

Code: Select all

procedure CloneChart(const Dest,Origin:TCustomChart; const AOwner:TComponent; ForceManualData:Boolean);
//...
  for t:=0 to Origin.SeriesCount-1 do
  begin
    //...
      CloneChartSeries(Origin[t],AOwner,Dest);
    //...
  end;

  // Relink Custom Axes within Destination Series
  for t:=0 to Origin.SeriesCount-1 do
  begin
    if Origin[t].CustomVertAxis <> nil then
       Dest[t].CustomVertAxis:=Dest.CustomAxes[Origin[t].CustomVertAxis.Index];

    if Origin[t].CustomHorizAxis <> nil then
       Dest[t].CustomHorizAxis:=Dest.CustomAxes[Origin[t].CustomHorizAxis.Index];
  end;
  //...
At the end of the TChartAxis.Assign method in TeEngine.pas, add this:

Code: Select all

procedure TChartAxis.Assign(Source: TPersistent);
Begin
  if Source is TChartAxis then
  With TChartAxis(Source) do
  Begin
    //...
    Self.FPartnerAxis         :=FPartnerAxis;
    Self.FUsePartnerAxis      :=FUsePartnerAxis;
  end
  else inherited;
end;