简体   繁体   中英

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.

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.

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


Is there any default property for AxisY to achieve this? I tried different properties of AxisY but none seem to work well for my scenario.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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