C# 我如何避免ZedGraph重新标记我的YAxis,除以1000?

C# 我如何避免ZedGraph重新标记我的YAxis,除以1000?,c#,visual-studio,zedgraph,C#,Visual Studio,Zedgraph,我正在创建一个C#visual studio forms应用程序,该应用程序使用zedgraph绘制程序收集的数据,但在绘制数据时遇到以下问题: private void createGraph() { GraphPane myPane = zdc_graph.GraphPane; myPane.CurveList.Clear(); myPane.GraphObjList.Clear(); myPane.Title

我正在创建一个C#visual studio forms应用程序,该应用程序使用zedgraph绘制程序收集的数据,但在绘制数据时遇到以下问题:

    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();
    }
我的y轴值通常在100000+范围内,因此当zed graph绘制值时,它会用0、10、15、20、25等标记y轴标签,然后在y轴标签上,它会将“(10^3)”附加到标题上,并相应地绘制值。我想做的是让它用0、10000、15000、20000等值或0、10k、15k、20k等值标记y轴,而不是让它调整y轴标题

我尝试设置
YAxis.Scale.MajorStep=double.Parse(“10000”)但唯一的效果是在y轴上添加大量的记号线,但没有其他效果。以下是我绘制数据图表的代码:

    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();
    }

我希望这是有道理的。感谢您的帮助。

ZedGraph正在尝试检测幅值并简化图形。您可以通过以下操作关闭此选项:

myPane.YAxis.Scale.MagAuto = false;
这将产生y轴标签,如
100000

如果要使用分隔符逗号格式化标签,如
100000

myPane.YAxis.Scale.Format = "#,#";
最后,如果您希望显示
100k
,则需要订阅
ScaleFormatEvent
并返回您自己的格式,如下所示:

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);
}

我也有类似的问题。因此,应用你的方法,它在应用程序上工作,但我也希望打印出一个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;
       }