## Setting Labels for a Logarithmic Scale

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Dave
Posts: 137
Joined: Mon Sep 22, 2008 12:00 am

### Setting Labels for a Logarithmic Scale

Hi

I can change Y axis to a logarthmic scale by doing;

tChart1.Axes.Left.Logarithmic = true;

However the axis only shows 1 label. See the 2 attached screenshots for a linear scale chart and the corresponding logarithmic scale chart.

I searched the forum and I found you can do;

tChart.Axes.Left.Increment = 100;
tChart1.Axes.Left.Logarithmic = true;

This improves things a bit with more labels displayed. However depending on the Y-axis scale, often there are too many labels and they overlap.

Is there a way to calculate the Increment (perhaps based on the max and min Y values in the chart?) such that a reasonable number of labels (that do not overlap!) are displayed.

Thanks!
Attachments
chart with logarithmic scale
log.PNG (65.68 KiB) Viewed 1703 times
chart with normal linear scale
linear.PNG (78.28 KiB) Viewed 1698 times

Christopher
Guru
Posts: 1218
Joined: Fri Nov 15, 2002 12:00 am

### Re: Setting Labels for a Logarithmic Scale

Dave,
Dave wrote:s there a way to calculate the Increment (perhaps based on the max and min Y values in the chart?) such that a reasonable number of labels (that do not overlap!) are displayed.
An example here uses scrolling ... run the following code and then scroll the chart vertically (right-button mouse click and drag down):

Code: Select all

``````    private void InitializeChart()
{
Random rnd = new Random();
tChart1.Aspect.View3D = false;

for (int i = 0; i < 5; i++)
{

for (int j = 0; j < 50; j++)
{
}
}

tChart1.Scroll += TChart1_Scroll;
}

private void TChart1_Scroll(object sender, EventArgs e)
{
double range = tChart1.Axes.Left.Maximum - tChart1.Axes.Left.Minimum;
range /= 10000;
int div = (Utils.Round(range) / 100) * 100;
tChart1.Axes.Left.Increment = div;
}
``````
This can be modified to account for scrolling vertically upwards and for other similar circumstances.
Best Regards,
 Christopher Ireland / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com Instructions - How to post in this forum

Dave