Hi,
I have a chart showing data sets composed of multiple renderable series. Each data set is displayed using one FastLineRenderableSeries and three XyScatterRenderableSeries. All four series show in the legend for each data set, but I would only like to show the FastLineRenderableSeries in the legend for each data set. How can I do this?
I’ve seen the legendModifier.GetLegendDataFor property, but that can only be set to show options from this enum
public enum SourceMode
{
AllSeries = 0,
AllVisibleSeries = 1,
SelectedSeries = 2,
UnselectedSeries = 3,
}
which aren’t what I need. Some kind of flag on the renderable series saying whether they should be shown in the legend, or some way to specify the items source for the legend would be good.
Thanks!
- Robert Evans asked 9 years ago
- You must login to post comments
Sorted it. I declare the SciChartLegend separately from the LegendModifier in the xaml and attach a behaviour to the SciChartLegend. The behaviour declares a dependency property and binds the LegendModifier.LegendData property to it. The behavour subscribes to the LegendModifier.LegendData.SeriesInfo.CollectionChanged event in order to maintain its own ObservableCollection (which is a copy of LegendModifier.LegendData.SeriesInfo with the unwanted SeriesInfo objects filtered out), which it uses to create a new ChartDataObject which is finally assigned to the behaviour’s AssociatedObject.LegendData property.
- Robert Evans answered 9 years ago
- last edited 9 years ago
-
That's a great solution! Also see our article on creating a custom legend data source http://support.scichart.com/index.php?/Knowledgebase/Article/View/17238/32/custom-chartmodifiers---part-4---custom-legend-data-sources as well as this article on SeriesInfo http://support.scichart.com/index.php?/Knowledgebase/Article/View/17249/42/seriesinfo---the-series-viewmodel-for-legends-tooltips-rollovers as it gives great insight into what this API is doing
- You must login to post comments
I wanted to do the same thing and thought I would share my solution as its pretty simple and is consistent with how you exclude series from the RolloverModifier:
I created a derived legend modifier with a boolean attached property “IncludeSeries”. This has a default value of true. This derived class overrides the GetSeriesInfo() method and filters the renderable series by the value of the “IncludeSeries” attached property (code below):
public class FilteringLegendModifier : LegendModifier
{
public static bool GetIncludeSeries(DependencyObject obj)
{
return (bool)obj.GetValue(IncludeSeriesProperty);
}
public static void SetIncludeSeries(DependencyObject obj, bool value)
{
obj.SetValue(IncludeSeriesProperty, value);
}
// Using a DependencyProperty as the backing store for IncludeSeries. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IncludeSeriesProperty = DependencyProperty.RegisterAttached("IncludeSeries", typeof(bool), typeof(FilteringLegendModifier), new PropertyMetadata(true));
protected override ObservableCollection<SeriesInfo> GetSeriesInfo(IEnumerable<IRenderableSeries> allSeries)
{
var filteredSeries = allSeries.Where(s => s is UIElement)
.Where(s => (bool)((UIElement)s).GetValue(IncludeSeriesProperty));
return base.GetSeriesInfo(filteredSeries);
}
}
Use this modifier in your xaml exactly the same as you use the standard LegendModifier. If you want a series to be excluded from the legend add the IncludeSeries attached property set to false (since True is the default value you do not need the property on series you want to show):
...
<s:SciChartSurface.RenderableSeries>
<s:XyScatterRenderableSeries x:Name="seriesToShowInLegend"/>
<s:XyScatterRenderableSeries x:Name="seriesToExcluedFromInLegend" modifiers:FilteringLegendModifier.IncludeSeries="False" />
</s:SciChartSurface.RenderableSeries>
...
Hope that might help someone!
- Bill Dines answered 7 years ago
- last edited 7 years ago
-
I see there’s a use-case for adding LegendModifier.IncludeSeries attached property … I will add it to the TODO list
- You must login to post comments
Please login first to submit.