0

I have created the bar chart but the series are showing vertically.I need to show the bars horizontally.i have used the below code

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);
        }
    }
Nad
  • 4,605
  • 11
  • 71
  • 160
Priya
  • 411
  • 2
  • 7
  • 19

1 Answers1

0

You can define your chart type in your Series variable.

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

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

So your code could look like this:

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

Reference:

Community
  • 1
  • 1
Marco
  • 22,856
  • 9
  • 75
  • 124
  • Thank you @Serv.But i have tried that already but its throwing error like cannot include multiple chartypes at the same time – Priya Jul 01 '15 at 06:26
  • Chart Area Axes - The chart area contains incompatible chart types. For example, bar charts and column charts cannot exist in the same chart area. this is the error throwed – Priya Jul 01 '15 at 06:28
  • This means you have different SeriesChartTypes defined in your chart. I have edited my answer. see: http://stackoverflow.com/questions/23244745/chart-area-axes-the-chart-area-contains-incompatible-chart-types – Marco Jul 01 '15 at 06:30
  • Yeah.I also fixed that by doing the same code.Thank you for your great help.It was fixed.@Serv – Priya Jul 01 '15 at 06:33