Reputation: 955
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?
I want red lines for data range inside rectangle, if it is possible.
Upvotes: 1
Views: 2500
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();
}
Upvotes: 2
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