MsChart - 具有特定值的Rangebar标记

时间:2016-05-17 20:30:51

标签: c# .net winforms charts mschart

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

处显示三角形标记

谢谢。

2 个答案:

答案 0 :(得分:0)

您可以制作两个图表区域并将它们放在彼此的顶部。使第二个图表区域背面颜色透明。

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

答案 1 :(得分:0)

试试这个:

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

enter image description here