Vertical Axis Labels Showing as Percent of Range?

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Aaron Peronto
Newbie
Newbie
Posts: 38
Joined: Thu Feb 01, 2007 12:00 am

Vertical Axis Labels Showing as Percent of Range?

Post by Aaron Peronto » Mon Feb 26, 2007 8:46 pm

Here is my situation.
I have several verticals axes (left, right and 4 custom axes).
For each one, I want to have the option of having the labels on that axis show as a percentage of the min and max values for that axis.

For example, my Left axis has a max of 1200 and min of 0. I want the label at 600 to read 50% instead of 600. Likewise, any other label that appears needs to display its percentage of the range instead of the actual number.

How can I achieve this?

Thanks for your help.

Aaron Peronto

Edu
Advanced
Posts: 206
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia

Post by Edu » Tue Feb 27, 2007 10:42 am

Hi Aaron

You can use the GetAxisLabel event to change the labels as below code:

Code: Select all

private void Form1_Load(object sender, EventArgs e)
        {
            tChart1.Aspect.View3D = false;
            line1.FillSampleValues();
            line2.FillSampleValues();
            
            Axis axis1 = new Axis(false, false, tChart1.Chart);
            tChart1.Axes.Custom.Add(axis1); 
            line1.CustomVertAxis = axis1;

            line2.VertAxis = Steema.TeeChart.Styles.VerticalAxis.Right;
            
            //Uncomment the block below to display the labels at each series point
            //for (int i = 0; i < tChart1.Series.Count; i++)
            //{
            //    tChart1[i].GetVertAxis.Labels.Style = AxisLabelStyle.Mark; 
            //}
            
            tChart1.Panel.MarginLeft = 10;
        }

        private void tChart1_GetAxisLabel(object sender, GetAxisLabelEventArgs e)
        {
            string fmt = "{0:##,##0.##} %";

            if (!(sender as Axis).Horizontal)
                foreach (Steema.TeeChart.Styles.Series s in tChart1.Series)
                    if (s.GetVertAxis == sender)
                    {
                        double Value = Convert.ToDouble(e.LabelText);

                        double percent = Value * 100 / s.MaxYValue();
                        e.LabelText = string.Format(fmt, percent);

                        break;
                    }

        }
Best Regards,
Edu

Steema Support Central
http://support.steema.com/

Aaron Peronto
Newbie
Newbie
Posts: 38
Joined: Thu Feb 01, 2007 12:00 am

Post by Aaron Peronto » Tue Feb 27, 2007 4:04 pm

Thank you very much.

That worked exactly as I needed it to.

Aaron Peronto
Newbie
Newbie
Posts: 38
Joined: Thu Feb 01, 2007 12:00 am

Post by Aaron Peronto » Tue Feb 27, 2007 4:18 pm

Ok, so now I have my labels being displayed as a percentage of the range from Axis.Minimum to Axis.Maximum.

However, when I zoom the graph, this causes a problem.
Axis.Minimum and Axis.Maximum are reset when you zoom.
So what I really need to use are the overall Min and Max for the Axis that the graph would use to reset to when you unzoom.
This way, when I zoom in, my % numbers on my labels on the axis will still reflect the % from the original min and max and NOT the % from the zoomed min and max.

Are these values stored with each axis somewhere that is accessible?

Thanks.

Aaron

Edu
Advanced
Posts: 206
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia

Post by Edu » Wed Feb 28, 2007 10:28 am

Hi Aaron

Custom axes don't support zoom, you can find more information about it in the link: http://www.teechart.net/reference/modul ... labels#172

In your example you can try the below code:

Code: Select all

private void tChart1_UndoneZoom(object sender, EventArgs e)
        {
           foreach (Steema.TeeChart.Styles.Series s in tChart1.Series)
            s.GetVertAxis.Automatic=true;
        }

        private void tChart1_Zoomed(object sender, EventArgs e)
        {
            foreach (Steema.TeeChart.Styles.Series s in tChart1.Series)
            {
                if (s.CustomVertAxis != null)
                {
                    s.GetVertAxis.SetMinMax(s.GetVertAxis.CalcPosPoint(tChart1.Zoom.y1), s.GetVertAxis.CalcPosPoint(tChart1.Zoom.y0));
                }
            }
        }
Best Regards,
Edu

Steema Support Central
http://support.steema.com/

Post Reply