1

I have data seris that are grouped hierarchically. I need the chart legend to reflect this structure (see screenshot)

[edit: image removed to prevent potential client IP issues]

Switching off a group should naturally switch off all its child axes. Is it possible to do this with the built in axis legend? If so, could you provide some pointers as to how? (because presently I don't have the faintest idea) If not, what would be the best workaround? Disable the legend, implement a custom control, and then dynamically change the SeriesSource bound property?

Shaggydog
  • 3,456
  • 7
  • 33
  • 50

1 Answers1

0

The SciChartLegend control is simply an ItemsControl which displays data by binding to an ObservableCollection of SeriesInfo via the LegendModifier.LegendData property.

In English, what that means is, if you can figure out how to display a hierarchical group in an ItemsControl then you can do the same in the SciChart Legend control.

What you may need to do is to create your own class inheriting from ItemsControl to bind to LegendModifier.LegendData and group the items as you wish. Or, use an attached behaviour or converter to group items.

Next, you can use your own class or ItemsControl (instead of SciChartLegend) using the technique in the LegendModifier Documentation.

Alternatively – Binding LegendModifier.LegendData to SciChartLegend

You can alternatively bind LegendModifier.LegendData to a SciChartLegend and place anywhere in your application. You can also bind to an LegendModifier.LegendData to an ItemsControl.ItemsSource and template it as you wish.

<!-- Somewhere else in your application, you can declare n ItemsControl -->
<!-- and bind to LegendModifier.LegendData -->
<ItemsControl
   Margin="23,23"
   ScrollViewer.HorizontalScrollBarVisibility="Auto"
   ScrollViewer.VerticalScrollBarVisibility="Auto"
   <!-- Here you may need a converter or attached behaviour to group the SeriesInfo as you wish -->
   ItemsSource="{Binding LegendData.SeriesInfo, ElementName=legendModifier, Mode=OneWay}">
    <ItemsControl.ItemTemplate>
        <!-- Here you may need a Hierachical Data Template to display hierachical data -->
        <DataTemplate x:Key="SciChartLegendItemTemplate" DataType="chartData:SeriesInfo">
            <StackPanel Orientation="Horizontal">
                <CheckBox Margin="5,0,0,0"
                          HorizontalAlignment="Left"
                          VerticalAlignment="Center"
                          IsChecked="{Binding RenderableSeries.IsVisible, Mode=TwoWay}"
                          Visibility="Visible" />

                <r:PointMarker Width="40"
                               Height="10"
                               Margin="5,0,0,0"
                               HorizontalAlignment="Center"
                               VerticalAlignment="Center"
                               HorizontalContentAlignment="Stretch"
                               VerticalContentAlignment="Stretch"
                               DataContext="{Binding RenderableSeries}"
                               DeferredContent="{Binding LegendMarkerTemplate}"
                               Visibility="{Binding ShowSeriesMarkers, RelativeSource={RelativeSource AncestorType=visuals:SciChartLegend}, Converter={StaticResource BooleanToVisibilityConverter}}" />

                <TextBlock Margin="5,0,5,0"
                           HorizontalAlignment="Left"
                           Text="{Binding SeriesName}" />
            </StackPanel>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

While something like this is not a complete solution, it does show you how to use the SciChart Legend API to substitute an ItemsControl and template legend items. From that hopefully you should be able to group the items and display data in a hierachical way.

Dr. Andrew Burnett-Thompson
  • 20,980
  • 8
  • 88
  • 178
  • Hi, I've tried to follow your advice, but truth be told I didn't quite understand it. To be honest, I'm not even sure whether you've suggested 2 or 3 alternative solutions. I've tried creating a custom LegendModifier.LegendTemplate, that would display my custom structure. I made a template for a group, that includes an ItemsControl for the group's content. This ItemsControl would have another custom template. The result was no legend shown whatsoever. Unfortunately with my limited knowledge of WPF, there are too many uknowns for me to have an idea where I went wrong. – Shaggydog May 16 '16 at 14:12
  • I'd like to focus on this part of your answer: "What you may need to do is to create your own class inheriting from ItemsControl to bind to LegendModifier.LegendData and group the items as you wish." Does this mean I can leave the legend modifier as is, and just create a custom ItemsControl implementation, that would handle the grouping separately? Then my question is, how do I make the SciChart use this custom control, instead of a SciChart legend? – Shaggydog May 16 '16 at 14:15
  • Yes that's exactly correct. SciChartLegend is simply an ItemsControl that has been templated to make it work out of the box. The LegendModifier documentation here http://www.scichart.com/documentation/v4.x/LegendModifier.html has a section "Alternatively – Binding LegendModifier.LegendData to SciChartLegend". LegendModifier.LegendData is simply a collection of SeriesInfo. SeriesInfo is discussed in detail at http://www.scichart.com/documentation/v4.x/SeriesInfo%20%E2%80%93%20the%20ViewModels%20for%20Tooltips%20and%20Legends.html I'd suggest opening a new question if you want more detail! – Dr. Andrew Burnett-Thompson May 16 '16 at 15:19