Jump to content
Software FX Community

Creating a 2D side by side stacked bar chart


marshall77

Recommended Posts

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;

}

}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...