Domanda

Come posso non disegnare un punto vuoto nella libreria di grafici C#? Non voglio che l'ultimo punto vuoto con il valore 0 per 11/10 venga disegnato nel grafico, ma nonostante impostarlo come punto vuoto, è disegnato con un valore di 0.

Dai un'occhiata al grafico qui.

enter image description here

Ecco il codice:

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);
}
È stato utile?

Soluzione

Ho trovato la risposta, ho dovuto impostare.

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

Inoltre, avrei rimosso la proprietà seguente dalla serie, questo interferisce con lo stile sopra e disegnava sempre il punto nonostante impostato il colore del punto vuoto.

BackGradientStyle = GradientStyle.TopBottom,
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top