Page 1 of 1
Switching to Logarithmic Y Axis
Posted: Thu Jun 02, 2005 2:30 am
by 9340511
My users would like to be able to use TChart's ability to view data on either a linear or logarithmic scale.
The file -
http://oli.tottensoftwaredesign.com/linear.tee is an example of data that has zeros present on the y axis. These were added so that a line-series would look right when zoomed-in on.
When they switch THIS TEE file to logarithmic Y Axis, we get a EZeroDivide exception from the Series Unit, TCustomSeries.GetAreaBrushColor function.
Any helping me to resolve this would be greatly appreciated.
Gary
Posted: Thu Jun 02, 2005 7:25 am
by narcis
Hi oysterbayer,
These were added so that a line-series would look right when zoomed-in on.
Why do you needed to do that?
When they switch THIS TEE file to logarithmic Y Axis, we get a ZeroDivide exception from the Series Unit, TCustomSeries.GetAreaBrushColor function.
It works fine here using latest TeeChart version (v7.04), which version are you using?
Posted: Thu Jun 02, 2005 4:07 pm
by 9340511
When I open this file with TChartOffice 7.02, and convert the Y Axis to logarithmic, it works fine. However, when I slide the hand "up", exposing zero and negative values for the Y Axis (now logarithmic) I get a zeroDivide condition.
It seems to me that the TChart should recognize that the Y axis cannot go below its limits, and not allow sliding further than the limits of logs.
What do you think?
Posted: Thu Jun 02, 2005 6:46 pm
by 9340511
narcis wrote:Why do you needed to do that?
It looked better when we add the zeros.
Posted: Fri Jun 03, 2005 4:45 am
by 9340511
I have tracked the problem down in the SERIES unit, and made a fix to my version of the source code that stops the Exception from occuring. The issue seems to be that the routine CalcYPosLeftRight attempts to take the Natural Log of a Zero; the LN function raises the EZeroDivide exception (i believe).
The following code fixes the problem, though there may well be a better place in your code to trap this situation.
{ calculate vertical pixel }
Function CalcYPosLeftRight(Const YLimit:Double; AnotherIndex:Integer):Integer;
var tmpPredValueX : Double;
tmpPredValueY : Double;
tmpDif : Double;
tmpY : Double;
begin
tmpPredValueX:=XValues.Value[AnotherIndex];
tmpDif:=XValues.Value[ValueIndex]-tmpPredValueX;
With ParentChart do
if tmpDif=0 then result:=CalcYPos(AnotherIndex)
else
begin
tmpPredValueY:=YValues.Value[AnotherIndex];
if MandatoryAxis.Logarithmic then // 7.0 #1225
begin
// beginning of fix
if tmpPredValueY <= 0 then tmpY:=0
else
if YValues.Value[ValueIndex] <= 0 then tmpY := 0
else
// end of fix
tmpY:=Exp(Ln(tmpPredValueY)+(YLimit-tmpPredValueX)*
(Ln(YValues.Value[ValueIndex])-Ln(tmpPredValueY))/tmpDif);
end
else
tmpY:=1.0*tmpPredValueY+(YLimit-tmpPredValueX)*
(YValues.Value[ValueIndex]-tmpPredValueY)/tmpDif;
result:=CalcYPosValue(tmpY);
end;
end;
Posted: Mon Jun 06, 2005 10:21 pm
by Pep
Hi,
I think this problem has been fixed in one of the latest TeeChart Pro versions (now available the v7.04). I've not been able to reproduce the problem with the TeeChart Office v3.0 neither the TeeChart Pro v7.04. Could you please check if it works fine for you using the latest sources ?
Posted: Tue Jun 07, 2005 5:56 am
by 9340511
I have downloaded v7.04, installed it, and I get the same bug. Here is the trace:
exception class : EZeroDivide
exception message : Floating point division by zero.
main thread ($ce4):
address exe/dll unit lineno procedure-name
005c786b IHA7.exe Series 1427 CalcYPosLeftRight
005c909a IHA7.exe Series 1841 TCustomSeries.DrawValue
00581831 IHA7.exe TeEngine 7112 TChartSeries.DrawAllValues
005c9f0c IHA7.exe Series 2173 TCustomSeries.DrawAllValues
00587ed3 IHA7.exe TeEngine 10153 DrawSeries
005885ed IHA7.exe TeEngine 10343 DrawAllSeries
005887e2 IHA7.exe TeEngine 10401 TCustomAxisPanel.InternalDraw
0059f6b8 IHA7.exe TeeProcs 1246 TCustomTeePanel.Draw
0059f446 IHA7.exe TeeProcs 1200 TCustomTeePanel.Draw
0059f713 IHA7.exe TeeProcs 1284 TCustomTeePanel.Paint
0046cf33 IHA7.exe Controls TCustomControl.PaintWindow
0046904e IHA7.exe Controls TWinControl.PaintHandler
004693c7 IHA7.exe Controls TWinControl.WMPaint
0046cecc IHA7.exe Controls TCustomControl.WMPaint
00466379 IHA7.exe Controls TControl.WndProc
00468ec2 IHA7.exe Controls TWinControl.WndProc
77f9ff54 ntdll.dll KiUserCallbackDispatcher
00468ac4 IHA7.exe Controls TWinControl.MainWndProc
0047b4b4 IHA7.exe Forms StdWndProc
77f9ff54 ntdll.dll KiUserCallbackDispatcher
77e15f64 user32.dll DispatchMessageA
00483e23 IHA7.exe Forms TApplication.ProcessMessage
00483e5a IHA7.exe Forms TApplication.HandleMessage
00484065 IHA7.exe Forms TApplication.Run
00753290 IHA7.exe IHA7 60 initialization
Why do I get the error and you guys can't reproduce it? I don't really know.
But we do get it - 100% reproducable in our executable. And the code-changes mentioned in a prior post do fix the problem.
If you review the code fixes I made, they make sense. The LN function doesn't like zero values, and through Delphi tracing I can see that the routine mentioned does pass zero's to it, with my data and wiring of TChart.
Please let me know if you need more information.
Thanks!
Posted: Tue Jun 07, 2005 8:28 am
by narcis
Hi osterbayer,
Thank you very much for your report. We will review your code and we will include the fix for the next release.
Posted: Tue Jul 10, 2007 2:48 pm
by 9343620
The bug reportet by oysterbayer is still in the newest version.
I downloaded v7.12 because i got the same error as reported in this topic.
The error was still there, so i traced into the source to the CalcYPosLeftRight routine. And there is still no check if the parameter value for the LN function is Zero or less!