如何在asp.net中创建水平条形图

时间:2015-07-01 06:10:48

标签: asp.net

我创建了条形图但该系列正在显示垂直。我需要显示水平 .i使用下面的代码

private void LoadChartData(DataTable initialDataSource)
    {
        for (int i = 1; i < initialDataSource.Columns.Count; i++)
        {
            Series series = new Series();
            foreach (DataRow dr in initialDataSource.Rows)
            {
                int y = (int)dr[i];
                series.Points.AddXY(dr["Closing_Month"].ToString(), y);
            }
            Chart1.Series.Add(series);
        }
    }

1 个答案:

答案 0 :(得分:0)

您可以在Series变量中定义图表类型。

/*Horizontal bars*/
series.ChartType = SeriesChartType.Bar;

/*Vertical columns*/
series.ChartType = SeriesChartType.Column;

所以你的代码看起来像这样:

private void LoadChartData(DataTable initialDataSource)
{
    for (int i = 1; i < initialDataSource.Columns.Count; i++)
    {
        Series series = new Series();
        /*make sure every series is of the same chart type*/
        foreach (Series series in chart.Series)
        {
            series.ChartType = SeriesChartType.Bar;
        }
        foreach (DataRow dr in initialDataSource.Rows)
        {
            int y = (int)dr[i];
            series.Points.AddXY(dr["Closing_Month"].ToString(), y);
        }
        Chart1.Series.Add(series);
    }
}

参考: