赢得表格图表 [英] Win Form Charting
问题描述
我可能问错了问题,但我需要的是在我的 Windows 窗体图表中添加一个指导线".换句话说,我有一个包含简单数据系列的图表,我需要在通过分数或 80% 的 y 轴上画一条线.我不想添加第二个系列,因为第一个系列的数据点数量不确定.有没有一种简单的方法可以在 y 轴上简单地画一条线?下面的虚线是我要拍摄的(不需要箭头).
I may be asking the wrong question, but what I need is to add a "Guide Line" to my windows form chart. In other words I have a chart with a simple data series and I need to draw a line on the y axis at the passing score, or 80%. I don't want to add a second series as the first series has an undetermined number of data points. Is there a simple way to simply draw one line on the y axis? The dashed line below is what I am shooting for(it does not need the arrows).
100|
|
90|
| o
80|<----------------------->
|
70| o o
|
60| o
| o o
50|o o
|_________________________
1 2 3 4 5 6 7 8 9
推荐答案
您可以添加StripLine.
使用StripWidth
设置行位置的属性:
Use StripWidth
property to set line position:
var series = chart1.Series[0]; //series object
var chartArea = chart1.ChartAreas[series.ChartArea];
chartArea.AxisY.StripLines.Add(new StripLine
{
BorderDashStyle = ChartDashStyle.Dash,
BorderColor = Color.DarkBlue,
StripWidth = 80//Here is your y value
});
更新:此答案的先前版本使用了 Interval
而不是 StripWidth
.正如@dthor 在评论中正确指出设置Interval
将绘制一条重复的带状线.在上面的例子中,Interval
默认设置为 0.
UPDATE: Previous version of this answer used Interval
instead of StripWidth
. As @dthor correctly pointed out in the comments setting the Interval
will draw a repeated strip line. In the example above, Interval
is set to 0 by default.
这篇关于赢得表格图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!