Page 1 of 1
Vertical Axis Labels Showing as Percent of Range?
Posted: Mon Feb 26, 2007 8:46 pm
by 9794096
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
Posted: Tue Feb 27, 2007 10:42 am
by 9348258
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;
}
}
Posted: Tue Feb 27, 2007 4:04 pm
by 9794096
Thank you very much.
That worked exactly as I needed it to.
Posted: Tue Feb 27, 2007 4:18 pm
by 9794096
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
Posted: Wed Feb 28, 2007 10:28 am
by 9348258
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));
}
}
}