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

How to change Legend items content

8 Answers 362 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Daxesh
Top achievements
Rank 1
Daxesh asked on 08 Jul 2009, 02:56 PM

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

Sort by
0
Giuseppe
Telerik team
answered on 10 Jul 2009, 10:55 AM
Hi Daxesh,

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.
0
Daxesh
Top achievements
Rank 1
answered on 13 Jul 2009, 03:45 PM
Hi,
Thanks for your reply. I have added this and it works, now it will not show me the autogenerated legend.

But there is one more problem in this. when i added my legend, the colour of the legend is not match with my pie chart. In my legend it shows with white colour. Following is my code.

    RadChart1.DefaultSeriesDefinition = new PieSeriesDefinition();
            RadChart1.DefaultSeriesDefinition.ShowItemToolTips = true;
           
            double[] itm = new double[3];
            itm[0] = 200;
            itm[1] = 24;
            itm[2] = 800;

            ChartLegendItem ch = new ChartLegendItem() { Label = "test" };
            ChartLegendItem ch1 = new ChartLegendItem() { Label = "test1" };
            ChartLegendItem ch2 = new ChartLegendItem() { Label = "test2" };

            ChartLegendItemCollection chC = new ChartLegendItemCollection();
            chC.Add(ch);
            chC.Add(ch1);
            chC.Add(ch2);                                 

            RadChart1.DefaultView.ChartLegend.UseAutoGeneratedItems = false;           
           
            RadChart1.DefaultView.ChartLegend.Items.Add(chC[0]);
            RadChart1.DefaultView.ChartLegend.Items.Add(chC[1]);
            RadChart1.DefaultView.ChartLegend.Items.Add(chC[2]);             
            RadChart1.ItemsSource = itm;   
           
            RadChart1.DefaultView.ChartTitle.Content = "Account info";

Please let me know, what should i do to reslove this.

Thanks,
Daxesh Thoriya
0
Giuseppe
Telerik team
answered on 16 Jul 2009, 10:27 AM
Hi Daxesh,

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.
0
Yusuf
Top achievements
Rank 1
answered on 04 Aug 2009, 06:28 PM
How to achieve similiar functionality for Spline Series? Can we use the same helper class to retrieve the StylePallete and use different style Name? What style to search for? Is it the RadialStyle only or some other name? Also what about other series type? Where can we get information about this?

Thanks & Regards,
Yusuf
0
Giuseppe
Telerik team
answered on 07 Aug 2009, 12:32 PM
Hello 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.
0
Sarah
Top achievements
Rank 1
answered on 23 Oct 2009, 06:22 PM
Hi,
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" />



0
Giuseppe
Telerik team
answered on 29 Oct 2009, 08:50 AM
Hi Sarah,

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.
0
Sarah
Top achievements
Rank 1
answered on 29 Oct 2009, 08:12 PM
Thank you!

That is exactly what I was looking for.

Cheers,
Sarah
Tags
Chart
Asked by
Daxesh
Top achievements
Rank 1
Answers by
Giuseppe
Telerik team
Daxesh
Top achievements
Rank 1
Yusuf
Top achievements
Rank 1
Sarah
Top achievements
Rank 1
Share this question
or