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

PieSeries collection legend

Hi,

We are trying to have a legend that makes sense with a chart displaying a collection of PieSeries. Something like the picture "expected.png" in the attach file. There is also an example of the code we use to build our Pie chart.

Thanks,
Mathieu

Attachment: PieSeries_Collection_Legend_c82b2506.zip

9 Replies

SS Suresh S Syncfusion Team July 18, 2014 11:06 AM UTC

Hi Mathieu,


Thanks for using Syncfusion products.


We have analyzed the reported query, currently we don’t have support for connector line for legends. However, we have used Annotations to achieve your requirement. Also, we have prepared sample based on your query. Please download it from the given below location.


Please let us know if you require further assistance on this.


Regards,

Suresh S 


Attachment: WPF_d7234b3a.zip


MG Mathieu Guérin July 18, 2014 02:55 PM UTC

Hi,

Thanks for the quick reply.

In our solution we have to build a collection of PieSeries that can change over time, with an buildChart button. More like the example of code in attach file. I guess the only way to have a legend that make sense is to add code in code behind for the XAML file ? Also is there any Event like OnChartDataChanged where we can add the code of the legend ?

Thanks,
Mathieu

Attachment: WPF_d1beddb8.zip


SS Suresh S Syncfusion Team July 21, 2014 11:16 AM UTC

Hi Matheiu,

 

Thanks for your response. We have added chart legend in code behind as shown in the below code snippet. Also, we have modified the sample based on your query. Please download it from the given below location.

 

Code Snippet [C#]:

private void Chart_OnLoaded(object sender, RoutedEventArgs e)

        {

            var legend = new ChartLegend

            {

                Header = "Series",

                DockPosition = ChartDock.Top,

 

            };

           chart.Legend = legend;

        }


Note:

Adding connector line for legends as per your previous requirement is not possible while adding series dynamically.


Regards,

Suresh S


Attachment: WPF_918e1f54.zip


MG Mathieu Guérin July 21, 2014 04:05 PM UTC

Hi,

In the sample code you modified, when the BuildPieCommand is called, the Chart is updated with the new data, but there is no call to Chart_OnLoaded. Is there an event called when there is a change apply to the data of the chart ? I want to add the code of the legend here, but the only event I found is SizeChanged. So I have to resize the windows to rebuild the legend of the chart.

Thanks,
Mathieu


SS Suresh S Syncfusion Team July 22, 2014 12:56 PM UTC

Hi Matheiu,


Thanks for your response.


‘Chart_OnLoaded’ will be called(invoked), when the chart getting loaded in view. There we have added the code for adding legends to the chart. So whenever the series is added dynamically to the chart or adding itemssource to the series, legends will be updated automatically. So you can use this event for adding legend in code behind.


Also if this is not your exact requirement, please provide us more information regarding your scenario which requires the event to be invoked or called after series or datasource has been updated. Otherwise if you are facing any refreshing problem in legends, when adding series or datasource dynamically, please revert us by modifying the sample based on your application with replication procedure.


This would be helpful for us to serve you. Please let us know, if you need any further assistance.


Regards,

Suresh S



MG Mathieu Guérin July 22, 2014 09:24 PM UTC

Hi,

I have modified the sample (see attach file). Now when you press the BuildChart button, the legend is updated like you say, but what I want is a legend that will be modified in the code behind each time the DataSource of the chart change (every time you press the BuildChart button). In the sample, if you try to resize the window the event SizeChanged will be invoked and the code behind will update the legend. This is the only way I find to have a legend that make sense (related to colors in the pie chart), but I have to resize the window to apply the change on the legend. 

Is there any event invoked when the DataSource of the chart  is modified, so i can update the legend in the same time ?

Thanks,
Mathieu

Attachment: WPF_b0ac0a2f.zip


SS Suresh S Syncfusion Team July 23, 2014 11:59 AM UTC

Hi Matheiu,


Thanks for your response.


We have used ‘series_Loaded’ event to achieve your requirement.  Whenever the series is added dynamically to the chart or the itemssource is changed ‘series_Loaded’ event is invoked. So you can use this event for adding legend in code behind as shown in the below codesnippet [C#].

Also, we have modified the sample based on your requirement. Please download it from the given below location.


Code Snippet[C#]:

void series_Loaded(object sender, RoutedEventArgs e)

        {

            Changed(sender);

        }


Regards,

Suresh S


Attachment: WPF_20381c3d.zip


MG Mathieu Guérin July 23, 2014 09:03 PM UTC

Hi,

I know this is a solution to add the code of legend in ViewModel part of our solution, but we don't want to have any references to Syncfusion in our ViewModel class. Right now, only the UI part our solution knows about Syncfusion and that's why I'm searching a way to update the legend of the pie chart in the code behind (MainWindow class in the sample). If you confirm that it is impossible, we will have to implement a structure for legend in our solution and link it to Syncfusion legend in the UI part of our solution.

Thanks,
Mathieu


SS Suresh S Syncfusion Team July 25, 2014 01:33 PM UTC

Hi Matheiu,

In the sample, we are already having Syncfusion reference in ViewModel for adding Series to the chart, so that we have given the solution to add legend in viewmodel.  In order to achieve your requirement (without using Syncfusion reference in ViewModel) we can create a separate helper class for generating Series and Legends. 

Hence we can use those helper methods in button click event. We have modified the sample, please download it from the given below location.

Note:
In the sample, we have included a helper class, which is used for generating legends alone.

Please let us know if you require further assistance on this.

Regards,
Suresh S

Attachment: WPF_95016dae.zip

Loader.
Live Chat Icon For mobile
Up arrow icon