Page 1 of 1
What happened to MinVisibleValue & MaxVisibleValue
Posted: Tue Aug 05, 2008 10:55 pm
by 10548832
I have searched everywhere, through the source code, through the examples. Where is:
MinVisibleSeriesValue
MaxVisibleSeriesValue
MinVisibleValue
MaxVisibleValue
I'm trying to get my left axis to scale correctly while scrolling.
Delphi6
TChart 8 VCL
Posted: Wed Aug 06, 2008 8:37 am
by yeray
Hi Phineas,
The methods you mention are exclusive ActiveX methods. Here is how you could calculate the same in Delphi.
And please, let us know if we've mistakenly documented the methods you mention as belonging to the VCL version, and if so, where we can find the error to correct it.
Code: Select all
function TForm1.MaxMinVisibleValue(IsMax:WordBool;AllSeries: WordBool; SeriesIndex: Integer; FAxis: TChartAxis): Double;
Var i,j,firstSeries,startSeries,endSeries : Integer;
tmpResult,tmpVal : Double;
firstTime: Boolean;
begin
firstSeries:=-1;
firstTime:=True;
tmpResult:=0;
With FAxis.ParentChart do
Begin
If AllSeries=True then
Begin
for i:=0 to SeriesCount-1 do
Begin
if (Series[i].Active) then
Begin
firstSeries:=i;
break;
end;
end;
end
else
firstSeries:=SeriesIndex;
if (firstSeries>=0) and (firstSeries<SeriesCount) then
Begin
If AllSeries=True then
Begin
startSeries:=0;
endSeries:=SeriesCount-1;
end
else
Begin
startSeries:=SeriesIndex;
endSeries:=SeriesIndex;
end;
for i:=startSeries to endSeries do
Begin
if ((Series[i].AssociatedToAxis(FAxis)=True) and (Series[i].Active))then
begin
for j:=Series[i].FirstValueIndex to Series[i].LastValueIndex do
Begin
if FAxis.Horizontal=True then
tmpVal:=Series[i].XValue[j]
else
begin
if (Series[i].YValue[j] <= FAxis.Maximum) and (Series[i].YValue[j] >= FAxis.Minimum) then
tmpVal:=Series[i].YValue[j];
end;
if firstTime then
Begin
tmpResult := tmpVal;
firstTime:=False;
end
else
Begin
if (IsMax) then
Begin
if (tmpVal>tmpResult) then
tmpResult:=tmpVal;
end
else
Begin
if (tmpVal<tmpResult) then
tmpResult:=tmpVal;
end;
end;
end
end;
end;
end
end;
result:=tmpResult;
end;
Posted: Wed Aug 06, 2008 9:08 pm
by 10548832
Thanks for that Yeray
Now how to use it.
Would this be the call to the function?
Chart1.LeftAxis.SetMinMax(MaxMinVisibleValue(false, true, 0, Chart1.LeftAxis), MaxMinVisibleValue(true, true, 0, Chart1.LeftAxis));
And where to place it.
OnAddSeries
OnAfterDraw
OnBeforeDrawSeries
OnBeforeDrawAxes
OnScroll
????????????
I placed a tChart on a form.
procedure TForm1.FormCreate(Sender: TObject);
begin
Series1 := TLineSeries.Create(Chart1);
Series1.FillSampleValues(3000);
Chart1.AddSeries(Series1);
Chart1.BottomAxis.SetMinMax(1,10);
ChartScrollBar1.RecalcPosition;
end;
procedure TForm1.Chart1BeforeDrawSeries(Sender: TObject);
begin
Chart1.LeftAxis.SetMinMax(MaxMinVisibleValue(false, true, 0, Chart1.LeftAxis),
MaxMinVisibleValue(true, true, 0, Chart1.LeftAxis));
end;
I have had nothing but crashes trying to get it to work and/or series1 just disappears. I get worse results when Series1 is TCandleSeries.style := csCandleStick;
What am I doing wrong Yeray?
Posted: Thu Aug 07, 2008 8:14 am
by yeray
Hi Phineas,
Some considerations:
1) I've fixed the function I told you yesterday modifying one line of code. Where said:
Code: Select all
if (Series[i].YValue[j] < FAxis.Maximum) and (Series[i].YValue[j] > FAxis.Minimum) then
Now it's:
Code: Select all
if (Series[i].YValue[j] <= FAxis.Maximum) and (Series[i].YValue[j] >= FAxis.Minimum) then
2) I recommend you to use Chart1.Axes.Left or Chart1.Axes.Bottom instead of Chart1.LeftAxis or Chart1.BottomAxis because they are deprecated properties.
3) You probably get this error because you are calling the function in OnBeforeDrawSeries event. Note that in the function you are reading the series' values, so you cannot call this function until teechart has the series' values calculated.
So here I recommend you to use another event as OnAfterDraw or OnScroll.