Setting Labels for a Logarithmic Scale

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

Setting Labels for a Logarithmic Scale

Post by Dave » Thu Jul 02, 2015 9:47 pm

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
log.PNG
chart with logarithmic scale
log.PNG (65.68 KiB) Viewed 7657 times
linear.PNG
chart with normal linear scale
linear.PNG (78.28 KiB) Viewed 7652 times

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

Re: Setting Labels for a Logarithmic Scale

Post by Christopher » Fri Jul 03, 2015 10:51 am

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++)
      {
        tChart1.Series.Add(typeof(Line));

        for (int j = 0; j < 50; j++)
        {
          tChart1[i].Add(rnd.Next(10000, 1000000));
        }
      }

      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
Advanced
Posts: 139
Joined: Mon Sep 22, 2008 12:00 am

Re: Setting Labels for a Logarithmic Scale

Post by Dave » Tue Jul 14, 2015 3:56 pm

Thanks Chris. That helped a lot.

Post Reply