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

[Solved] PieChart - labels from variables?

9 Answers 632 Views
Chart for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Andreas
Top achievements
Rank 2
Andreas asked on 10 Dec 2012, 11:25 AM
Dear Telerik,

I'm trying to find a way to solve my "problem" with PieCharts.

In code behind, I'm using the following code line, where "food" "travel" and "bills" are integer variables:
this.pie.DataContext = new List<int> { food, travel, bills };

In XAML, I'm using the following:
<telerik:RadPieChart x:Name="pie" PaletteName="DefaultDark">
    <telerik:PieSeries ItemsSource="{Binding}"/>
</telerik:RadPieChart>

Now, I wonder if it's possible to insert labels in the pie chart, representing the variables in C#?

Regards.

9 Answers, 1 is accepted

Sort by
0
Accepted
Ivaylo Gergov
Telerik team
answered on 11 Dec 2012, 02:05 PM
Hello Andreas,

Thank you for using our RadControls for Windows 8!

You can achieve the desired functionality via declaring ChartSeriesLabelDefinition for your pie series and instructing it to bind the label value to a property from your business object (via ChartSeriesLabelDefinition.Binding property). For example -- if your business object has two properties Value and Category, you can instruct the control to visualize the Value by setting it through the PieSeries.ValueBinding property and visualize the Category as label by setting it through the ChartSeriesLabelDefinition.Binding property. See the code snippet below:

First, create custom class for Data:
public class Data
   {
       public int Value
       {
           get;
           set;
       }
       public string Category
       {
           get;
           set;
       }
   }

Then create sample Data and set it to the chart's DataContext:
List<Data> data = new List<Data>();
data.Add(new Data { Category = "food", Value = 20 });
data.Add(new Data{ Category = "travel", Value = 30});
data.Add(new Data{ Category = "bills", Value = 50});
this.pie.DataContext = data;

Finally, you can declare it in Xaml: 
<telerik:RadPieChart x:Name="pie" PaletteName="DefaultDark" ClipToBounds="False" Width="300" Height="300">
    <telerik:PieSeries ItemsSource="{Binding}" ShowLabels="True">
        <telerik:PieSeries.ValueBinding>
            <telerik:PropertyNameDataPointBinding PropertyName="Value"/>
        </telerik:PieSeries.ValueBinding>
        <telerik:PieSeries.LabelDefinitions>
            <telerik:ChartSeriesLabelDefinition>
                <telerik:ChartSeriesLabelDefinition.Binding>
                    <telerik:PropertyNameDataPointBinding PropertyName="Category" />
                </telerik:ChartSeriesLabelDefinition.Binding>              
            </telerik:ChartSeriesLabelDefinition>
        </telerik:PieSeries.LabelDefinitions>            
    </telerik:PieSeries>
</telerik:RadPieChart>

I hope this helps. If you have any further questions do not hesitate to contact us again.

 

All the best,
Ivaylo Gergov
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Andreas
Top achievements
Rank 2
answered on 11 Dec 2012, 03:09 PM
Such an awesome and quick response! Works just the way I wanted it to.

Thanks Ivaylo.

Best regards,
Andreas.
0
Shashank
Top achievements
Rank 1
answered on 18 Feb 2013, 02:24 PM
Hi Telerik,

What if I want to show both item name and its percentage on the pie chart?

Thanks,
-Shashank
0
Ivaylo Gergov
Telerik team
answered on 21 Feb 2013, 12:07 PM
Hi Shashank,

Thank you for using our controls.

In this case you can create LabelDefinitions and take advantage of ChartSeriesLabelDefinition.Template property. Thus you can control the visual representation of the labels per series basis. I suggest you to take a look at our online help where you can find an example - http://www.telerik.com/help/windows-8-xaml/radchart-labels-chartserieslabeldefinition.html

I hope this information is useful.

Greetings,
Ivaylo Gergov
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Shashank
Top achievements
Rank 1
answered on 25 Feb 2013, 03:20 PM
Thanks,

