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. (Last updated on : November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

PieSeries collection legend

Thread ID:

Created:

Updated:

Platform:

Replies:

117006 Jul 17,2014 08:51 PM UTC Jul 25,2014 01:33 PM UTC WPF 9
loading
Tags: Chart
Mathieu Guérin
Asked On July 17, 2014 08:51 PM UTC

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

Suresh S [Syncfusion]
Replied On 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

Mathieu Guérin
Replied On 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

Suresh S [Syncfusion]
Replied On 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

Mathieu Guérin
Replied On 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

Suresh S [Syncfusion]
Replied On 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


Mathieu Guérin
Replied On 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

Suresh S [Syncfusion]
Replied On 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

Mathieu Guérin
Replied On 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

Suresh S [Syncfusion]
Replied On 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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;