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

Group by date and stack by ItemType

3 Answers 111 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Horst
Top achievements
Rank 1
Horst asked on 01 Jul 2011, 03:34 PM
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...

3 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 06 Jul 2011, 01:20 PM
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!

0
Horst
Top achievements
Rank 1
answered on 06 Jul 2011, 02:54 PM
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
0
Nikolay
Telerik team
answered on 08 Jul 2011, 09:33 AM
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!

Tags
Chart
Asked by
Horst
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Horst
Top achievements
Rank 1
Share this question
or