如何在ZedGraph直方图中设置不同的颜色? [英] How can I set different colors in a ZedGraph histogram?
问题描述
我在ZedGraph中绘制了直方图。我必须为特定范围的值设置特定的颜色。例如:
图形窗格= zedGraph.GraphPane;
list = new PointPairList();
for(int i = 0; i <256; i ++)
{
list.Add(i,array_with_y_values [i]);
}
Pane.AddBar(,list,Color.Red);
我如何设置其他颜色?
你在找这样的东西吗?这段代码添加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
I got a histogram drawn in ZedGraph. And I have to set the specific color for a specific range of the values. For example:
Graph Pane = zedGraph.GraphPane;
list = new PointPairList ();
for (int i = 0; i < 256; i++)
{
list.Add(i, array_with_y_values[i]);
}
Pane.AddBar("", list, Color.Red);
And how I can set the other color for some of them?
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
这篇关于如何在ZedGraph直方图中设置不同的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!