It's really a simple task I am doing here. I need to put two series as StackedColumn and 1 Point series together in one ChartArea. Below is the code. Each series only has three DataPoints for test purpose.
The resulting chart looks in the first picture below. The width of the stacked column looks slim. If I change the data of the Point series to 1 point per month over the three months, the resulting stacked column width looks just fine (picture 2). Also, if I use Column instead of StackedColumn for s1 and s2, the column width will be all good (Picture 3), no matter what data in the Point series s3.
Can anybody explain what's going on here and how to fix the problem in picture 1.
Series s1 = new Series("s1");
s1.ChartType = SeriesChartType.StackedColumn;
//s1.ChartType = SeriesChartType.Column;
s1.XValueType = ChartValueType.Date;
s1.Points.Add(new DataPoint((new DateTime(2016, 1, 1)).ToOADate(), 100));
s1.Points.Add(new DataPoint((new DateTime(2016, 2, 1)).ToOADate(), 100));
s1.Points.Add(new DataPoint((new DateTime(2016, 3, 1)).ToOADate(), 100));
Series s2 = new Series("s2");
s2.ChartType = SeriesChartType.StackedColumn;
//s2.ChartType = SeriesChartType.Column;
s2.XValueType = ChartValueType.Date;
s2.Points.Add(new DataPoint((new DateTime(2016, 1, 1)).ToOADate(), 200));
s2.Points.Add(new DataPoint((new DateTime(2016, 2, 1)).ToOADate(), 200));
s2.Points.Add(new DataPoint((new DateTime(2016, 3, 1)).ToOADate(), 200));
Series s3 = new Series("s3");
s3.ChartType = SeriesChartType.Point;
s3.XValueType = ChartValueType.Date;
s3.Points.Add(new DataPoint((new DateTime(2016, 1, 1)).ToOADate(), 400));
s3.Points.Add(new DataPoint((new DateTime(2016, 1, 4)).ToOADate(), 400));
s3.Points.Add(new DataPoint((new DateTime(2016, 1, 7)).ToOADate(), 400));
//s3.Points.Add(new DataPoint((new DateTime(2016, 1, 1)).ToOADate(), 400));
//s3.Points.Add(new DataPoint((new DateTime(2016, 2, 4)).ToOADate(), 400));
//s3.Points.Add(new DataPoint((new DateTime(2016, 3, 7)).ToOADate(), 400));
cht.Series.Add(s1); cht.Series.Add(s2); cht.Series.Add(s3);
cht.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Months;
cht.ChartAreas[0].AxisX.Interval = 1;
cht.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
cht.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
As per MSDN on StackedColumn:
Here is says:
Since the
Point
and theStackedColumn
series' are not aligned, the columns make room for the missing columns.This can't really be avoided if you want more points to show than stacked columns because :
You could try to overlay a second
ChartArea
with the first one and then add a Point series. See here for two examples! It may take some test to find the right way to set up the second chartarea and its axes..