如何在 ZedGraph 直方图中设置不同的颜色?

发布于 2024-10-07 18:50:04 字数 294 浏览 0 评论 0原文

我在 ZedGraph 中绘制了一个直方图。我必须为特定范围的值设置特定的颜色。例如:

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

我如何为其中一些设置其他颜色?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

躲猫猫 2024-10-14 18:50:04

您在寻找这样的东西吗?这段代码添加了 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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文