Group by date and stack by ItemType

4 posts, 0 answers
  1. Horst
    Horst avatar
    3 posts
    Member since:
    Jun 2011

    Posted 01 Jul 2011 Link to this post

    My data items look like this:
    Public Class ExportData
        Public Property MyDate As Date
        Public Property ItemType As String
     End Class
    Now I'd like to get a stacked bar chart that groups the items by month and stacks the count of the different item types. For each month I would have a stacked bar that says for example  "Jan 11 = 3 items of type A, 4 items of type B, 5 items of type C".
    Is this possible?

    I tried to with the following XAML code to configure the chart:
    <telerik:RadChart.SeriesMappings>
        <telerik:SeriesMapping x:Name="DataMapping" LegendLabel="Sales">
     
            <telerik:SeriesMapping.SeriesDefinition>
                <telerik:StackedBarSeriesDefinition ShowItemLabels="True" ShowItemToolTips="True" ItemToolTipFormat="#Y">
                    <telerik:StackedBarSeriesDefinition.InteractivitySettings>
                        <telerik:InteractivitySettings HoverScope="Series" SelectionScope="None" />
                    </telerik:StackedBarSeriesDefinition.InteractivitySettings>
                </telerik:StackedBarSeriesDefinition>
            </telerik:SeriesMapping.SeriesDefinition>
     
            <telerik:SeriesMapping.ItemMappings>
                <telerik:ItemMapping FieldName="ItemType" DataPointMember="YValue" AggregateFunction="Count" />
                <telerik:ItemMapping FieldName="MyDate" DataPointMember="XCategory" />
            </telerik:SeriesMapping.ItemMappings>
     
            <telerik:SeriesMapping.GroupingSettings>
                <telerik:GroupingSettings StackGroupFieldName="ItemType" ShouldFlattenSeries="True">
                    <telerik:GroupingSettings.GroupDescriptors>
                        <telerik:ChartYearGroupDescriptor />
                        <telerik:ChartMonthGroupDescriptor />
                        <telerik:ChartGroupDescriptor Member="ItemType" />
                    </telerik:GroupingSettings.GroupDescriptors>
                </telerik:GroupingSettings>
            </telerik:SeriesMapping.GroupingSettings>
     
        </telerik:SeriesMapping>
    </telerik:RadChart.SeriesMappings>
    Thanks for any ideas...
  2. Nikolay
    Admin
    Nikolay avatar
    386 posts

    Posted 06 Jul 2011 Link to this post

    Hi Horst,

    Could you, please, elaborate a bit more on the specific scenario you are trying to achieve. From the code snippet you've sent it appears that you need DateTime along the X Axis and Categories ( type A, type B, etc. ) on the Y Axis :
    <telerik:ItemMapping FieldName="ItemType" DataPointMember="YValue" AggregateFunction="Count" />

    which would not work, as the Y axis is numerical, so you would need to add another numeric property, for example double, to map to the YValue. Then you could map the string property ItemType to LegendLabel and get the desired chart.

    In case we have misunderstood your specific scenario, it would be very helpful for us if you're able to open a support ticket and attach a picture of what the chart needs to look like.

    Kind regards,
    Nikolay
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. UI for WPF is Visual Studio 2017 Ready
  4. Horst
    Horst avatar
    3 posts
    Member since:
    Jun 2011

    Posted 06 Jul 2011 Link to this post

    Example for desired stacked bar chart
    (grouped by date on X axis, count of different item types A,B,C on Y axis):

    10 +  +---+       
      |  |   |       
      |  | A |       
      |  |   |       
      |  +---+       
      |  | B |  +---+
    5  +  +---+  | A |
      |  |   |  +---+
      |  |   |  | B |
      |  | C |  |   |
      |  |   |  +---+
      |  |   |  | C |
    0  +  +---+  +---+
         Jan    Feb
  5. Nikolay
    Admin
    Nikolay avatar
    386 posts

    Posted 08 Jul 2011 Link to this post

    Hi Horst,

    In order to achieve a chart like the presented one, you would need to create 3 series mappings, each with a StackedBarSeriesDefinition.The ItemMappings should look like this :
    <telerik:SeriesMapping.ItemMappings>
                            <telerik:ItemMapping DataPointMember="YValue" AggregateFunction="Count" />
                            <telerik:ItemMapping FieldName="MyDate" DataPointMember="XCategory" />
                            <telerik:ItemMapping FieldName="ItemType" DataPointMember="Label" />
                        </telerik:SeriesMapping.ItemMappings>

    Please, note that you do not map any property to YValue, but use the Aggregate Function count.

    After that, for each mapping, you should add a month group descriptor and a FilterDescriptor for "ItemType" :
    <telerik:SeriesMapping.GroupingSettings>
                            <telerik:GroupingSettings ShouldFlattenSeries="True">
                                <telerik:GroupingSettings.GroupDescriptors>
                                    <telerik:ChartMonthGroupDescriptor />
                                </telerik:GroupingSettings.GroupDescriptors>
                            </telerik:GroupingSettings>
                        </telerik:SeriesMapping.GroupingSettings>
      
                        <telerik:SeriesMapping.FilterDescriptors>
                            <telerik:FilterDescriptor Member="ItemType" Operator="IsEqualTo" Value="C" />
                        </telerik:SeriesMapping.FilterDescriptors>

    Hope this would help.

    Regards,
    Nikolay
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Back to Top