Please help me by letting me know, how can i have the label moved inside the graph.

i.e currently the position of labels are just outside the corresponding section, all i want to know is how can i have that label inside the pie chart section?
0
Ivaylo Gergov
Telerik team
answered on 26 Feb 2013, 12:50 PM
Hi Shashank,

This is possible by setting Margin.Left property value of the respective ChartSeriesLabelDefinition like this:
<telerik:ChartSeriesLabelDefinition Margin="125,0,0,0"/>

I hope this is useful. Let me know if you need further assistance.

 

Kind regards,
Ivaylo Gergov
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Anand kumar
Top achievements
Rank 1
answered on 28 Mar 2017, 09:36 AM

Hi All,

I want to display value and text in the Pie chart and want to bind it from view model using wpf.
But its not showing the text value .can any one help me to sort this.

<telerik:RadPieChart Grid.Column="2"   Palette="Windows8">
            <telerik:PieSeries ShowLabels="True"   ItemsSource="{Binding Lstexmple}" RadiusFactor="0.6">
                <telerik:PieSeries.DataPoints>
                    
                    
                    <telerik:PieDataPoint Value="{Binding Id1}" Label="{Binding Id2} />
                    <telerik:PieDataPoint Value="15.11" Label="Belgium: 15.11%" />
                    <telerik:PieDataPoint Value="10.35" Label="Holland: 10.35%" />
                    <telerik:PieDataPoint Value="3.55" Label="Luxembourg: 3.55%" />
                </telerik:PieSeries.DataPoints>

                <telerik:PieSeries.LabelDefinitions>
                    <telerik:ChartSeriesLabelDefinition Margin="-40,0,0,0" />
                </telerik:PieSeries.LabelDefinitions>

                <telerik:PieSeries.LabelConnectorsSettings>
                    <telerik:ChartSeriesLabelConnectorsSettings />
                </telerik:PieSeries.LabelConnectorsSettings>
            </telerik:PieSeries>
        </telerik:RadPieChart>

0
Anand kumar
Top achievements
Rank 1
answered on 28 Mar 2017, 09:39 AM
Hi All,
I want to display value and text in the Pie chart and want to bind it from view model using wpf.
But its not showing the text value .can any one help me to sort this.
<telerik:RadPieChart Grid.Column="2"   Palette="Windows8">
            <telerik:PieSeries ShowLabels="True"   ItemsSource="{Binding Lstexmple}" RadiusFactor="0.6">
                <telerik:PieSeries.DataPoints>
                                        
                    <telerik:PieDataPoint Value="{Binding Id1}" Label="{Binding Id2} />
                   
                </telerik:PieSeries.DataPoints>

                <telerik:PieSeries.LabelDefinitions>
                    <telerik:ChartSeriesLabelDefinition Margin="-40,0,0,0" />
                </telerik:PieSeries.LabelDefinitions>

                <telerik:PieSeries.LabelConnectorsSettings>
                    <telerik:ChartSeriesLabelConnectorsSettings />
                </telerik:PieSeries.LabelConnectorsSettings>
            </telerik:PieSeries>
        </telerik:RadPieChart>
0
Martin Ivanov
Telerik team
answered on 31 Mar 2017, 08:01 AM
Hello Anand,

Let me start with that this the Windows8 XAML forum. I recommend you to address your question in the WPF forum.

You can see how to use RadChartView for WPF in a data binding scenario in the Create Data-Bound Chart help article. Note that setting the ItemsSource property and adding items manually in the DataPoints collection is not a good idea. Instead you can set the ItemsSource and ValueBinding properties of the DataPoint. Then you can use ChartSeriesLabelDefinition and its Template property to bind the to the label property from your view model. 

Regards,
Martin
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Chart for XAML
Asked by
Andreas
Top achievements
Rank 2
Answers by
Ivaylo Gergov
Telerik team
Andreas
Top achievements
Rank 2
Shashank
Top achievements
Rank 1
Anand kumar
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or