Search code examples
c#zedgraph

Add custom labels to the yaxis instead of actual values in Zedgraph


I try to add Add custom labels to the yaxis instead of actual values in zedgraph.I have a structure like that :

myPane.YAxis.Scale.Min = 0;
myPane.YAxis.Scale.Max = 1;
myPane.YAxis.Scale.MajorStep = 0.1;
myPane.YAxis.IsVisible = true;
myPane.YAxis.Title.IsVisible = false;

I try to accomplish assign label of myPane.YAxis.Scale.Min to the "Min" word instead of 0. And label of myPane.YAxis.Scale.Max to the "Max" word instead of 1 and assign label of middle of the axis to the "(Min+Max)/2 " word. Other actual labels also should be invisible. So I need to know:

1)How can I make yaxis values invisible? 2) How can I add custom values to the yaxis?

Please help..


Solution

  • You have to handle the ScaleFormatEvent:

        ...
        yAxis.ScaleFormatEvent += yAxis_ScaleFormatEvent;
    }
    
    private string yAxis_ScaleFormatEvent(GraphPane pane, Axis axis, double val, int index)
    {
        if (val == 0) return "Min";
        else if (val == 0) return "Max";
        else if(val == 0.5) return val.ToString();
        else return "";
    }