你在寻找这样的东西吗?这段代码添加了 50 个 y 值在 0 到 15 之间的随机条。它将 y 值 <5 的条着色为红色,5-10 为黄色,>10 为绿色。
GraphPane pane = zedGraphControl1.GraphPane;
PointPairList list = new PointPairList();
Random rand = new Random();
for (int i = 0; i < 50; i++)
{
list.Add(i, rand.Next(15));
}
BarItem myBar = pane.AddBar("", list, Color.Red);
Color[] colors = { Color.Red, Color.Yellow, Color.Green };
myBar.Bar.Fill = new Fill(colors);
myBar.Bar.Fill.Type = FillType.GradientByY;
myBar.Bar.Fill.RangeMin = 5;
myBar.Bar.Fill.RangeMax = 10;
zedGraphControl1.AxisChange();
这是 ZedGraph 的修改示例:http ://www.zedgraph.org/wiki/index.php?title=Multi-Colored_Bar_Demo