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

RadChartView. How to use RadLegend??

2 Answers 523 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
srikanth
Top achievements
Rank 1
srikanth asked on 28 Mar 2013, 01:13 PM
Hello. I'm using RadCartesianChart to show some data in Stacked Bar Series. I want to have dynamic number of series and for that i use
RadCartesianChart.SeriesProvider. I want to bind legend to my chart but legend doesn't display at the window. Here is snippets of code that i use in XAML:

        <telerik1:RadCartesianChart x:Name="Chart"
                                    Grid.Row="1"
                                    Palette="Arctic">
            <telerik1:RadCartesianChart.HorizontalAxis>
                <telerik1:CategoricalAxis />
            </telerik1:RadCartesianChart.HorizontalAxis>
            <telerik1:RadCartesianChart.VerticalAxis>
                <telerik1:LinearAxis />
            </telerik1:RadCartesianChart.VerticalAxis>
            <telerik1:RadCartesianChart.Grid>
                <telerik1:CartesianChartGrid StripLinesVisibility="Y">
                    <telerik1:CartesianChartGrid.YStripeBrushes>
                        <SolidColorBrush Color="#F2F2F2" />
                        <SolidColorBrush Color="Transparent" />
                    </telerik1:CartesianChartGrid.YStripeBrushes>
                </telerik1:CartesianChartGrid>
            </telerik1:RadCartesianChart.Grid>

            <telerik1:RadCartesianChart.SeriesProvider>
                <telerik1:ChartSeriesProvider Source="{Binding DailyDatas}">
                    <telerik1:ChartSeriesProvider.SeriesDescriptors>

                        <telerik1:CategoricalSeriesDescriptor CategoryPath="HourName"
                                                              ItemsSourcePath="Data"
                                                              ValuePath="Value">
                            <telerik1:CategoricalSeriesDescriptor.Style>
                                <Style TargetType="telerik1:BarSeries">
                                    <Setter Property="CombineMode" Value="Stack" />
                                </Style>
                            </telerik1:CategoricalSeriesDescriptor.Style>
                        </telerik1:CategoricalSeriesDescriptor>

                    </telerik1:ChartSeriesProvider.SeriesDescriptors>
                </telerik1:ChartSeriesProvider>

            </telerik1:RadCartesianChart.SeriesProvider>
        </telerik1:RadCartesianChart>
        
        <telerik1:RadLegend Items="{Binding ElementName=Chart, Path=LegendItems}"/>

DailyDatas is an ObservableCollection of DailyData:

    public class HourInfo
    {
        public string HourName { get; set; }
        public double? Value { get; set; }
    }

    public class DailyData
    {
        public string RoleName { get; set; }
        public ObservableCollection<HourInfo> Data { get; set; }
    }

What am i doing wrong? Maybe there is another way to make dynamic number of stacked bar series?
Suggest me please asap! Thank you in advance!

2 Answers, 1 is accepted

Sort by
0
Accepted
Petar Marchev
Telerik team
answered on 01 Apr 2013, 07:46 AM
Hello Srikanth,

You can check our Browsers example where the described is achieved. I think you need to simply add a Setter targeting the LegendSettings property: 

<Style TargetType="telerik1:BarSeries">
 <Setter Property="CombineMode" Value="Stack" />
 <Setter Property="LegendSettings">
  <telerik1:SeriesLegendSettings Title="{Binding RoleName}" />
 </Setter>

By default the series are created with no legend settings. This is the way to tell the chart not to produce legend a item for a series. When you need to have a legend item for a series you must set the LegendSettings property of the series in mind. Let us know if you need further help.

Regards,
Petar Marchev
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
srikanth
Top achievements
Rank 1
answered on 01 Apr 2013, 08:23 AM
Thank you a lot! All is working correctly!
Tags
ChartView
Asked by
srikanth
Top achievements
Rank 1
Answers by
Petar Marchev
Telerik team
srikanth
Top achievements
Rank 1
Share this question
or