MsChart - 特定值的范围条标记

MsChart - Rangebar marker at a specific value

我只是找不到在范围条 MsChart 上的特定值处添加标记的方法。 假设我们有一个包含 1 个系列和 1 个点的简单范围条形图。该点有 2 个 Y 值(例如:5-20)。如何在 15 处显示三角形标记?

谢谢。

您可以制作两个图表区域并将它们放在彼此之上。使第二个图表区域背景色透明。

private void Form1_Load(object sender, EventArgs e)
{
    chart1.Series.Clear();

    chart1.ChartAreas[0].Position = new ElementPosition(0, 0, 100, 100);

    Series s1 = new Series();
    s1.ChartType = SeriesChartType.RangeBar;
    s1.Points.AddXY(2, 2);
    s1.Points.AddXY(1, 1);

    chart1.Series.Add(s1);

    ChartArea ca2 = new ChartArea();
    chart1.ChartAreas.Add(ca2);
    ca2.Position = new ElementPosition(0, 0, 100, 100);
    ca2.BackColor = Color.Transparent;

    Series s2 = new Series();
    s2.ChartType = SeriesChartType.Point;
    s2.MarkerStyle = MarkerStyle.Triangle;
    s2.MarkerSize = 10;
    s2.Points.AddXY(2, 2);
    s2.ChartArea = ca2.Name;

    chart1.Series.Add(s2);
}

试试这个:

    private void Form1_Load(object sender, EventArgs e)
    {
        DataPoint dp1 = new DataPoint(1, new double[] { 5, 15 });
        dp1.MarkerStyle = MarkerStyle.Triangle;
        dp1.MarkerSize = 12;
        dp1.MarkerColor = Color.Red;

        DataPoint dp2 = new DataPoint(1, new double[] { 15, 20 });

        chart1.Series[0].Points.Add(dp1);
        chart1.Series[0].Points.Add(dp2);
    }