What happened to MinVisibleValue & MaxVisibleValue

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Phineas
Newbie
Newbie
Posts: 18
Joined: Wed Apr 09, 2008 12:00 am

What happened to MinVisibleValue & MaxVisibleValue

Post by Phineas » Tue Aug 05, 2008 10:55 pm

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

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Post by Yeray » Wed Aug 06, 2008 8:37 am

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;
Last edited by Yeray on Thu Aug 07, 2008 8:01 am, edited 1 time in total.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Phineas
Newbie
Newbie
Posts: 18
Joined: Wed Apr 09, 2008 12:00 am

Post by Phineas » Wed Aug 06, 2008 9:08 pm

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?

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Post by Yeray » Thu Aug 07, 2008 8:14 am

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.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply