how to chart this data?

Thread is closed for posting
2 posts, 0 answers
  1. Daniel Sprague
    Daniel Sprague avatar
    17 posts
    Member since:
    Feb 2010

    Posted 13 Mar 2013 Link to this post

    Need some direction on how to implement this. Any and all assistance is greatly appreciated!
    Have a rather abstract business problem, but is huge in my company, so I’m translating it into something simpler to understand.
    We’ve collected data on how much coffee people drink, on a daily basis, and need to chart it, showing how much they actually consumed compared to what they should have consumed.

    The Data looks like this:

    Person                  DateExamined  Budgeted Cups                 Actual Cups Consumed
    Fred                       3/1/13                   2                                              1
    Fred                       3/2/13                   2                                              4
    Fred                       3/3/13                   2                                              2
    Bob                        3/1/13                   3                                              5
    Bob                        3/2/13                   3                                              4
    Bob                        3/3/13                   3                                              5
    Steve                    3/1/13                   1                                              1
    Steve                    3/2/13                   1                                              0
    Steve                    3/3/13                   1                                              0

    So by looking at the data we can see how much coffee people actually drank, compared to what they were supposed (budgeted) to drink, on a daily basis.

    In the RadChart, I need this charted with a Horizontal Line, with the dates being the x-axis labels.  The line series is the part I’m stumped on.  For the data above, the chart should show a total of 6 lines… more precisely, 3 “groups” of 2 lines… each of the 3 groups being 1 of the persons… the 2 lines being the budget and actual, so one can clearly see when people went over or under.

    Thanks for all feedback on this.
  2. Missing user
    Missing user avatar

    Posted 18 Mar 2013 Link to this post

    Hello Daniel,

    You'll have to manually populate the data in the chart, since your problem has to be solved through grouping and RadChart doesn't currently offer such a feature. However, you can easily group your data using the GroupBy Linq extension method.

    Suppose the data for a single person is stored in a business object defined as follows:
    public class BudgetedVsActualConsumption
        public DateTime DateExamined { get; set; }
        public string Person { get; set; }
        public int BudgetedCups { get; set; }
        public int ActualCups { get; set; }

    Assuming you have a single collection of BudgetedVsActualConsumption items populated with the sample data you posted, you need only follow this sample code snippet:
    var groupedData = GetSampleData().GroupBy(bvac => bvac.Person);
    foreach (var group in groupedData)
        ChartSeries seriesBudget = new ChartSeries() { Type = ChartSeriesType.Line };
        ChartSeries seriesConsumption = new ChartSeries() { Type = ChartSeriesType.Line };
        seriesBudget.Name = group.Key + " Budget";
        seriesConsumption.Name = group.Key + " Consumption";
        foreach (var item in group)
            seriesBudget.Items.Add(new ChartSeriesItem { XValue = item.DateExamined.ToOADate(), YValue = item.BudgetedCups });
            seriesConsumption.Items.Add(new ChartSeriesItem { XValue = item.DateExamined.ToOADate(), YValue = item.ActualCups });

    All the best,
    Ivan N.
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top