0
votes

I have a chart control that I use to show sound pressure lines.

So the X axis is

31.5 63 125 250 500 1000 2000 4000 and 8000.

I set the chart logarithmic on and the log base to 10.

But I'm not able to show all these labels on the axis, it shows 31.5 315 and 3150 only.

Tried to put interval to 1 but no luck.

Can anyone help me?

1
To get full control over the labelling you may need to use CustomLabelsTaW
I tried that but then the chart don't show labels at allMr P
True, its either Labels or CustomLabels.TaW
So I add my labels then how can I disable the standard ones and use my customs?Mr P
Please, see my following answerMr P

1 Answers

0
votes

To make CustomLabels show up on your axis you need to create them with at least these three properties:

  • Text
  • FromPosition
  • ToPosition

Here is an example:

enter image description here

private void button4_Click(object sender, EventArgs e)
{
    Series S2 = chart1.Series.Add("Series2");
    ChartArea CA = chart1.ChartAreas[0];
    CA.AxisY.IsLogarithmic = true;

    List<double> fr = new List<double>();
    for (int i = 3; i < 18; i++ )
    {
        fr.Add(Math.Pow(2, 1f * i / 2));
    }

        for (int i = 1; i < fr.Count; i+=2)
        {
            CustomLabel cl = new CustomLabel();
            cl.FromPosition =  fr[i - 1];
            cl.ToPosition = fr[i + 1];
            cl.Text = fr[i] + " Hz";
            CA.AxisY.CustomLabels.Add(cl);

        }

    for (int i = 1; i < 60; i++)
    {
        chart1.Series[0].Points.AddXY(i, Math.Pow(2, i));
        chart1.Series[1].Points.AddXY(i, i * i);
    }

}

Note that for best precision you should use FromPositions and ToPositions that don't fall on the Labels but right between. So I skip every other step in the list of frequency steps for the displayed Labels and use them instead for their FromPositions and ToPositions.