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

StackedBar Binding Values

1 Answer 63 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Vinay
Top achievements
Rank 1
Vinay asked on 12 Sep 2011, 01:21 PM
Hi,
I wanted to create a StackedBar Chart similar to the Demo in FirstLook of Silverlight Chart.
Below is the snapshot of  my sample Data,

  • I want the Cout in XAxis
  • Month with Year on Y axis
  • And IncidentTypes as Legends 

Please provide me with a sample or guide me on how to achieve this. 
Since the code provided in the Demo uses MVVM and is bit complicated.
I am not using MVVM.

1 Answer, 1 is accepted

Sort by
0
Accepted
Garrett
Top achievements
Rank 1
answered on 12 Sep 2011, 05:42 PM
Hi Vinay,

It sounds like you want a Horizontal stacked bar, not a regular stacked bar, correct?

I pasted the code that might help you below. Here's what you want to focus on:

  • Hooking it into your data. It looks like you have a GridView already hooked up to a set of data, but I'm not sure if this is database data or not. If it is, you'll need to set your ViewModel of the radChart as the ViewModel of the GridView. You can do this through the GUI. If you're not able to figure it out, let me know and I'll try to provide a tutorial.
  • Check this code out:

<telerik:AxisX IsDateTime="True"
                                               Step="5"
                                               LabelRotationAngle="45"
                                               LayoutMode="Inside"
                                               LabelStep="2"
                                               DefaultLabelFormat="MM/yyyy">
                                </telerik:AxisX

The above code is what you'll want to play with to get your dates looking the way you want (it's in the code below as well).Poke around in the RadChart Documentation here to find out more.


Here's the code for the whole chart:

<telerik:RadChart Height="500" HorizontalAlignment="Left" Margin="0,0,0,0" Name="radChart1" VerticalAlignment="Top" Width="600">
            <telerik:RadChart.SeriesMappings>
                <telerik:SeriesMapping x:Name="defaultSeriesDefinition">
                    <telerik:SeriesMapping.GroupingSettings>
                        <telerik:GroupingSettings>
                            <telerik:GroupingSettings.GroupDescriptors>
                                <telerik:ChartGroupDescriptor Member="IncidentTypes" />
                            </telerik:GroupingSettings.GroupDescriptors>
                        </telerik:GroupingSettings>
                    </telerik:SeriesMapping.GroupingSettings>
                    <telerik:SeriesMapping.SeriesDefinition>
                        <telerik:StackedBarSeriesDefinition ShowItemLabels="False" ShowItemToolTips="True">
                            <telerik:StackedBarSeriesDefinition.InteractivitySettings>
                                <telerik:InteractivitySettings HoverScope="Series" SelectionMode="Multiple" SelectionScope="Series" />
                            </telerik:StackedBarSeriesDefinition.InteractivitySettings>
                        </telerik:StackedBarSeriesDefinition>
                    </telerik:SeriesMapping.SeriesDefinition>
                    <telerik:SeriesMapping.ItemMappings>
                        <telerik:ItemMapping DataPointMember="XCategory"  FieldName="InitiatedMonth"/>
                        <telerik:ItemMapping DataPointMember="YValue" FieldName="Count"/>
                    </telerik:SeriesMapping.ItemMappings>
                </telerik:SeriesMapping>
            </telerik:RadChart.SeriesMappings>
            <telerik:RadChart.DefaultView>
                <telerik:ChartDefaultView>
                    <telerik:ChartDefaultView.ChartLegend>
                        <telerik:ChartLegend x:Name="radChartLegend" Header="Incident Type" />
                    </telerik:ChartDefaultView.ChartLegend>
                    <telerik:ChartDefaultView.ChartArea>
                        <telerik:ChartArea LegendName="radChartLegend" LabelFormatBehavior="None">
                            <telerik:ChartArea.AxisX>
                                <telerik:AxisX IsDateTime="True"
                                               Step="5"
                                               LabelRotationAngle="45"
                                               LayoutMode="Inside"
                                               LabelStep="2"
                                               DefaultLabelFormat="MM/yyyy">
                                </telerik:AxisX>
                            </telerik:ChartArea.AxisX>
                        </telerik:ChartArea>
                    </telerik:ChartDefaultView.ChartArea>
                    <telerik:ChartDefaultView.ChartTitle>
                        <telerik:ChartTitle />
                    </telerik:ChartDefaultView.ChartTitle>
                </telerik:ChartDefaultView>
            </telerik:RadChart.DefaultView>
        </telerik:RadChart>


Let me know if this helps.

Garrett
Tags
Chart
Asked by
Vinay
Top achievements
Rank 1
Answers by
Garrett
Top achievements
Rank 1
Share this question
or