Web forum is in read-only mode. Login as active registered customer for write access
  Forum Search   New Posts New Posts

Divide by zero for empty series

 Post Reply Post Reply
Author
Mark Fairlamb View Drop Down
New Member
New Member
Avatar

Joined: 13 Aug 2019
Posts: 8
Post Options Post Options   Quote Mark Fairlamb Quote  Post ReplyReply Direct Link To This Post Topic: Divide by zero for empty series
    Posted: 27 Mar 2020 at 9:38am
Hi 

If you drop an FNC Chart and a button on a form and then put the following code in the button on click event:

procedure TForm1.Button1Click(Sender: TObject);
var
 i : integer;
begin
 Chart.BeginUpdate;
 Chart.Series[0].YValues.AutoUnits := false;
 Chart.Series[0].YValues.MajorUnitSpacing := 1.0; // not required to generate error
 for i := 0 to Chart.Series.Count-1 do
    Chart.Series.Points.Clear;
 Chart.EndUpdate;
end;

When you call Chart.EndUpdate you get a divide by zero error.
The error happens on line 4014 of VCL.TMSFNCChart.pas because "max" is zero
dv.ValueRadius := PointF((pr.Bottom - pr.Top) / max * JMax / 2, (pr.Bottom - pr.Top) / max * JMax / 2);

Changing the AutoUnits to true avoids the error so I can get around this but setting it to true when I clear and then back to false when I add a point is a bit clunky and causes me difficulties if it started false (i.e. I have to track for each series in each chart...)
 
Hope you can help/explain so I can get around this more eloquently.

Cheers,
Mark

Back to Top
Pieter Scheldeman View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 3728
Post Options Post Options   Quote Pieter Scheldeman Quote  Post ReplyReply Direct Link To This Post Posted: 28 Mar 2020 at 2:46pm
Hi,

We have tried to reproduce this issue here but are not able to.
Can you perhaps send us a full sample?
Back to Top
Mark Fairlamb View Drop Down
New Member
New Member
Avatar

Joined: 13 Aug 2019
Posts: 8
Post Options Post Options   Quote Mark Fairlamb Quote  Post ReplyReply Direct Link To This Post Posted: 30 Mar 2020 at 12:30am
Hi Pieter,

Thanks for the quick response.  I have emailed the sample code to support@tmssoftware.com (I mention the title of the post in the subject line).

I look forward to hearing from you.

Thanks,
Mark
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down