如何在ZedGraph直方图中设置不同的颜色? [英] How can I set different colors in a ZedGraph histogram?

查看:575
本文介绍了如何在ZedGraph直方图中设置不同的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