Duplicate chart with custom axes

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
roumen
Newbie
Newbie
Posts: 3
Joined: Fri Dec 15, 2017 12:00 am

Duplicate chart with custom axes

Post by roumen » Mon Jan 29, 2018 10:52 am

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 8994 times

Code: Select all

  CloneChart(clone, master, self, FALSE):
ss_Clone.png
ss_Clone.png (30.57 KiB) Viewed 8992 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
Attachments
_Save.zip
(53.98 KiB) Downloaded 744 times

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Duplicate chart with custom axes

Post by Yeray » Mon Jan 29, 2018 2:37 pm

Hello,

This sounds as the very same ticket #780, isn't it?
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

roumen
Newbie
Newbie
Posts: 3
Joined: Fri Dec 15, 2017 12:00 am

Re: Duplicate chart with custom axes

Post by roumen » Mon Jan 29, 2018 4:30 pm

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

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Duplicate chart with custom axes

Post by Yeray » Tue Jan 30, 2018 10:31 am

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;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply