Page 1 of 1

Unexpected behavior with Chart1.Draw

Posted: Thu Mar 31, 2016 8:11 am
by 17576646
When trying to refresh the chart using the command Chart1.Draw, a copy of the chart is created rather than a refresh of the original chart. To reproduce, create a MultiDevice Application. Place a TChart somewhere in the middle of the form. Place a TButton on the form with the following OnClick code:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
begin
  Chart1.Draw;
end;
Run and click the button. A copy of the chart appears in the top left of the form.

Is this the expected behavior of Draw in Firemonkey? If so, how can I force a refresh when something more than a Repaint is required?

Re: Unexpected behavior with Chart1.Draw

Posted: Fri Apr 01, 2016 7:36 am
by yeray
Hello,

I could reproduce the problem so I've added it to the public tracker:
http://bugs.teechart.net/show_bug.cgi?id=1488

Feel free to add your mail to the CC list to be automatically notified when an update arrives.

Re: Unexpected behavior with Chart1.Draw

Posted: Mon Apr 04, 2016 4:33 am
by 17576646
Given the bug in Draw, how may I force a refresh of a chart? I find my chart refreshes when edits are made in controls but not necessarily when edits are made programmatically. Specifically, I'm recalculating the chart height periodically. Repaint does not force an update after a height revision in code. I was hoping to use Draw for this purpose but since it is not working, what else might I do?

Re: Unexpected behavior with Chart1.Draw

Posted: Mon Apr 04, 2016 11:48 am
by yeray
Hello,

As a workaround, this seems to work fine for me here:

Code: Select all

  Chart1.Draw(Chart1.DelphiCanvas, RectF(Chart1.Position.X, Chart1.Position.Y, Chart1.Position.X+Chart1.Width, Chart1.Position.Y+Chart1.Height));

Re: Unexpected behavior with Chart1.Draw

Posted: Tue Apr 05, 2016 12:06 am
by 17576646
Thank you. The proposed workaround works if the chart lies directly on the form. But let's say that the chart is inside a TRectangle that is on the form. Then the code must be modified to:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
begin
  with Chart1 do
    Draw(DelphiCanvas, RectF(Rectangle1.Position.X + Position.X,
      Rectangle1.Position.Y + Position.Y, 
      Rectangle1.Position.X + Position.X + Width, 
      Rectangle1.Position.Y + Position.Y + Height));
end;
It appears that Chart1.DelphiCanvas covers the entire form. Therefore, Chart1.Draw() (no parameters) redraws the chart in the top left of the form. Chart1.Draw(Chart1.DelphiCanvas, RectF) can be made to redraw the chart in the correct place but the user must calculate the RectF position and size taking into account any components in which the chart is nested.