Clone TChart to TQRChart

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Lenfors
Newbie
Newbie
Posts: 49
Joined: Thu Sep 20, 2007 12:00 am

Clone TChart to TQRChart

Post by Lenfors » Mon Sep 16, 2013 12:23 pm

Hello!

I'm trying to copy my TChart to a TQRChart for printout. Most things seem to work but all my custom axis seems to dissapear!?

AQRChart.Chart.Assign(AChart);
for t:=0 to AChart.SeriesCount-1 do
CloneChartSeries(AChart[t]).ParentChart:=AQRChart.Chart;

I cant find any CloneChartAxis! How do I clone the axis and assign all my cloned series to them?

Best regards, Mikael

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

Re: Clone TChart to TQRChart

Post by Yeray » Tue Sep 17, 2013 2:47 pm

Hi Mikael,

For printing, it may be easier to use a bitmap. You could have a TQRImage in your TQuickRep and then assign the chart bitmap exported with TeeBitmap function.
This works fine for me here:

Code: Select all

procedure TForm1.AssignToImage(AQRImage: TQRImage; AChart: TChart);
var tmpBitmap: TBitmap;
begin
  tmpBitmap:=AChart.TeeCreateBitmap;
  AQRImage.Picture.Bitmap:=tmpBitmap;
  AQRImage.Width:=tmpBitmap.Width;
  AQRImage.Height:=tmpBitmap.Height;
end;
I see the Assign function copies the series and the custom axes from the origin chart to the destination chart. What it isn't copying are the relations between the series and the custom axes. I've added it to the wish list to be revised forfuture releases (TV52016721).

In the meanwhile, if you know the relations, you could manually assing them after the code you posted above, or after calling the CloneChart function:

Code: Select all

  AQRChart.Chart.Assign(AChart);

  for t:=0 to AChart.SeriesCount-1 do
    CloneChartSeries(AChart[t]).ParentChart:=AQRChart.Chart;

  for t:=0 to AQRChart.Chart.SeriesCount-1 do
    AQRChart.Chart[t].CustomVertAxis:=AQRChart.Chart.CustomAxes[t];
Or:

Code: Select all

  CloneChart(AQRChart.Chart, AChart, Self, false);
  for t:=0 to AQRChart.Chart.SeriesCount-1 do
    AQRChart.Chart[t].CustomVertAxis:=AQRChart.Chart.CustomAxes[t];
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

Lenfors
Newbie
Newbie
Posts: 49
Joined: Thu Sep 20, 2007 12:00 am

Re: Clone TChart to TQRChart

Post by Lenfors » Mon Sep 23, 2013 1:47 pm

Hello!

Ok, thanks!

I cant use the BitMap solution as there are several changes done on the printout in respect to the original.

The problem is that i have about 40 series spread over about 30 different scales so your "one to one" copy does not work.
Any easy code to find out which custom axis i should apply each copied serie to?

Regards, Mikael

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

Re: Clone TChart to TQRChart

Post by Narcís » Tue Sep 24, 2013 8:30 am

Hi Mikael,
Any easy code to find out which custom axis i should apply each copied serie to?
The examples with CustomVertAxis and CustomAxes Yeray posted in his last reply don't help with this?
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

Lenfors
Newbie
Newbie
Posts: 49
Joined: Thu Sep 20, 2007 12:00 am

Re: Clone TChart to TQRChart

Post by Lenfors » Wed Sep 25, 2013 1:32 pm

Hello!

No it does not work, if you check his code:

CloneChart(AQRChart.Chart, AChart, Self, false);
for t:=0 to AQRChart.Chart.SeriesCount-1 do
AQRChart.Chart[t].CustomVertAxis:=AQRChart.Chart.CustomAxes[t];

He assumes a 1:1 relationship between the Series and the CustomAxes but some of my Seried share the same axes!

Best regards, Mikael

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

Re: Clone TChart to TQRChart

