Page 1 of 1
Clone TChart to TQRChart
Posted: Mon Sep 16, 2013 12:23 pm
by 10546756
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
Re: Clone TChart to TQRChart
Posted: Tue Sep 17, 2013 2:47 pm
by yeray
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];
Re: Clone TChart to TQRChart
Posted: Mon Sep 23, 2013 1:47 pm
by 10546756
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
Re: Clone TChart to TQRChart
Posted: Tue Sep 24, 2013 8:30 am
by narcis
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?
Re: Clone TChart to TQRChart
Posted: Wed Sep 25, 2013 1:32 pm
by 10546756
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
Re: Clone TChart to TQRChart
Posted: Wed Sep 25, 2013 1:43 pm
by narcis
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.
Re: Clone TChart to TQRChart
Posted: Wed Sep 25, 2013 1:45 pm
by 10546756
Ok, thanks. I'll test it!
Re: Clone TChart to TQRChart
Posted: Mon Sep 30, 2013 8:42 am
by 10546756
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;
Re: Clone TChart to TQRChart
Posted: Tue Oct 01, 2013 3:09 pm
by yeray
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;
Re: Clone TChart to TQRChart
Posted: Mon May 26, 2014 11:00 am
by yeray
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.