简体   繁体   English

.NET图表并显示所有X轴标签

[英].NET Chart and show all axis X labels

I have a chart control that I use to show sound pressure lines. 我有一个图表控件,用于显示声压线。

So the X axis is 所以X轴是

31.5 63 125 250 500 1000 2000 4000 and 8000.

I set the chart logarithmic on and the log base to 10. 我将图表的对数设置为10,对数基数设置为10。

But I'm not able to show all these labels on the axis, it shows 31.5 315 and 3150 only. 但是我无法在轴上显示所有这些标签,它仅显示31.5 315和3150。

Tried to put interval to 1 but no luck. 尝试将时间间隔设置为1,但没有运气。

Can anyone help me? 谁能帮我?

To make CustomLabels show up on your axis you need to create them with at least these three properties: 为了使CustomLabels在您的轴上显示,您需要至少使用以下三个属性来创建它们:

  • Text
  • FromPosition
  • ToPosition

Here is an example: 这是一个例子:

在此处输入图片说明

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. 请注意,为了获得最佳精度,您应该使用FromPositionsToPositions ,它们不在Labels上,而是在Labels之间。 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 . 因此,我跳过了所显示Labels的频率步进列表中的所有其他步骤,而是将其FromPositionsToPositions

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM