0

目前我正在使用 ZedGraph 来显示我的曲线。我想在 ZedGraph 控件上标记曲线的特定区域并将其标记如下。

在此处输入图像描述

注意:我需要根据文本大小在 X 和 Y 轴上使用不同类型的标记。

提前感谢您的帮助。

4

1 回答 1

1

你有两个选择,

1)使用BoxObject在特定区域绘制如下

在此处输入图像描述

您可以按如下方式使用源代码:

 private void Form1_Load(object sender, EventArgs e)
    {
        // Create an instance of Graph Pane
        GraphPane myPane = zedGraphControl1.GraphPane;

        // Build a PointPairList with points based on Sine wave
        PointPairList list = new PointPairList();
        for (double i = 0; i < 36; i++)
        {
            double x = i * 10.0 + 50.0;
            double y = Math.Sin(i * Math.PI / 15.0) * 16.0;
            list.Add(x, y);
        }

        // Hide the legend
        myPane.Legend.IsVisible = false;

        // Add a curve
        LineItem curve = myPane.AddCurve("label", list, Color.Red, SymbolType.Circle);
        curve.Line.Width = 1.5F;
        curve.Symbol.Fill = new Fill(Color.White);
        curve.Symbol.Size = 5;

        // Make the XAxis start with the first label at 50
        myPane.XAxis.Scale.BaseTic = 50;

        // Fill the axis background with a gradient
        myPane.Chart.Fill = new Fill(Color.White, Color.SteelBlue, 45.0F); 

        // Draw Region 1
        drawRegion(list[0].X, list[10].X,"Positive Cycle");

        // Calculate the Axis Scale Ranges
        zedGraphControl1.AxisChange();

        // Refresh to paint the graph components
        Refresh(); 
    }

    private void drawRegion(double xMin, double xMax, string regName)
    {
        GraphPane pane = zedGraphControl1.GraphPane;

        BoxObj box = new BoxObj(xMin,20, xMax, 40.0, Color.Empty, Color.LightSteelBlue);// Color.FromArgb(225, 245, 225));
        box.Location.CoordinateFrame = CoordType.AxisXYScale;
        box.Location.AlignH = AlignH.Left;
        box.Location.AlignV = AlignV.Top;

        // place the box behind the axis items, so the grid is drawn on top of it
        box.ZOrder = ZOrder.E_BehindCurves;//.D_BehindAxis;//.E_BehindAxis;
        pane.GraphObjList.Add(box);

        // Add Region text inside the box 
        TextObj myText = new TextObj(regName, 160, -15);
        myText.Location.CoordinateFrame = CoordType.AxisXYScale;
        myText.Location.AlignH = AlignH.Right;
        myText.Location.AlignV = AlignV.Center;
        myText.FontSpec.IsItalic = true;
        myText.FontSpec.IsBold = false;
        myText.FontSpec.FontColor = Color.Red;
        myText.FontSpec.Fill.IsVisible = false;
        myText.FontSpec.Border.IsVisible = false;
        pane.GraphObjList.Add(myText);

        zedGraphControl1.Refresh();
    }

2)这有点困难但可行,绘制这里讨论的单独垂直线:1、2添加所需的文本等。

我建议你使用option 1,这比 2 容易得多!

于 2013-07-05T11:39:47.957 回答