I have a chart that is graphing multiple DataSeries. I’m trying to create a sort of “legend” on my chart which essentially works like this
example except no rolling over is necessary and it always just displays the most recent value. Any suggestions? Is there a good way to get the most recent value out of a DataSeries to bind to?
Thanks,
Alex
- aitkin asked 12 years ago
- You must login to post comments
Hi Aitkin,
You should try using the LegendModifier, which is demonstrated here:
Legend Modifier Demo
It uses a similar mechanism to bind to SeriesInfo objects as the RolloverModifier. The LegendModifier sets SeriesInfo.XValue equal to the latest value in the data-series. You’ll have to modify the control template of the LegendControl to display the info. So, the Xaml would look something like this (taken from MultipleLinesView.xaml in the examples)
<Grid> <SciChart:SciChartSurface x:Name="sciChart" SciChart:ThemeManager.Theme="ExpressionLight"> <!-- Declare RenderableSeries ... --> <!-- Declare Axes ... --> <!-- Declare ChartModifiers --> <SciChart:SciChartSurface.ChartModifier> <SciChart:ModifierGroup> <SciChart:LegendModifier x:Name="legendModifier"/> </SciChart:ModifierGroup> </SciChart:SciChartSurface.ChartModifier> </SciChart:SciChartSurface> <!-- Declare SciChartLegend and override template --> <SciChart:SciChartLegend Margin="23,23" LegendData="{Binding LegendData, ElementName=legendModifier}"> <SciChart:SciChartLegend.Template> <ControlTemplate TargetType="SciChart:SciChartLegend"> <ControlTemplate.Resources> <Common:IComparableConverter x:Key="ComparableConverter"/> <Common:ColorToBrushConverter x:Key="ColorToBrushConverter"/> </ControlTemplate.Resources> <Border x:Name="PART_Border" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}"> <ItemsControl BorderThickness="0" DataContext="{TemplateBinding LegendData}" ItemsSource="{Binding SeriesInfo}"> <ItemsControl.ItemTemplate> <DataTemplate> <Grid HorizontalAlignment="Left"> <Grid.ColumnDefinitions> <ColumnDefinition/> <ColumnDefinition/> <ColumnDefinition/> <ColumnDefinition/> </Grid.ColumnDefinitions> <Ellipse Fill="{Binding SeriesColor, Converter={StaticResource ColorToBrushConverter}}" Width="9" Height="9" Margin="3"/> <TextBlock Grid.Column="1" Text="{Binding SeriesName}" Width="90" Style="{StaticResource tbStyle}"/> <!-- When binding to XValue, YValue of type IComparable, StringFormat is mandatory due to a --> <!-- XAML bug that cannot convert IComparable to text, even though underlying type is double --> <StackPanel Orientation="Horizontal" Grid.Column="2"> <TextBlock Text="X: " Style="{StaticResource tbStyle}"/> <TextBlock Text="{Binding XValue, StringFormat=\{0:0.00\}}" Style="{StaticResource tbStyle}"/> </StackPanel> <StackPanel Orientation="Horizontal" Grid.Column="3"> <TextBlock Text="Y: " Margin="3" Style="{StaticResource tbStyle}"/> <TextBlock Text="{Binding YValue, StringFormat=\{0:0.00\}}" Style="{StaticResource tbStyle}"/> </StackPanel> </Grid> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </Border> </ControlTemplate> </SciChart:SciChartLegend.Template> </SciChart:SciChartLegend> </Grid>
The controltemplate basically modifies the existing LegendControl to display the latest YValue after the series name. The StringFormat is needed to convert an IComparable value to double (unfortunately this implicit conversion is lacking in the .NET framework).
This should result in the following (attached image)
Best regards,
Andrew
- Andrew Burnett-Thompson answered 12 years ago
-
Hi, I'm trying to implement a very similar idea for my own project, but I can't seem to find where Common is defined for the control template. Is it possible to continue using this code in v1.71, or would it need significant modification?
-
Or, since I'm not just looking for the last value added, would it be better to modify Rollover to simply update some text boxes that are located inside the legend?
-
Hi there, I'm not sure if I understood you correctly, but it seems to me that you are looking for this behavior, aren't you? If no, could you please clarify your request, maybe with some screenshots? Regarding IComparableConverter, ColorToBrushConverter classes, you can find them in default SciChart namespace, Abt.Controls.SciChart, and also in Abt.Controls.SciChart.Example.Common namespace(in examples suite). Hope this helps! Best regards, Yuriy
-
The look of the functionality is what I'm looking for, yes. But I would prefer it exist within a legend, if possible. That way I can still remove different series from the graph as needed. So, basically, just a third column in the legend that displays the y value at the current x position.
-
Also, I've managed to find the BrushConverter within namespace:Abt.Controls.SciChart.Example.Common, but IComparable doesn't seem to be in there or in Abt.Controls.SciChart. Any other suggestions?
-
I'm using the legendmodifier to display the latest y values sort of like the rollermodifier but constantly updating. My issue is that when I have small visible range say 5 miutes it works just fine, but when I have dense visible range say 1 hour it updates the legend values less frequently (it skips 3 to 4 values). Can you advice on how to fix this?
- You must login to post comments
Please login first to submit.