Automatic Axis Max & Min for Custom Axis?

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Thu Jan 08, 2004 6:55 am

Is there a way to make my custom Y-axis automatically change the the Max and Min values based on the zoom?
Actually, there is, but not fully automatically with single line of code. All you have to do is:
a) Calculate visible points local minimum and maximum values,
b) adjust vertical axis scale acording to these two values. This can be done in chart Zoomed event.

The following code will calculate series (local) extreme values:

Code: Select all

    public void LocalMinMax(Steema.TeeChart.Styles.Series series, int first, int last, ref double min, ref double max)
    {
      min = series.YValues[first];
      max = series.YValues[first];
      for (int i=first; i<=last; i++)
      {
        if (series.YValues[i] < min) min = series.YValues[i];
        if (series.YValues[i] > max) max = series.YValues[i];
      }

    }
where first, last are first and last visible point index. The only problem (I think) is firstVisible and lastVisible (point) index properties are declared as protected internal integer variables so they cannot be accessed in (normal) code with end result being you cannot calculate local min/max value. I'll check if this is as designed or we can move it to public section in next maintenance release.
Marjan Slatinek,
http://www.steema.com

Marc
Site Admin
Site Admin
Posts: 1272
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Post by Marc » Thu Jan 08, 2004 8:40 pm

Confirmation:

The public properties First/LastVisible are in for the next maintenance release available this month.

Marc
Site Admin
Site Admin
Posts: 1272
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Post by Marc » Mon Jan 12, 2004 12:56 pm

Hello,

I don't think it's related. I can't generate a problem here in a simple test.

It can be checked. If you add Sample data to a Series..

eg.
tChart1[0].FillSampleValues(10);

and then open the Chart Editor. For the bottom Axis the indexed values 0 to 9 will be set such that 0 and 9 fall at Axes (Left and Right) and thus changing the 'Label on Axis' checkbox value in the Editor Bottom Axis Label tab will toggle their appearance or not.

If you look at the Left Axis Minimum and Maximum values as quoted in the max/min tabs when Autoscales is set to true and those values coincide with the min and max labels then setting 'Label on Axis' as false should hide the Labels. If the values are different you can test out the property by setting Autoscale to false and manually putting the LeftAxis Min value to the value of the Label. Toggling 'Label on Axis' should now hide/display tha Labels.

Regards,
Marc Meumann
Steema Support

Marc
Site Admin
Site Admin
Posts: 1272
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Post by Marc » Tue Jan 13, 2004 11:55 pm

Hello,

I tried out that example. It 'Label on Axis' property seems to behave correctly. If an Axis Label is situated exactly at an Axis Min or Max it will toggle accordingly. That can be tested by matching up the Axis scales' Min or Max to a Label value then toggling the option.

The zoom is a different issue. The default behaviour can be overridden by calculating the Axis X and Y positions and setting them when zooming. Assuming I have understood correctly that you wish to see only the actual 'under mouse rectangle' Series in the zoom then the following code should do it... ->

Adding events for the Chart:
eg.

Code: Select all

private bool zoomed=false;

private void tChart1_Zoomed(object sender, System.EventArgs e)
{
  zoomed=true;
}

private int MouseXDown;
private int MouseYDown;
private int MouseXUp;
private int MouseYUp;

private void tChart1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
  MouseXDown=e.X;
  MouseYDown=e.Y;
}

private void tChart1_UndoneZoom(object sender, System.EventArgs e)
{
  zoomed=false;
  lineSeries2.CustomVertAxis.Automatic=true;
  lineSeries3.CustomVertAxis.Automatic=true;
  lineSeries4.CustomVertAxis.Automatic=true;
}

private void tChart1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
  if (zoomed)
  {
    MouseXUp=e.X;
    MouseYUp=e.Y;

    double max=lineSeries2.YScreenToValue(MouseYDown);
    double min=lineSeries2.YScreenToValue(MouseYUp);
    lineSeries2.CustomVertAxis.SetMinMax(min,max);

    max=lineSeries3.YScreenToValue(MouseYDown);
    min=lineSeries3.YScreenToValue(MouseYUp);
    lineSeries3.CustomVertAxis.SetMinMax(min,max);

    max=lineSeries4.YScreenToValue(MouseYDown);
    min=lineSeries4.YScreenToValue(MouseYUp);
    lineSeries4.CustomVertAxis.SetMinMax(min,max);
  }
}
Regards,
Marc Meumann
Steema Support

Marc
Site Admin
Site Admin
Posts: 1272
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Post by Marc » Fri Jan 16, 2004 12:19 pm

Hello,

FYI.

There's a more elegant solution to this posted by a customer in this forum under the subject: "Custom axes bugs are still in "

ie. uses:

Code: Select all

myVerticalCustomAxis.SetMinMax( 
myVerticalCustomAxis.CalcPosPoint (Chart1.Zoom.y1), myVerticalCustomAxis.CalcPosPoint(Chart1.Zoom.y0)); 
Regards,
Marc Meumann
Steema Support

Post Reply