Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
677 views
in Technique[技术] by (71.8m points)

c# - Winforms chart: how to enable background color gauge

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

enter image description here

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

Their positions and sizes are controlled 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);

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...