首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在zed图上标记区域

在zed图上标记区域
EN

Stack Overflow用户
提问于 2013-07-05 15:31:37
回答 1查看 2.1K关注 0票数 0

目前我正在使用ZedGraph来显示我的曲线。我想在ZedGraph控件上标记曲线的特定区域,并像下面这样标记它。

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

提前感谢您的帮助。

EN

回答 1

Stack Overflow用户

发布于 2013-07-05 19:39:48

你有两个选择

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

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

代码语言:javascript
复制
 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)这有点困难,但可以在这里讨论绘制单独的垂直线:12,并添加所需的文本等。

我建议你使用option 1,它比2简单得多!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17483418

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档