RadChart StackBar

Thread is closed for posting
5 posts, 0 answers
  1. Eric
    Eric avatar
    12 posts
    Member since:
    Apr 2009

    Posted 22 Jul 2011 Link to this post

    Hello,

    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();

    }


  2. Evgenia
    Admin
    Evgenia avatar
    1407 posts

    Posted 27 Jul 2011 Link to this post

    Hi Eric,

    As I read your post - you want to stack 2 bar series where the first one is the count of the items that are older than 8 days and the second serie - the count of those items with less than 8 days. Please correct me if I misunderstand your scenario.
    Also it is hard for us to reproduce your problem from the code snippet provided. Could you please open a new formal support thread and send us a sample runnable project so that we will get back to you with our findings?

    Best wishes,
    Evgenia
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Eric
    Eric avatar
    12 posts
    Member since:
    Apr 2009

    Posted 05 Aug 2011 Link to this post

    Hello,

    Is there a sample for stacked bar that you can point me to?  I have not found a complete sample anywhere. 
    Thanks.
  5. Evgenia
    Admin
    Evgenia avatar
    1407 posts

    Posted 10 Aug 2011 Link to this post

    Hi Eric,

    The following code snippet demonstrates how to create StackedBar chart bound to a List of Business Objects:
    protected void Page_Load(object sender, EventArgs e)
        {
            DataTable tbl = new DataTable();
            DataColumn col = new DataColumn("Bar1");
            col.DataType = typeof(int);
            tbl.Columns.Add(col);
            col = new DataColumn("Bar2");
            col.DataType = typeof(int);
            tbl.Columns.Add(col);
            col = new DataColumn("Name");
            col.DataType = typeof(string);
            tbl.Columns.Add(col);
            col = new DataColumn("Status");
            tbl.Columns.Add(col);
      
            int size = 4;
            string[] labels = new string[]{"Toyota", "Mazda", "Mini", "Renault", "Opel"};        
            int maxLen = size.ToString().Length;
            for (int i = 0; i <= size; i++)
            {
                tbl.Rows.Add(new object[]{i+1, i+2, labels[i]});
            }
            ChartSeries series1 = new ChartSeries();
            series1.DataYColumn = "Bar1";
            RadChart1.AddChartSeries(series1);
            ChartSeries series2 = new ChartSeries();
            series2.DataYColumn = "Bar2";
            RadChart1.AddChartSeries(series2);
            RadChart1.PlotArea.XAxis.DataLabelsColumn = "Name";
            RadChart1.DefaultType = Telerik.Charting.ChartSeriesType.StackedBar;
            RadChart1.DataSource = tbl;
            RadChart1.DataBind();
    }

    Some notes about it - the DataLabelsColumn property of the XAxis is used to bind custom labels to the XAxis. The DataYColumn property is used to bind the Series YValues to a business object's property.
     
    Best wishes,
    Evgenia
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  6. Eric
    Eric avatar
    12 posts
    Member since:
    Apr 2009

    Posted 15 Aug 2011 Link to this post

    Thank you.  That is all I needed. 
    Eric
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017