Q: I am building a horizontal bar chart. When I set the data in a vertical chart everything is ok. When I rotate it (with SeriesType = Horizontal) I get everything at the wrong place. I set the correct data for X and Y but this doesn’t seem to help.
A: When you want to rotate the bar chart there are other settings to be considered other than the data, which you assign to the series. The most important are the settings of the axis. If you have set manually the min and max value at the axes and their interval when you change the data for the chart the axes setting probably are not correct. If you have this bar chart:
BarSeries series0 = barChart1.Series[0] as BarSeries; series0.BarType = BarType.Vertical; series0.XData = new ListHere you can set the axes like this:{ 1, 2, 3, 4 }; series0.YData = new List { 23, 45, 67, 28 };
barChart1.XAxisSettings.MinValue = 0; barChart1.XAxisSettings.Interval = 1; barChart1.XAxisSettings.MaxValue = 4; barChart1.YAxisSettings.MinValue = 0; barChart1.YAxisSettings.MaxValue = 80; barChart1.YAxisSettings.Interval = 10;However, once you change the data for X and Y the settings for the axis will make the chart ugly. So, we must change them also:
barChart1.YAxisSettings.MinValue = 0; barChart1.YAxisSettings.Interval = 1; barChart1.YAxisSettings.MaxValue = 4; barChart1.XAxisSettings.MinValue = 0; barChart1.XAxisSettings.MaxValue = 80; barChart1.XAxisSettings.Interval = 10;You can let the control calculate the axes settings automatically but the result may not be what you need. Here is how to do it:
barChart1.YAxisSettings.MinValue = double.NaN; barChart1.YAxisSettings.Interval = double.NaN; barChart1.YAxisSettings.MaxValue = double.NaN; barChart1.XAxisSettings.MinValue = double.NaN; barChart1.XAxisSettings.MaxValue = double.NaN; barChart1.XAxisSettings.Interval = double.NaN;