Blast
Blast

Reputation: 955

ZedGraph different line colors

I wanna change the line color permanently if points > 100; I mean i wanna see Red lines on graph for data are greater than 100 and green for data is smaller than 100. How can i do this?

enter image description here

I want red lines for data range inside rectangle, if it is possible.

Upvotes: 1

Views: 2500

Answers (2)

SanVEE
SanVEE

Reputation: 2070

I don't think it's possible to change the color of few points in the curve, but you can change the color of a region using BoxObject of Zedgraph.

Try the following:

 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

Upvotes: 2

vgru
vgru

Reputation: 51292

Check out the Gradient-By-Value example chart. That chart uses the third coordinate (Z) to indicate the color of a point, by setting:

curve.Symbol.Fill.Type = FillType.GradientByZ;

Similarly, you can use GradientByY to indicate that y-axis values should be used. It seems however, that if RangeMin and RangeMax are equal, wrong color will be applied to the entire chart, so you need to make them differ by a relatively small value.

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;

Upvotes: 3

Related Questions