c# – 如何更改asp.net图表控件系列颜色?

我用这段代码编写简单的图表Web应用程序:

Series Series1 = new Series();
            Series Series2 = new Series();
            Series1.ChartType = SeriesChartType.Column;
            Series1.ChartType = SeriesChartType.Column;

            Series1.Points.Add(30);
            Series2.Points.Add(40);
            Chart1.Series.Add(Series1);
            Chart1.Series.Add(Series2);

代码输出是这样的:
《c# – 如何更改asp.net图表控件系列颜色?》

但我希望向用户显示两列差异,并向我展示一些事情:
《c# – 如何更改asp.net图表控件系列颜色?》

我怎么能为此目的编写代码?谢谢.

最佳答案 如果我没有错,你正在寻找堆栈类型图,你需要添加第三个系列来表示差异,请尝试以下

        Series Series1 = new Series();
        Series Series2 = new Series();
        Series Series3 = new Series(); 
        Series1.ChartType = SeriesChartType.Column;
        Series2.ChartType = SeriesChartType.StackedColumn;
        Series3.ChartType = SeriesChartType.StackedColumn;

        int series1Data=30;
        int series2Data=40;
        int series3Data=series2Data-series1Data;
        series2Data=series1Data;

        Series1.Points.Add(series1Data);
        Series2.Points.Add(series2Data);
        Series3.Points.Add(series3Data);
        Chart1.Series.Add(Series1);
        Chart1.Series.Add(Series2);
        Chart1.Series.Add(Series3);
点赞