【问题标题】:Custom X/Y grid line in MSChart controlMSChart 控件中的自定义 X/Y 网格线
【发布时间】:2011-06-29 17:02:54
【问题描述】:

我有一个带有简单 2D 折线图的 C# windows 窗体,我想向其中添加自定义 X 或 Y 轴标记,并绘制自定义网格线(以突出显示的颜色,例如虚线)。我查看了 customLabels 属性,但这似乎覆盖了我仍想显示的默认网格。这是为了说明阈值或截止值之类的东西。如何使用 MSChart 控件执行此操作?

非常感谢

【问题讨论】:

    标签: c# .net plot mschart


    【解决方案1】:

    你能用带状线实现你想要的吗?

    在 ms 图表示例中(在此处获取 http://archive.msdn.microsoft.com/mschart),在“使用自定义标签”部分中,它们在 Y 轴上使用带状线,这对于突出显示值范围非常有效。它们也不会影响网格......我通过稍微更改示例代码检查了这一点,这样我就可以轻松地移动带状线的边界(见下文)。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-14
      • 1970-01-01
      • 2021-07-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多