We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How to display Pie Chart legend?

Hello,

I don't know why but I can't make a simple pie chart sample with a legend work.

I created a new business application projet and update the Home class constructor (in Home.xaml.cs file) as follow:

            InitializeComponent();

            this.Title = ApplicationStrings.HomePageTitle;

            Chart myChart = new Chart();         
            ChartArea area = new ChartArea();
            ChartSeries series = new ChartSeries();
            ChartAdornmentInfo adornment = new ChartAdornmentInfo();
            ChartLegend legend = new ChartLegend();           
                                 
            legend.DockPosition = ChartDock.Top;           

            series.Type = ChartTypes.Pie;
            series.Label = "Series1";
            series.IsIndexed = false;
            ChartPieType.SetExplodedIndex(series,1);
            series.DataSource = new ObservableCollection<NamedValue>() {new NamedValue("Part 1", 40), new NamedValue("Part 2", 60)};
            series.BindingPathX = "Name";
            series.BindingPathsY = new List<string>() {"Value"};
           
            // Initialize the Adornment Information.
            adornment.Visible = true;
            adornment.HorizontalAlignment = HorizontalAlignment.Center;
            adornment.VerticalAlignment = VerticalAlignment.Top;           
            adornment.SegmentLabelContent = LabelContent.Percentage;
            adornment.SegmentLabelFontFamily = new FontFamily("Segoe UI");
           
            series.AdornmentsInfo = adornment;

            area.Legends = legend;           
            area.Series.Add(series);
            myChart.Areas.Add(area);

            ContentStackPanel.Children.Add(myChart);


and I added the following class

public class NamedValue
    {
        public string Name{get;set;}       
        public double Value{get;set;}

        public NamedValue(string name, double value)
        {
            Name = name;
            Value = value;

        }
    }

I don't know why but I have no legend in my chart.

Any Idea ?

Thank you

4 Replies

RA Rajkumar Syncfusion Team July 26, 2012 05:32 AM UTC

Hi PierreAlainGaltier,
 
Thanks for your interest in Syncfusion products.
 
We are unable to reproduce the issue and the added code is sufficient enough to display Legends. Please try to set the visibility of Legends as in below code snippet and check whether the legend is visible or not.
Code Snippet:
legend.Visibility = System.Windows.Visibility.Visible;
If you are still having a problem in displaying Legends, please create a direct track incident regarding this issue. So that we can analyze more on this and provide a better solution.
 
Thanks,
Rajkumar B R


SH Scott Harner July 30, 2014 01:09 AM UTC

I realize this is an old thread, but I am trying to get a legend to show with a pie chart using version 10.2.0.75 and am also having no luck. I took the original poster's code and pasted it into a brand new windows phone 7.1 project. The chart shows, but the legend does not. I tried this on one box using vs 2010 express on windows vista and another box using vs 2012 express on windows 8. I notice that there is also no legend when I run the sample browser project that was provided despite the fact that there is legend xaml included with the pie chart.


SS Suresh S Syncfusion Team July 30, 2014 10:48 AM UTC

Hi Scott,

We have introduced the new SfChart control  for Windows Phone from 11.1 version. Could you please upgrade to the latest version?

Regards,
Suresh S


SH Scott Harner July 30, 2014 12:28 PM UTC

It's good to hear that the issue has been addressed in a newer version. I had won a copy of Essential Studio at a user group meeting a while back, but didn't have a reason to use it during my year of support. I finally had a personal project where it made sense to give Essential Studio a try, by adding a pie chart, but unfortunately it is not working in the newest version that I had access to (10.2.0.75). Regardless, thanks for the quick follow-up response.

Loader.
Live Chat Icon For mobile
Up arrow icon