This is a migrated thread and some comments may be shown as answers.

radChart Grouping

2 Answers 34 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Lorne
Top achievements
Rank 1
Lorne asked on 21 Sep 2012, 04:19 PM
Hi,
I am currently using Silverlight 4, and Telerik.Windows.Controls.Charting v 2011.1.315.1040

Can you help me without doing an upgrade? 
without pointing me to your demos (because they are on silverlight 5) Can you please help?

I am trying to create a bar chart with a Category on the X Axis.  Each Category will contain 3 (unstacked) bars representing JobCount, EstHrs, ActHrs.  I am attaching an excel spreadsheet to show you exactly how I need the data to look.
I have gone about this several different ways and haven't got it to work. 

I have created a BarchartItem to hold the data that looks like this:
public class CategoryBarchartItem
   {
       public int JobCount { get; set; }
       public decimal EstHrsCount { get; set; }
       public decimal ActHrsCount { get; set; }
       public string Category { get; set; }
       public int ItemId { get; set; }
}

I have created a xaml that looks like this:
    <telerik:RadChart Name="Chart" ItemsSource="{Binding}">
        <telerik:RadChart.SeriesMappings>
            <tCharting:SeriesMapping>
                <tCharting:SeriesMapping.SeriesDefinition>
                    <tCharting:BarSeriesDefinition />
                </tCharting:SeriesMapping.SeriesDefinition>
                <tCharting:SeriesMapping.GroupingSettings>
                    <tCharting:GroupingSettings ShouldCreateSeriesForLastGroup="True">
                        <tCharting:GroupingSettings.GroupDescriptors>
                            <tCharting:ChartGroupDescriptor Member="JobCount" />
                            <tCharting:ChartGroupDescriptor Member="ActHrsCount" />
                            <tCharting:ChartGroupDescriptor Member="EstHoursCount" />
                        </tCharting:GroupingSettings.GroupDescriptors>
                    </tCharting:GroupingSettings>
                </tCharting:SeriesMapping.GroupingSettings>
                <tCharting:SeriesMapping.ItemMappings>
                    <tCharting:ItemMapping FieldName="Value" DataPointMember="YValue"/>
                    <tCharting:ItemMapping FieldName="Description" DataPointMember="XCategory"/>
                </tCharting:SeriesMapping.ItemMappings>
            </tCharting:SeriesMapping>
        </telerik:RadChart.SeriesMappings>
    </telerik:RadChart>
</UserControl>

I get an error: Exception has been thrown by the target of an invocation when I try to assign my data to the DataContext

I also tried grouping the data myself:
private void PopulateData()
     {
         //take raw data and group it
         var query = from jh in JobHours
                     group jh by jh.CategoryName into g
                     select new
                     {
                         Actualhours = g.Sum(jh => jh.ActualTime),
                         EstimatedHours = g.Sum(jh => jh.EstimatedTime),
                         currentCategory = g.Key,
                         currentJobCount = g.Count()
                     };
         List<CategoryBarchartItem> chartItems = new List<CategoryBarchartItem>();
         int counter = 0;
         foreach (var myjobCount in query)
         {
             chartItems.Add(new CategoryBarchartItem
                             {
                                 ActHrsCount = myjobCount.Actualhours ?? 0,
                                 EstHrsCount = myjobCount.EstimatedHours ?? 0,
                                 JobCount = myjobCount.currentJobCount,
                                 Category = myjobCount.currentCategory,
                                 ItemId = counter
                             });
             counter++;
         }
         DataContext = chartItems;
     }

