3

如何在 C# 图表库中不画一个空点?我不希望在图表中绘制 11/10 的最后一个值为 0 的空点,但尽管将其设置为空点,但它的绘制值为 0。

在这里查看图表。

在此处输入图像描述

这是代码:

void Main()
{
    System.Windows.Forms.DataVisualization.Charting.Chart chart1 = new Chart();
    ChartArea chartArea1 = new ChartArea("foobar");
    chartArea1.Name = "ChartArea1";
    chart1.ChartAreas.Add(chartArea1);

    chart1.Name = "chart1";
    chart1.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.Fire;     
    Series series1 = new Series("seriesfoo")
     {
         XValueType = ChartValueType.Date,
        ChartArea = "ChartArea1",
        ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedArea,
        Legend = "Legend1",
        Name = "MyGraph",
        IsXValueIndexed = true,
    };

     Series series2 = new Series("seriesbar")
     {
        XValueType = ChartValueType.Date,    
        ChartArea = "ChartArea1",
        ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line,
        Legend = "Legend1",
        Name = "Gap",
        IsXValueIndexed = true,
        YAxisType = System.Windows.Forms.DataVisualization.Charting.AxisType.Secondary,
        YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Double
     };

    chart1.Series.Add(series1);
    chart1.Series.Add(series2);
    chart1.Size = new System.Drawing.Size(797, 267);
    chart1.Text = "chart1";

    int[] dat = {20, 19, 10};
    for (int i = 0; i < dat.Length; i++ )
    {
        // Add X and Y values for a point. 
        chart1.Series[0].Points.AddXY(DateTime.Today.AddDays(i), dat[i]);
    }

    int[] dat2 = {20, 16, 12, 8, 4, 0};
    for (int i = 0; i < dat2.Length; i++ )
    {
        chart1.Series[1].Points.AddXY(DateTime.Today.AddDays(i), dat2[i]);
    }

    chart1.DataManipulator.InsertEmptyPoints(1, IntervalType.Days, "MyGraph, Gap");
    chart1.DataManipulator.IsEmptyPointIgnored  = true;
    MemoryStream stream = new MemoryStream(2048);
    chart1.SaveImage("C:\\temp\\chart.png", ChartImageFormat.Png);
}
4

1 回答 1

3

我找到了答案,不得不设置。

chart1.Series[0].EmptyPointStyle.Color = Color.Transparent;

另外,我想从系列中删除以下属性,这会干扰上述样式,并且尽管设置了空点颜色,但总是在绘制点。

BackGradientStyle = GradientStyle.TopBottom,
于 2013-11-08T17:46:22.940 回答