I am attempting to create a Stacked Bar Chart and have so far been unsuccessful. I've attached an image to show you where I'm at and wrote in what I am looking for.. What I really need is the codes (ALAM and DOKE) to be along the X-Axis where currently there is 1 and 2. I also need to show 2 levels of counts for each code, which I kind of have working. I need a count for items that are older than 8 days and a count for items that are 8 items that are 8 and younger. I get the stacked look by creating 2 series, but I can't seem to split out each code by itself.
Thanks
Here is my code. I use an existing data table then manipulate with linq.
----------------------------------------------------------------------------------------------------------------------------------------------------
private void PopulateChart(DataTable dt)
{
// pull fields I need an calculate the shift age.
var query1 = from data in dt.AsEnumerable()
where data.Field<string>("Facility_Code").ToString().Trim() == "DOKE"
|| data.Field<
string>("Facility_Code").ToString().Trim() == "ALAM"
select new
{
FacilityCode = data.Field<
string>("Facility_Code").ToString()
,ShiftAge = data.Field<
DateTime>("Shift_Date") - DateTime.Now
};
// build 0-7 day chart series
TimeSpan ts = new TimeSpan(8, 0, 0, 0); // time span 8 days
// get all my shifts less than 8 days.
var query2 = from row in query1
where row.ShiftAge < ts
group row by row.FacilityCode into grp
orderby grp.Key
select new
{
FacilityCode = grp.Key,
Shifts = grp.Count()
};
// get all my shifts greater or equal to 8 days
var query3 = from row in query1
where row.ShiftAge >= ts
group row by row.FacilityCode into grp
orderby grp.Key
select new
{
FacilityCode = grp.Key,
Shifts = grp.Count()
};
Telerik.Charting.
ChartSeries csUnderEight = new Telerik.Charting.ChartSeries();
csUnderEight.Type = Telerik.Charting.
ChartSeriesType.StackedBar;
csUnderEight.Name =
"Open shifts within 0-7 days.";
csUnderEight.DataLabelsColumn =
"FacilityCode";
csUnderEight.Appearance.LabelAppearance.LabelLocation = Telerik.Charting.Styles.
StyleSeriesItemLabel.ItemLabelLocation.Outside;
Telerik.Charting.
ChartSeries csEightAndOver = new Telerik.Charting.ChartSeries();
csEightAndOver.Type = Telerik.Charting.
ChartSeriesType.StackedBar;
csEightAndOver.Name =
"Open shifts within 8-14 days.";
csEightAndOver.DataLabelsColumn =
"FacilityCode";
csEightAndOver.Appearance.LabelAppearance.LabelLocation = Telerik.Charting.Styles.
StyleSeriesItemLabel.ItemLabelLocation.Outside;
// csEightAndOver.DataLabelsColumn = "FacilityCode";
this.chartOpenShifts.Series.Add(csUnderEight);
this.chartOpenShifts.Series.Add(csEightAndOver);
foreach (var item in query2)
{
csUnderEight.AddItem(item.Shifts,item.FacilityCode);
}
foreach (var item in query3)
{
csEightAndOver.AddItem(item.Shifts,item.FacilityCode);
}
this.chartOpenShifts.DataGroupColumn = "FacilityCode";
//this.chartOpenShifts.PlotArea.XAxis.DataLabelsColumn = "FacilityCode";
//this.chartOpenShifts.PlotArea.DataTable.Visible = true;
//this.chartOpenShifts.DataSource =query;
//this.chartOpenShifts.Series
//this.chartOpenShifts.PlotArea.XAxis.DataLabelsColumn = "Facility_Code";
//this.chartOpenShifts.DataBind();
}