Hi,
I am using the charts control from telerik for display piechart. I have created the chart and display the value on chart as per my need. There are three things in the chart so it displays in three colours and in legend shows three values. But there is one problem in the legend it shows “Item 0”, “Item 1”, “Item 2”.
I want to show my content instead of this “Item 0”, “Item 1”, and “Item 2”. I want to replace “Item 0” with “ “Basic portal”, “Item 1” with “Premier Portal” and “Item 2” with “Free space”.
Please help me how to do this.
I have tried the following thing.
RadChart1.DefaultView.ChartLegend.Items.Insert(0, new ChartLegendItem { Label = " Basic portal" });
RadChart1.DefaultView.ChartLegend.Items.Insert(1, new ChartLegendItem { Label = " Premier Portal" });
RadChart1.DefaultView.ChartLegend.Items.Insert(2, new ChartLegendItem { Label = " Free space" });
But in this case it just inserts new legend, “Item 0”, “Item 1”, and “Item 2” are still there in legend.
I also try to clear or remove all but it won’t do that also.
RadChart1.DefaultView.ChartLegend.Items.Clear();
RadChart1.DefaultView.ChartLegend.Items.RemoveAll();
Please help me on this ASAP. Thanks in advance.
Thanks
Daxesh Thoriya
8 Answers, 1 is accepted
You can set the ChartLegend.UseAutoGeneratedItems property to false in order to instruct the chart not to generate legend items on its own.
Hope this helps.
Kind regards,
Manuel
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
We have attached a sample application that uses your code and demonstrates how to apply styles to the legend items that match the default theme colors for pie slices (basically you need to extract from the charting assembly the StylesPalette object that holds the default colors for Pie /Doughnut series types and apply each style to the legend items).
Hope this helps.
Kind regards,
Manuel
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Thanks & Regards,
Yusuf
Certainly you can use the helper class to achieve the desired functionality for spline series as well. Here are the corresponding keys for the series type style palettes used by the chart control:
- "AreaStyle" (Area, StackedArea, StackedArea100, SplineArea, StackedSplineArea, StackedSplineArea100, Range, SplineRange)
- "LineStyle" (Line, StackedLine, Spline, StackedSpline)
- "BarStyle" (Bar, StackedBar, StackedBar100)
- "RadialStyle" (pie, doughnut)
- "CandleStickStyle" (CandleStick)
- "StickStyle" (Stick)
- "BubbleStyle" (Bubble)
Hope this helps.
All the best,
Manuel
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
I have a pie chart with 4 wedges that will always be Green, Red, Yellow and White.
I used your sample in my code, but rather than using the default pie chart styles I have created my own. The result is a correctly styled legend and incorrect pie. How do I take my new stylePalette and apply it to the chart so the legend and the pie match?
I tried the following code, but I think it doesn't like that it is type StylePalette.
<telerikChart:RadChart x:Name="costPieChart"
Loaded="costPieChart_Loaded"
Visibility="Visible"
Style="{StaticResource TelerikPieChartStyle}" >
xaml:
<telerikCharting:StylesPalette x:Key="TelerikPieChartStyle">
<Style TargetType="Shape">
<Setter Property="Stroke"
Value="{StaticResource RadialItemStroke}" />
<Setter Property="StrokeThickness"
Value="{StaticResource RadialItemStrokeThickness}" />
<Setter Property="Fill"
Value="{StaticResource SeriesItem01Fill}" />
</Style>
<Style TargetType="Shape">
<Setter Property="Stroke"
Value="{StaticResource RadialItemStroke}" />
<Setter Property="StrokeThickness"
Value="{StaticResource RadialItemStrokeThickness}" />
<Setter Property="Fill"
Value="{StaticResource SeriesItem02Fill}" />
</Style>
<Style TargetType="Shape">
<Setter Property="Stroke"
Value="{StaticResource RadialItemStroke}" />
<Setter Property="StrokeThickness"
Value="{StaticResource RadialItemStrokeThickness}" />
<Setter Property="Fill"
Value="{StaticResource SeriesItem03Fill}" />
</Style>
<Style TargetType="Shape">
<Setter Property="Stroke"
Value="{StaticResource RadialItemStroke}" />
<Setter Property="StrokeThickness"
Value="{StaticResource RadialItemStrokeThickness}" />
<Setter Property="Fill"
Value="{StaticResource SeriesItem04Fill}" />
</Style>
<SolidColorBrush x:Key="RadialItemStroke"
Color="#FF000000" />
<mscorlib:Double x:Key="RadialItemStrokeThickness">1</mscorlib:Double>
<SolidColorBrush x:Key="SeriesItem01Fill"
Color="Green" />
<SolidColorBrush x:Key="SeriesItem02Fill"
Color="Yellow" />
<SolidColorBrush x:Key="SeriesItem03Fill"
Color="Red" />
<SolidColorBrush x:Key="SeriesItem04Fill"
Color="White" />
You need to set a special well-known resource key ("RadialStyle") to your desired StylesPalette that RadChart will automatically pick up and use when styling the pie wedges.
Attached is a sample application that demonstrates the desired functionality.
Sincerely yours,
Manuel
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
That is exactly what I was looking for.
Cheers,
Sarah