Hi,
I am trying to generate a 2D side by side stacked bar chart but even though I am getting the bars side by side I am unable to get them stacked. Is there anything that I am missing? I have included a couple of code snippets below for reference.
Thanks
Marshall
DataTable
DtChart = GetEmptyChartData();for (int i = 0; i < ChartDt.Rows.Count; i++)
{
string planName = ChartDt.Rows["plan_name"].ToString();
DtChart.Rows.Add(new object[] { ChartDt.Rows["year"].ToString(), ChartDt.Rows["econ_scen"].ToString(), ChartDt.Rows["plan_name"].ToString(), ChartDt.Rows["value"].ToString(), ChartDt.Rows["name"].ToString(), "" });
}
//dtProvider = new DataTableProvider(DtChart);
//cfxCT = new CrosstabDataProvider();
string[] fileds = { "year" };//DISTINCT fields arrayDataTable YearDt = DataTableToRecordset.SelectDistinct(DtChart, fileds);
int YearCount = YearDt.Rows.Count;int iMutiply = DtChart.Rows.Count / YearCount;
Axis axis = chart.Axis[YearCount];axis.Visible = true;
axis.Min = 0;
axis.Max = DtChart.Rows.Count;
axis.Step = iMutiply;
axis.YAxis = false;
axis.Gridlines =
true;int step = iMutiply;for (int j = 0; j < YearCount; j++)
{
axis.Label[step] = YearDt.Rows[j]["year"].ToString();
step = step + iMutiply;
}
chart.AxisX.LabelAngle = 90;
dtProvider = new DataTableProvider(DtChart);
cfxCT =
new CrosstabDataProvider();cfxCT.DataType[0] = CrosstabDataType.NotUsed;
cfxCT.DataType[1] =
CrosstabDataType.RowHeading;cfxCT.DataType[2] = CrosstabDataType.ColumnHeading;
cfxCT.DataType[3] =
CrosstabDataType.Value;cfxCT.DataType[4] = CrosstabDataType.NotUsed;cfxCT.DataType[5] = CrosstabDataType.NotUsed;
cfxCT.DataSource = dtProvider;
chart.DataSourceSettings.DataSource = cfxCT;
chart.DataBind();
for (int i = 0; i < chart.NSeries; i++)
{
if (this.Variables.Count == 0)//user hasn't selected any variables yet
{
chart.Series.Gallery = Gallery.Lines;
}
else if (this.Variables[0].ChartType == Variable.ChartTypes.Bar)
{
chart.Series.Gallery = Gallery.Bar;
chart.Series.Stacked =
true;chart.Stacked = Stacked.Normal;
}
else if (this.Variables[0].ChartType == Variable.ChartTypes.Line)
{
chart.Series.Gallery = Gallery.Lines;
}
}