Winforms图表:如何启用背景颜色标尺 [英] Winforms chart: how to enable background color gauge

查看:808
本文介绍了Winforms图表:如何启用背景颜色标尺的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一种在Winform图表控制库中启用自定义背景颜色标准的方法。以下是一个示例:





查看绿色,黄色和红色在后台?



现在,我需要一种方式来自定义背景颜色标尺通过控制开始/结束Y值,颜色本身,以及不同颜色的数量。



提前感谢!

解决方案

您可以添加


I'm looking for a way to enable custom background color gauge in the Winform chart control library. Here is an example:

See the green, yellow, and red color in the background?

Now, I need is a way to customize the background color gauge by controlling the starting/ending Y values, the color itself, as well as the number of different colors.

Thanks in advance!

解决方案

You can do that by adding StripLines to the y-Axis of the ChartArea.

Their positions and sizes are controll by their StripWidth, Interval and IntervalOffset properties.

All values are set in data values, so in the example above the three lines, bottom to top have StripWidth of 30, 40 and 30; their IntervalOffsets are 0, 30 and 70 and all have an Interval of 0, which means they don't repeat.

Let's try it:

Axis ay = chart1.ChartAreas[0].AxisY;
ay.Minimum = 0;
ay.Maximum = 100;

StripLine sl0 = new StripLine();
sl0.BackColor = Color.FromArgb(64, Color.LightSeaGreen);
sl0.StripWidth = 30;
sl0.IntervalOffset = 0;

StripLine sl1 = new StripLine();
sl1.BackColor = Color.FromArgb(64, Color.LightGoldenrodYellow);
sl1.StripWidth = 40;
sl1.IntervalOffset = 30;

StripLine sl2 = new StripLine();
sl2.BackColor = Color.FromArgb(64, Color.LightSalmon);
sl2.StripWidth = 30;
sl2.IntervalOffset = 70;

chart1.ChartAreas[0].AxisY.StripLines.Add(sl0);
chart1.ChartAreas[0].AxisY.StripLines.Add(sl1);
chart1.ChartAreas[0].AxisY.StripLines.Add(sl2);

这篇关于Winforms图表:如何启用背景颜色标尺的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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