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.
Unfortunately, activation email could not send to your email. Please try again.

Duplicate legends with dynamic Column Series

Thread ID:

Created:

Updated:

Platform:

Replies:

131290 Jul 3,2017 07:56 AM Jul 6,2017 06:45 AM WPF 3
loading
Tags: SfChart
Michael
Asked On July 3, 2017 07:56 AM

Hi. Being new to WPF, I'm having a problem I would love to get some help with.

Task:
Creating a program that dynamically adjusts the number of column series based on user input. To do this, I reused much of the code here . I would like a graphic interface akin to something like this:

That is, two column series stacked closely to each other, where the column series stacked closely share a property (in this case: Jewelry, Electronics etc.). The two column series also have a differing property (In this case, as shown in the legend: 2011, 2010).

Problem:
The problem I'm having is that when I create the series using the code shown above, the property the two stacked columns differ on gets duplicated. So instead of only showing: *2010 *2011 in the legend, the legend (and the bar graphs) show up as: *2010 *2011 *2010 * 2011 ... as if they are different properties.
Is there any way to avoid these duplicates?

Thanks in advance,
Michael

Durgadevi Selvaraj [Syncfusion]
Replied On July 4, 2017 09:05 AM

Hi Michael,

Thanks for contacting Syncfusion Support.

We have analyzed your reported problem and unable to reproduce the problem at our end. We have prepared a demo sample based on your provided information and it can be downloaded from below link,

Sample:  Sample_WPF


If you are still able to reproduce the reported problem, please revert us by modifying the provided sample. It would be helpful for us to provide you a solution sooner.

Regards,
Durgadevi S

Michael
Replied On July 5, 2017 02:54 AM

Hi. Thank you for your answer. It seems I have been a bit unclear in my explanation, my apologies. Comments are added in the file to clarify, and the code is modified to give an example of what I tried first.



Attachment: SyncfusionOnsdag2_1fc0fb20.7z

Durgadevi Selvaraj [Syncfusion]
Replied On July 6, 2017 06:45 AM

Hi Michael, 

Thanks for your update. 

We have analyzed the given sample and its legend items were generated based on number of series(based on items value) added in chart. However, you can avoid legend for same series label by using VisibilityOnLegend property as collapsed to the corresponding series as shown in the below code, 

   
private void GenerateSeries() 
        { 
            if (Source == null || (SeriesTemplateSelector == null && SeriesTemplate == null)) return; 
            var commonItemsSource = (Source as IEnumerable).GetEnumerator(); 
 
            List<string> LegendCollection = new List<string>(); 
 
            while (commonItemsSource.MoveNext()) 
            { 
                ChartSeries series = null; 
 
                //The conditions checked for setting the SeriesTemplate or SeriesTemplateSelector. 
                if (SeriesTemplate != null) 
                { 
                    series = SeriesTemplate.LoadContent() as ChartSeries; 
                } 
 
                if (LegendCollection.Contains((commonItemsSource.Current as AnnualPriceData).DataType)) 
                    series.VisibilityOnLegend = Visibility.Collapsed; 
 
                else 
                    LegendCollection.Add((commonItemsSource.Current as AnnualPriceData).DataType); 
 
 
                series.DataContext = commonItemsSource.Current; 
                Series.Add(series); 
            } 
        } 



Please find the output screenshot, 
  
We have modified the sample based on your requirement and please downloaded from the below link, 

Please let us know if you have any concerns. 

Regards,  
Durgadevi S 



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.

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.

;