Hi,
We are trying to create a stacked bar chart, but unfortunately we don’t seem to be able to get the chart to respect the minimum X-axis which always seems to set at zero.
We are trying to create a chart that looks like this:
Here is out code example. We would greatly appreciate if anybody has any feedback as to what we are doing wrong.
Thank you so much.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
string[] categories = new string[]
{
"Part time work",
"Private school",
"Build wealth",
"Wealth protection",
"Retirement",
"Bequeath to estate",
"Holiday",
"Car",
"Income in retirement"
};
double[] startDates = new double[]
{
45658,
45292,
44927,
44927,
44927,
44927,
44927,
44927,
48214
};
double[] duration = new double[]
{
2556,
2192,
3661,
3661,
3287,
10592,
365,
451,
7305
};
double[] totalLength = startDates.Select((x, index) => x + duration[index]).ToArray();
ChartType chartType = ChartType.BarStacked;
Shape shape = builder.InsertChart(chartType, 432, 252);
Chart chart = shape.Chart;
ChartSeriesCollection seriesColl = chart.Series;
seriesColl.Clear();
seriesColl.Add("Start dates", categories, startDates.ToArray());
seriesColl.Add("Duration", categories, duration.ToArray());
//seriesColl.Add("Start dates", startDates, startDates.ToArray());
//seriesColl.Add("Duration", startDates, duration.ToArray());
chart.Series[0].Format.Fill.Visible = false;
chart.Title.Show = false;
chart.Legend.Position = LegendPosition.None;
ChartAxis xAxis = chart.AxisX;
// Set X axis bounds.
xAxis.Scaling.Minimum = new AxisBound(startDates.Min());
xAxis.Scaling.Maximum = new AxisBound(totalLength.Max());
chart.AxisX.NumberFormat.FormatCode = "dd MMM yy";
doc.Save(@"C:\Temp\PrimeSolve\gantt-demo.docx");