Page 1 of 1

TChart.DrawToMetaCanvas question

Posted: Fri Mar 20, 2009 2:53 pm
by 10046032
Hello,

I have a TChart object with a series associated with left and bottom axis. I want to plot this TChart in a custom Metafile canvas so that the bottom axis will be drawn in a custom position e.g. at 500 pixels of my metafile canvas. This means that if I draw a line from (0,500) to (300,500) on my metafile canvas this line will touch the bottom axis of my chart. What I noticed is that if I pass a rectangle in the DrawToMetaCanvas procedure the bottom axis is drawn some pixels above the bottom of the rectangle due to the presence of the title and labels. Any ideas please?

Regards

Posted: Fri Mar 20, 2009 3:57 pm
by narcis
Hi johnnix,

Yes, you can set a custom ChartRect:

Code: Select all

  Chart1.CustomChartRect:=true;
  Chart1.ChartRect:=TeeRect(0,0,Chart1.Width,Chart1.Height);
Notice you'll need to include TeCanvas unit to the uses section to be able to use TeeRect method.

Hope this helps!

Posted: Sat Mar 21, 2009 3:27 pm
by 10046032
Hello,

Thank you for the tip. The plot area now is drawn as wanted but all other elements (axis, labels, chart title) are not positioned correctly. Here is the code I use to create the metafile:

Code: Select all

chart := TChart.Create(nil);
Chart.CustomChartRect:=true;
Chart.ChartRect:=TeeRect(10,start_y,150,start_y+trunc(total_depth*(h-start_y)/total_depth));

chart.BevelInner :=bvNone;
chart.BevelOuter := bvNone;
series := TLineSeries.Create(chart);
chart.AddSeries(series);
chart.Series[0].Assign(qt_plot.Series[0]); // assign series from other plot

chart.DrawToMetaCanvas(canvas, chart.ChartRect);
chart.free
I uploaded a picture in the attachments newsgroup with the same topic.

Regards

Posted: Mon Mar 23, 2009 3:51 pm
by narcis
Hi johnnix,

Could you please send us a simple example project we can run "as-is" to reproduce the problem here?

Thanks in advance.

Posted: Tue Mar 24, 2009 6:50 am
by 10046032
Hello Narcis,

I uploaded a sample project in the attachments newsgroup.

Regards

Posted: Tue Mar 24, 2009 3:35 pm
by narcis
Hi johnnix,

Thanks for the example project. I'm not sure about what you are trying to obtain here. Could you please explain what you'd like to get? An image would be very helpful.

Thanks in advance.

Posted: Thu Mar 26, 2009 6:39 am
by 10046032
Hello Narcis,

Please see my reply in the attachments newsgroup.

Regards

Posted: Mon Mar 30, 2009 7:35 am
by 10046032
Hello Narcis,

Did you understand what I need to do?

Regards

Posted: Mon Mar 30, 2009 7:55 am
by narcis
Hi johnnix,

Yes, we are investigating the issue here. Will get back to you ASAP.

Posted: Tue Mar 31, 2009 12:14 pm
by narcis
Hi johnnix,

Setting TitleSize in your project works fine for us here:

Code: Select all

procedure TForm10.Button1Click(Sender: TObject);
var chart: TChart;
    series: TLineSeries;
begin

  chart := TChart.Create(nil);
  if checkbox1.Checked then
  begin
    Chart.CustomChartRect:=true;
    Chart.ChartRect:=TeeRect(50,10,300,300);
  end;

  chart.Assign(plot);
  chart.BevelInner :=bvNone;
  chart.BevelOuter := bvNone;
  series := TLineSeries.Create(chart);
  chart.AddSeries(series);
  chart.Series[0].Assign(plot.Series[0]); // assign series from other plot
  Chart.Axes.Left.TitleSize := -40;
  Chart.Axes.Bottom.TitleSize := -20;

  chart.DrawToMetaCanvas(image1.canvas, chart.ChartRect);
  chart.free ;

  image1.Refresh;
end;

Posted: Wed Apr 01, 2009 5:18 am
by 10046032
Hello Narcis,

Setting the TitleSize seems to do the trick!!!!! Thank you very much for your support.