Page 1 of 1

Setting Labels for a Logarithmic Scale

Posted: Thu Jul 02, 2015 9:47 pm
by 13050364
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!

Re: Setting Labels for a Logarithmic Scale

Posted: Fri Jul 03, 2015 10:51 am
by Christopher
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.

Re: Setting Labels for a Logarithmic Scale

Posted: Tue Jul 14, 2015 3:56 pm
by 13050364
Thanks Chris. That helped a lot.