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

Duplicate legends with dynamic Column Series

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

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).

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,

3 Replies

DS Durgadevi Selvaraj Syncfusion Team July 4, 2017 01:05 PM UTC

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.

Durgadevi S

MI Michael July 5, 2017 06:54 AM UTC

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

DS Durgadevi Selvaraj Syncfusion Team July 6, 2017 10:45 AM UTC

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; 
                    LegendCollection.Add((commonItemsSource.Current as AnnualPriceData).DataType); 
                series.DataContext = commonItemsSource.Current; 

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. 

Durgadevi S 

Live Chat Icon For mobile
Up arrow icon