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

时间:2015-12-22 07:08:29

标签: 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);


代码输出是这样的:
enter image description here
但我希望向用户显示两列差异,并向我展示一些事情:
enter image description here
我怎样才能为此目的编写代码?谢谢。

1 个答案:

答案 0 :(得分:2)

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

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