How can I avoid the fact that ZedGraph migrates my YAxis by dividing it by 1000?

I am creating a C # Visual Studio Forms application that uses zedgraph to plot the data that the program collects, but when I print the data, I encounter the following problem:

My y axis values ​​are usually in the 100,000+ range, so when the zed graph displays the value that it calls the y axis labels with things like 0, 10, 15, 20, 25, and then on the y axis label, it will add "(10 ^ 3)" to the header and construct values ​​accordingly. What I want to do is assign the y axis or values ​​like 0, 10,000, 15,000, 20,000, etc. Or 0, 10k, 15k, 20k, etc., and do not change it along the y axis.

I tried to establish YAxis.Scale.MajorStep = double.Parse("10000");, but the only effect that is is to add a ton of more tick lines along the y axis, but no other effect. Here is my code that displays the data:

    private void createGraph()
    {
        GraphPane myPane = zdc_graph.GraphPane;
        myPane.CurveList.Clear();
        myPane.GraphObjList.Clear();

        myPane.Title.Text = this.monitoredHost.hostName + "\nWorkState[" +
                            this.monitoredHost.currentWorkState + "]";
        myPane.XAxis.Title.Text = "";

        myPane.YAxis.Title.Text = "OPS Per Second";
        myPane.YAxis.Scale.FontSpec.FontColor = Color.Blue;
        myPane.YAxis.Title.FontSpec.FontColor = Color.Blue;
        myPane.YAxis.Scale.MaxAuto = true;

        myPane.Y2Axis.Title.Text = "Reading";
        myPane.Y2Axis.IsVisible = true;
        myPane.Y2Axis.Scale.FontSpec.FontColor = Color.Red;
        myPane.Y2Axis.Title.FontSpec.FontColor = Color.Red;

        myPane.XAxis.Type = AxisType.Date;
        myPane.XAxis.Scale.Format = "T";
        myPane.XAxis.Scale.MajorUnit = DateUnit.Second;
        myPane.YAxis.Scale.Min = 0;
        myPane.YAxis.Scale.MajorStep = double.Parse("10000");
        myPane.Y2Axis.Scale.Min = 0;

        LineItem kpiCurve = myPane.AddCurve("OPS Per Second",
                           this.monitoredHost.graphKpiList,
                           Color.Blue,SymbolType.Circle);
        LineItem pwrCurve = myPane.AddCurve("Reading", 
                           this.monitoredHost.graphPwrList, Color.Red, 
                           SymbolType.Circle);

        kpiCurve.Line.Width = 2.0F;
        kpiCurve.Symbol.Size = 4.0F;
        kpiCurve.Symbol.Fill = new Fill(Color.White);

        pwrCurve.Line.Width = 2.0F;
        pwrCurve.Symbol.Size = 4.0F;
        pwrCurve.Symbol.Fill = new Fill(Color.White);
        pwrCurve.IsY2Axis = true;

        myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 210), -45F);

        zdc_graph.AxisChange();
        zdc_graph.Refresh();
    }

Hope this makes sense. Thanks for the help.

+5
source share
2 answers

ZedGraph tries to detect the magnitude and simplify the graph. You can disable it as follows:

myPane.YAxis.Scale.MagAuto = false;

This will result in y axis labels, for example 100000.

If you want to format the separator comma label, for example 100,000:

myPane.YAxis.Scale.Format = "#,#";

Finally, if you prefer to show 100k, you need to subscribe to ScaleFormatEventand return your own format, for example:

myPane.YAxis.ScaleFormatEvent += new Axis.ScaleFormatHandler(YAxis_ScaleFormatEvent);

string YAxis_ScaleFormatEvent(GraphPane pane, Axis axis, double val, int index)
{
    return String.Format("{0}k", val / 1000);
}
+9

. , , , PDF ( MigraDoc), .

       public Bitmap printGraphPane()
       {
        ZedGraphControl graph = new ZedGraphControl();
        GraphPane newGP = myPane.GraphPane;
        //newGP.YAxis.Scale.Mag = 0;
        //newGP.YAxis.Scale.Format = "#";
        //newGP.YAxis.ScaleFormatEvent += new Axis.ScaleFormatHandler(YAxis_ScaleFormatEvent);

        Bitmap bit = new Bitmap(newGraph.Width, newGraph.Height);
        newGraph.ClientSize = bit.Size;
        newGraph.DrawToBitmap(bit, new Rectangle(0, 0, newGraph.Width, newGraph.Height));

        return bit;
       }
0

All Articles