I am trying to customise the appearance of the RolloverModifier
tooltips that appear on a SciChart Line Chart, using a DataTemplate
(combined with the TooltipTemplate
attribute of the RolloverModifier
, but can't figure it out.
Here is my DataTemplate
which I've made as simple as possible just to get it working.
<DataTemplate x:Key="ChartToolTipTemplate" DataType="{x:Type s:SeriesInfo}">
<TextBlock Text="Hello" />
</DataTemplate>
What I've tried so far:
First:
<s:RolloverModifier x:Name="RolloverModifier" TooltipTemplate="{StaticResource ChartToolTipTemplate}">
but I get the error:
Unable to cast object of type 'SciChart.Charting.ChartModifiers.RolloverModifier' to type 'SciChart.Charting.Visuals.RenderableSeries.BaseRenderableSeries'.
From research online, it appears what I should be doing is:
<s:SciChartSurface.RenderableSeries>
<s:FastLineRenderableSeries s:TooltipModifier.TooltipTemplate="{StaticResource TooltipTemplate}"
s:TooltipModifier.IncludeSeries="True"
s:SeriesValueModifier.IncludeSeries="False"/>
</s:SciChartSurface.RenderableSeries>
However, this is no good to me as my RenderableSeries
is bound to an ObservableCollection<IRenderableSeries>
in my ViewModel.
<s:SciChartSurface
x:Name="SciChart"
Grid.Column="0"
Annotations="{Binding Annotations}"
GridLinesPanelStyle="{StaticResource GridLinesPanelStyle}"
RenderableSeries="{Binding ChartSeries}"
Style="{StaticResource SurfaceStyle}">
A suggestion on a similar question to this was to use ObservableCollection<IRenderableSeriesViewModel>
and set the style in the ViewModel as per this page in the documentation: Bind Tooltip Templates or Attached Properties in MVVM, but I couldn't figure out how to convert my IRenderableSeries
to a LineRenderableSeriesViewModel
and ended up with a blank chart.
Another suggestion in this similar question (SciChart: Custom RolloverModifierLabel for multiple DataSeries bound from code was to use an Implicit Style, so I added
<s:SciChartSurface.Resources>
<Style TargetType="s:BaseRenderableSeries">
<Setter Property="s:RolloverModifier.TooltipTemplate" Value="{StaticResource ChartToolTipTemplate}" />
<Setter Property="s:RolloverModifier.IncludeSeries" Value="True" />
<Setter Property="s:RolloverModifier.IsEnabled" Value="True" />
<Setter Property="FontSize" Value="30" />
</Style>
</s:SciChartSurface.Resources>
And kept the
<s:SciChartSurface.ChartModifier>
<s:ModifierGroup>
<s:LegendModifier
x:Name="LegendModifier"
Margin="10"
HorizontalAlignment="Right"
LegendTemplate="{StaticResource LegendTemplate}"
Orientation="Horizontal"
ShowLegend="{Binding ShowLegend}"
ShowVisibilityCheckboxes="False" />
<s:RolloverModifier x:Name="RolloverModifier" />
<s:SeriesSelectionModifier>
<s:SeriesSelectionModifier.SelectedSeriesStyle>
<Style TargetType="s:BaseRenderableSeries">
<Setter Property="Stroke" Value="DeepPink" />
<Setter Property="StrokeThickness" Value="3" />
</Style>
</s:SeriesSelectionModifier.SelectedSeriesStyle>
</s:SeriesSelectionModifier>
</s:ModifierGroup>
</s:SciChartSurface.ChartModifier>
But the style has no effect at all on the tooltips (even the FontSize
bit which I just put in to check if it was even working). Removing that line removes the tooltips completely.