Post by Narcís » Wed Sep 25, 2013 1:43 pm

Hi Mikael,

I see, it probably should be something like this:

Code: Select all

  for t:=0 to AQRChart.Chart.SeriesCount-1 do
    AQRChart.Chart[t].CustomVertAxis:=AChart.Chart[t].CustomVertAxis;
Where series axes settings are copied from one chart to the other.
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

Lenfors
Newbie
Newbie
Posts: 49
Joined: Thu Sep 20, 2007 12:00 am

Re: Clone TChart to TQRChart

Post by Lenfors » Wed Sep 25, 2013 1:45 pm

Ok, thanks. I'll test it!

Lenfors
Newbie
Newbie
Posts: 49
Joined: Thu Sep 20, 2007 12:00 am

Re: Clone TChart to TQRChart

Post by Lenfors » Mon Sep 30, 2013 8:42 am

Sorry, but I can't make it work!

I'm using TeeChart 8.07, is this maybee the problem. Is this functionality improved in later version?

My latest try is below. The problem is I can't get my custom axes to be copied currectly. On my original Chart I can see 20 series but on my report there are only two. Probably they are to high or low to be visible as their axes are not copied/assigned correctly.

Best regards, MIkael

// Copy chart
QRDataChart.Chart.FreeAllSeries;
QRDataChart.Chart.Assign(DataChart);

// Copy series
For I := 0 To DataChart.SeriesCount - 1 Do
Begin

CloneChartSeries(DataChart).ParentChart := QRDataChart.Chart;
QRDataChart.Chart.Series.CustomVertAxis := DataChart.Series.CustomVertAxis;

End;

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

Re: Clone TChart to TQRChart

Post by Yeray » Tue Oct 01, 2013 3:09 pm

Hi Mikael,

Give it a try to the following. I'm searching for the relations and assigning them accordingly. I'm only doing it only for the CustomVerticalAxis, but you shouldn't find problems to expand it for the CustomHorizontalAxis too if you also need it:

Code: Select all

uses Series;

procedure TForm1.FormCreate(Sender: TObject);
var i, nSeries: Integer;
begin
  nSeries:=4;
  Chart1.View3D:=false;

  for i:=0 to nSeries-1 do
  begin
    Chart1.AddSeries(TLineSeries).FillSampleValues;

    if i>0 then
    begin
      Chart1[i].CustomVertAxis:=Chart1.CustomAxes.Add;
      with Chart1[i].CustomVertAxis do
      begin
        StartPosition:=i*(100/nSeries);
        EndPosition:=(i+1)*(100/nSeries);
        Axis.Color:=Chart1[i].Color;
        LabelsFont.Color:=Chart1[i].Color;
      end;
    end;
  end;

  with Chart1.Axes.Left do
  begin
    EndPosition:=100/nSeries;
    Axis.Color:=Chart1[0].Color;
    LabelsFont.Color:=Chart1[0].Color;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  CopyChartToQRChart(Chart1, QRChart1);
end;

procedure TForm1.CopyChartToQRChart(AChart: TChart; AQRChart: TQRChart);
var i, j: Integer;
begin
  CloneChart(AQRChart.Chart, AChart, Self, false);

  for i:=0 to AChart.SeriesCount-1 do
    if AChart[i].CustomVertAxis<>nil then
      for j:=0 to AChart.CustomAxes.Count-1 do
        if AChart.CustomAxes[j]=AChart[i].CustomVertAxis then
          QRChart1.Chart[i].CustomVertAxis:=QRChart1.Chart.CustomAxes[j];
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

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

Re: Clone TChart to TQRChart

Post by Yeray » Mon May 26, 2014 11:00 am

Hi again,

I've moved the TV52016721 ticket to the public tracker.
http://bugs.teechart.net/show_bug.cgi?id=780
Feel free to add your mail to the CC list to be automatically notified when an update arrives.
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