简体   繁体   English

在Winforms图表C#中仅在Y轴上显示备用网格线号

[英]Showing only alternate grid line numbers in Y-axis in winforms chart c#

In Windows forms chart, I wanted to show only the alternate grid label numbers in the y-axis. 在Windows表单图表中,我只想在y轴上显示备用网格标签号。

For example, if the y-axis grid lines are at 15,20,25,30,35.. I would like to show only the numbers 15,25,35.. but the lines for 20,30,40,..should stay. 例如,如果y轴网格线为15,20,25,30,35 ..我只想显示数字15,25,35 ..,但只显示20,30,40,..应该留下。

Please refer the attached image for reference 请参考所附图片以供参考 请点击这里查看参考图片


Is there any default property for AxisY to achieve this? AxisY是否有任何默认属性可实现此目的? I tried different properties of AxisY but none seem to work well for my scenario. 我尝试了AxisY的其他属性,但似乎都不适合我的方案。

Please help me. 请帮我。

Thanks in Advance. 提前致谢。

I generate the series like below 我生成如下的系列

Random rno = new Random();
        for(int i=10; i< 100;i++)
        {
            int rnum = rno.Next(15, 150);
            chart1.Series[0].Points.AddXY(i,rnum);
        }
        chart1.ChartAreas[0].AxisY.Minimum = 15;
        chart1.ChartAreas[0].AxisY.Maximum = 150;
        chart1.ChartAreas[0].AxisY.Interval = 5;
        //chart1.ChartAreas[0].AxisY.MajorGrid.IntervalOffset = 5;

You can achieve this by changing only the interval of the grid itself: 您可以通过仅更改网格本身的间隔来实现:

chart1.ChartAreas[0].AxisY.Minimum = 15;
chart1.ChartAreas[0].AxisY.Maximum = 150;

chart1.ChartAreas[0].AxisY.Interval = 10; // Interval of the written numbers
chart1.ChartAreas[0].AxisY.MajorGrid.Interval = 5; // Interval of the grid

If you want to add tickmarks (as shown in your picture) to the gridlines that does not show a number you can do it with: chart1.ChartAreas[0].AxisY.MajorTickMark.Interval = 5; 如果要在没有显示数字的网格线上添加刻度线(如图所示),可以使用以下方法: chart1.ChartAreas[0].AxisY.MajorTickMark.Interval = 5;

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

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