1

我有按层次分组的数据系列。我需要图表图例来反映这种结构(见截图)

[编辑:删除图像以防止潜在的客户端 IP 问题]

关闭一个组应该自然地关闭它的所有子轴。是否可以使用内置的轴图例来做到这一点?如果是这样,您能否提供一些关于如何操作的指示?(因为目前我没有最微弱的想法)如果没有,最好的解决方法是什么?禁用图例,实现自定义控件,然后动态更改SeriesSource绑定属性?

4

1 回答 1

0

SciChartLegend控件只是一个ItemsControl,它通过LegendModifier.LegendData属性绑定到 SeriesInfo 的 ObservableCollection 来显示数据。

用英语来说,这意味着,如果你能弄清楚如何在 ItemsControl 中显示分层组,那么你可以在 SciChart Legend 控件中做同样的事情。

您可能需要做的是创建自己的继承自 ItemsControl 的类以绑定到LegendModifier.LegendData并根据需要对项目进行分组。或者,使用附加的行为或转换器对项目进行分组。

接下来,您可以使用LegendModifier 文档中的技术来使用您自己的类或 ItemsControl(而不是 SciChartLegend)。

或者 - 将 LegendModifier.LegendData 绑定到 SciChartLegend

您也可以将 LegendModifier.LegendData 绑定到 SciChartLegend 并放置在应用程序的任何位置。您还可以将 LegendModifier.LegendData 绑定到 ItemsControl.ItemsSource 并根据需要对其进行模板化。

<!-- 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>

虽然这样的东西不是一个完整的解决方案,但它确实向您展示了如何使用 SciChart Legend API 来替换 ItemsControl 和模板图例项。希望您能够从那里对项目进行分组并以分层方式显示数据。

于 2016-05-11T16:18:36.560 回答