简体   繁体   English

MSChart 控件中的自定义 X/Y 网格线

[英]Custom X/Y grid line in MSChart control

I have a C# windows form with a simple 2D line chart that I want to add custom X or Y axis markers to, and draw a custom grid line (in a highlighted color, dotted line for example).我有一个 C# windows 表格,带有一个简单的 2D 折线图,我想在其中添加自定义 X 或 Y 轴标记,并绘制自定义网格线(以突出显示的颜色,例如虚线)。 I have looked at the customLabels property, but this seems to override the default grid, which I still want to display.我查看了 customLabels 属性,但这似乎覆盖了我仍想显示的默认网格。 This is to illustrate something like a threshold or a cutoff.这是为了说明阈值或截止值之类的东西。 How can I do this with the MSChart control?如何使用 MSChart 控件执行此操作?

Many thanks非常感谢

Could you achieve what you want with striplines?你能用带状线实现你想要的吗?

In the ms chart samples (get it here http://archive.msdn.microsoft.com/mschart ), inside the "Using Custom Labels" section, they use striplines on the Y axis which are quite effective at highlighting ranges of values.在 ms 图表示例中(在此处获取http://archive.msdn.microsoft.com/mschart ),在“使用自定义标签”部分中,它们在 Y 轴上使用带状线,这在突出显示值范围方面非常有效。 They also do not affect the grid... I checked that by changing the sample code a little so I could easily move the boundaries of the striplines around (see below).它们也不会影响网格...我通过稍微更改示例代码检查了这一点,这样我就可以轻松地移动带状线的边界(见下文)。

double low_med = 17; // was 30
double med_hi = 92;  // was 70

// Set Y axis custom labels
axisY.CustomLabels.Add(0, low_med, "Low");
axisY.CustomLabels.Add(low_med, med_hi, "Medium");
axisY.CustomLabels.Add(med_hi, 100, "High");

StripLine stripLow = new StripLine();
stripLow.IntervalOffset = 0;
stripLow.StripWidth = low_med;
stripLow.BackColor = Color.FromArgb(64, Color.Green);

StripLine stripMed = new StripLine();
stripMed.IntervalOffset = low_med;
stripMed.StripWidth = med_hi - low_med;
stripMed.BackColor = Color.FromArgb(64, Color.Orange);

StripLine stripHigh = new StripLine();
stripHigh.IntervalOffset = med_hi;
stripHigh.StripWidth = 100 - med_hi;
stripHigh.BackColor = Color.FromArgb(64, Color.Red);

axisY.StripLines.Add(stripLow);
axisY.StripLines.Add(stripMed);
axisY.StripLines.Add(stripHigh);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM