ZedGraph不同的线条颜色

时间:2013-09-12 09:14:09

标签: c# zedgraph

如果要点>我想永久更改线条颜色100;我的意思是我想看到数据图上的红线大于100,数据的绿色小于100.我怎么能这样做?

enter image description here

如果可能,我希望矩形内的数据范围有红线。

2 个答案:

答案 0 :(得分:2)

查看Gradient-By-Value示例图表。该图表使用第三个坐标(Z)通过设置:

来指示点的颜色
curve.Symbol.Fill.Type = FillType.GradientByZ;

同样,您可以使用GradientByY指示应使用y轴值。但是,如果RangeMinRangeMax相等,则错误的颜色将应用于整个图表,因此您需要使它们相差较小的值。

curve.Symbol.Fill = new Fill( Color.Green, Color.Red );
curve.Symbol.Fill.Type = FillType.GradientByY;
curve.Symbol.Fill.RangeMin = 100 - 1e-3;
curve.Symbol.Fill.RangeMax = 100;

答案 1 :(得分:2)

我认为不可能更改曲线中几个点的颜色,但您可以使用Zedgraph的BoxObject来更改区域的颜色。

尝试以下方法:

 private void drawRegion()
    {
        GraphPane pane = zedGraphControl1.GraphPane;

        BoxObj box = new BoxObj(0, 20, 500, 10,Color.Empty, Color.LightYellow);

        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;
        pane.GraphObjList.Add(box);

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

        zedGraphControl1.Refresh();
    }

enter image description here