Search code examples
c#winformsmschartaxis-labels

Disable Interval Label from AxisY


as the title says, I need to disable Interval Labels from AxisY but only mantaining the extremes maximum and minimum axis y labels, is this possible?

I searched at this website and there nothing like my question...

Also, I need to know if the maximum axis y label and minimum axis y label can be rotated +45° and -45° respectively

Thank you!


Solution

  • I think you will have to use two CustomLabels.

    Note the they all must have the same angle.

    Use a suitable delta, i.e. a small number that determines the range of the label, and a suitable format..

    ChartArea ca = chart1.ChartAreas[0];
    Series series = chart1.Series[0];
    double delta = 0.1;
    
    double yMin = series.Points.Min(x => x.YValues[0]);
    double yMax = series.Points.Max(x => x.YValues[0]);
    CustomLabel clyMax = new CustomLabel();
    CustomLabel clyMin = new CustomLabel();
    
    clyMax.FromPosition = yMax - delta;
    clyMax.ToPosition = yMax + delta;
    clyMin.FromPosition = yMin - delta;
    clyMin.ToPosition = yMin + delta;
    
    clyMax.Text = yMax.ToString("0.0");
    clyMin.Text = yMin.ToString("0.0");
    
    ca.AxisY.LabelStyle.Angle = 45;
    
    ca.AxisY.CustomLabels.Add(clyMax);
    ca.AxisY.CustomLabels.Add(clyMin);