How can I set different colors in a ZedGraph histogram?

こ雲淡風輕ζ 提交于 2019-12-08 18:03:36

Are you looking for something like this? This piece of code adds 50 bars with random y values between 0 and 15. It will color bars with y values <5 as red, 5-10 as yellow, and >10 as green.

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();

This is a modified example of the ZedGraph one here: http://www.zedgraph.org/wiki/index.php?title=Multi-Colored_Bar_Demo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!