سؤال

I have the following code works fine:

string[] seriesArray = { "s1", "s2", "s3", "s4", "s5" };
double[] data = { 5, 10, 30, 60, 120 };

for (int i = 0; i < data.Length; i++)
{
    Series series = chartTotalTime.Series.Add(seriesArray[i]);
    series.Points.Add(data[i]);
    chartTotalTime.Series[seriesArray[i]].IsValueShownAsLabel = true;
    series.ChartType = SeriesChartType.Column;
}

When I change the code to SeriesChartType.Bar it breaks, just shows a white box with a red cross through it. Can someone tell me why? It seems odd considering it is pretty much the same chart rotated... I can find very few examples of how to implement this control.

Edited to add designer code:

        // 
        // chartTotalTime
        // 
        chartArea1.Name = "ChartArea1";
        this.chartTotalTime.ChartAreas.Add(chartArea1);
        legend1.Name = "Legend1";
        this.chartTotalTime.Legends.Add(legend1);
        this.chartTotalTime.Location = new System.Drawing.Point(35, 3);
        this.chartTotalTime.Name = "chartTotalTime";
        series1.ChartArea = "ChartArea1";
        series1.Legend = "Legend1";
        series1.Name = "Series1";
        this.chartTotalTime.Series.Add(series1);
        this.chartTotalTime.Size = new System.Drawing.Size(300, 300);
        this.chartTotalTime.TabIndex = 0;
        this.chartTotalTime.Text = "chart1";
هل كانت مفيدة؟

المحلول

I got your problem. Remove the defalut series (series1) added by the chart control. This should fix your problem.

The default series is of type SeriesCharType.Column. You cannot mix series with different chart type. When all the series are of Column type then no issue in displaying. But when you change the type to Bar in the code, it is not compatible with the default series type.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top