Logarithmic axis labelling (any base) and req. for E base
Posted: Wed Jun 06, 2007 12:26 pm
Hi,
I've got a working solution for putting labels on a logarithmic axis which always displays the next logarithmic decade. For instance, you plot values ranging from y=8 to 78 and you want the 1, 10 and 100 label to be visible - and I don't think that "myAxis.Automatic = true;" gets it right in most cases. In the y=8 to 78 example for instance, only 1 and 10 are visible
Add this below method to your .cs class. It generates the next logarithmic number based on the max value to plot and the logarithmic base you use on the axis:
private double GetLogarithmicMaximumLabel(double maxSeriesValue, double logBase)
{
int pow = 0;
while (maxSeriesValue >= 1)
{
maxSeriesValue /= logBase;
pow++;
}
return Math.Pow(logBase, pow);
}
Then in your code, apply the following property values to your axis:
double maxY = mySeries.MaxYValue();
myAxis.Automatic = false;
myAxis.Logarithmic = true;
myAxis.LogarithmicBase = 10; // for instance... it could be anything
if (myAxis.Minimum > myAxis.LogarithmicBase)
myAxis.Minimum = myAxis.LogarithmicBase;
myAxis.Maximum = GetLogarithmicMaximumLabel(Math.Ceiling(maxY), myAxis.LogarithmicBase);
myAxis.MinorGrid.Visible = true;
myAxis.Labels.Exponent = true;
myAxis.TickOnLabelsOnly = false;
myAxis.MinorTickCount = 9;
myAxis.MinorTicks.Length = 2;
If you got a solution for displaying the strings "E", "E^2", "E^3" etc. for base Math.E on the axis labels I would be glad to hear about it! The optimal solution would be properly formattted powers, eg. html equvivalent of "E<sup>2</sup>" and not "E^2".
Best regards
Michael Schøler
External Consultant
www.vestas.com
I've got a working solution for putting labels on a logarithmic axis which always displays the next logarithmic decade. For instance, you plot values ranging from y=8 to 78 and you want the 1, 10 and 100 label to be visible - and I don't think that "myAxis.Automatic = true;" gets it right in most cases. In the y=8 to 78 example for instance, only 1 and 10 are visible
Add this below method to your .cs class. It generates the next logarithmic number based on the max value to plot and the logarithmic base you use on the axis:
private double GetLogarithmicMaximumLabel(double maxSeriesValue, double logBase)
{
int pow = 0;
while (maxSeriesValue >= 1)
{
maxSeriesValue /= logBase;
pow++;
}
return Math.Pow(logBase, pow);
}
Then in your code, apply the following property values to your axis:
double maxY = mySeries.MaxYValue();
myAxis.Automatic = false;
myAxis.Logarithmic = true;
myAxis.LogarithmicBase = 10; // for instance... it could be anything
if (myAxis.Minimum > myAxis.LogarithmicBase)
myAxis.Minimum = myAxis.LogarithmicBase;
myAxis.Maximum = GetLogarithmicMaximumLabel(Math.Ceiling(maxY), myAxis.LogarithmicBase);
myAxis.MinorGrid.Visible = true;
myAxis.Labels.Exponent = true;
myAxis.TickOnLabelsOnly = false;
myAxis.MinorTickCount = 9;
myAxis.MinorTicks.Length = 2;
If you got a solution for displaying the strings "E", "E^2", "E^3" etc. for base Math.E on the axis labels I would be glad to hear about it! The optimal solution would be properly formattted powers, eg. html equvivalent of "E<sup>2</sup>" and not "E^2".
Best regards
Michael Schøler
External Consultant
www.vestas.com