and put it into a different XAML like this:
<UserControl x:Class="Macu.MarketingMinutes.Controls.Charts.JobHoursByCategory"
    xmlns:tCharting="clr-namespace:Telerik.Windows.Controls.Charting;assembly=Telerik.Windows.Controls.Charting"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
    <telerik:RadChart Name="Chart" ItemsSource="{Binding}">
        <telerik:RadChart.SeriesMappings>
            <telerik:SeriesMapping LegendLabel="Jobs">
                <telerik:SeriesMapping.SeriesDefinition>
                    <telerik:BarSeriesDefinition>
                        <telerik:BarSeriesDefinition.Appearance>
                            <telerik:SeriesAppearanceSettings Cursor="Hand" />
                        </telerik:BarSeriesDefinition.Appearance>
                    </telerik:BarSeriesDefinition>
                </telerik:SeriesMapping.SeriesDefinition>
                <telerik:SeriesMapping.GroupingSettings>
                    <telerik:GroupingSettings ShouldCreateSeriesForLastGroup="True">
                        <telerik:GroupingSettings.GroupDescriptors>
                            <telerik:ChartGroupDescriptor Member="CategoryName"/>
                        </telerik:GroupingSettings.GroupDescriptors>
                    </telerik:GroupingSettings>
                </telerik:SeriesMapping.GroupingSettings>
                <telerik:SeriesMapping.ItemMappings>
                    <telerik:ItemMapping DataPointMember="XCategory" FieldName="CategoryName"/>
                    <telerik:ItemMapping DataPointMember="YValue" FieldName="JobCount"/>
                </telerik:SeriesMapping.ItemMappings>
            </telerik:SeriesMapping>
            <telerik:SeriesMapping LegendLabel="Est.Hours">
                <telerik:SeriesMapping.SeriesDefinition>
                    <telerik:BarSeriesDefinition>
                        <telerik:BarSeriesDefinition.Appearance>
                            <telerik:SeriesAppearanceSettings Cursor="Hand"/>
                        </telerik:BarSeriesDefinition.Appearance>
                    </telerik:BarSeriesDefinition>
                </telerik:SeriesMapping.SeriesDefinition>
                <telerik:SeriesMapping.ItemMappings>
                    <telerik:ItemMapping DataPointMember="XCategory" FieldName="CategoryName"/>
                    <telerik:ItemMapping DataPointMember="YValue" FieldName="EstHrsCount"/>
                </telerik:SeriesMapping.ItemMappings>
            </telerik:SeriesMapping>
            <telerik:SeriesMapping LegendLabel="Act. Hours">
                <telerik:SeriesMapping.SeriesDefinition>
                    <telerik:BarSeriesDefinition>
                        <telerik:BarSeriesDefinition.Appearance>
                            <telerik:SeriesAppearanceSettings Cursor="Hand" />
                        </telerik:BarSeriesDefinition.Appearance>
                    </telerik:BarSeriesDefinition>
                </telerik:SeriesMapping.SeriesDefinition>
                <telerik:SeriesMapping.ItemMappings>
                    <telerik:ItemMapping DataPointMember="XCategory" FieldName="CategoryName"/>
                    <telerik:ItemMapping DataPointMember="YValue" FieldName="ActHrsCount" />
                </telerik:SeriesMapping.ItemMappings>
            </telerik:SeriesMapping>
        </telerik:RadChart.SeriesMappings>
    </telerik:RadChart>
</UserControl>

and I get no data.  Can you help me please to get this to work?

2 Answers, 1 is accepted

Sort by
0
Accepted
Petar Kirov
Telerik team
answered on 24 Sep 2012, 03:10 PM
Hi Lorne,

Thanks for contacting Telerik Support.

I have examined your code and prepared a sample project which I hope produces the result you are looking for (as far as I can tell because you forgot to attach the excel spreadsheet).

There are only 2 modifications I have made in your second XAML code as follows:
  • I have commented out the grouping settings in the Jobs series and
  • I have changed the XCategory binding from CategoryName to Category

Feel free to contact us if you still experience difficulties in setting up your project.

All the best,
Petar Kirov
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
Lorne
Top achievements
Rank 1
answered on 24 Sep 2012, 03:35 PM
sometimes its the dumb things like not using the same variable name.... sigh. thanks for catching that.
Tags
Chart
Asked by
Lorne
Top achievements
Rank 1
Answers by
Petar Kirov
Telerik team
Lorne
Top achievements
Rank 1
Share this question
or