Pre loader

Getting an exception when trying to set tooltip template

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

0
0

Getting an exception when trying to add tooltip template MVVM style to a blox plot. The chart also contains a scatter plot which should not be styled. That works fine, hoverwer, when I move the mouse over a box in the box plot, the exception is thrown.

I want to keep the styling, I just want to write something different than the default text.

The template:

  <DataTemplate DataType="scalarPlot:ToolTipData" x:Key="BoxSeriesTooltipTemplate">
    <TextBlock>
      <Run Text="Max:      " />
      <Run Text="{Binding Maximum}" />
      <LineBreak />
      <Run Text="P90:       " />
      <Run Text="{Binding P90}" />
      <LineBreak />
      <Run Text="Median: " />
      <Run Text="{Binding Median}" />
      <LineBreak />
      <Run Text="P10:       " />
      <Run Text="{Binding P10}" />
      <LineBreak />
      <Run Text="Min:       " />
      <Run Text="{Binding Minimum}" />
      <LineBreak />
    </TextBlock>
  </DataTemplate>

The binding:

      <Style TargetType="s:BaseRenderableSeries" x:Key="BoxSeriesStyle">
        <Setter Property="s:TooltipModifier.TooltipTemplate" Value="{StaticResource BoxSeriesTooltipTemplate}"/>
        <Setter Property="s:TooltipModifier.IncludeSeries" Value="True"/>
      </Style>

The modifier:

<s:SciChartSurface.ChartModifier>
      <s:ModifierGroup>
        <s:TooltipModifier IsEnabled="True" ShowTooltipOn="Always" ReceiveHandledEvents="True" TooltipLabelDataContextSelector="{Binding ToolTipDataContext}"/>
      </s:ModifierGroup>
    </s:SciChartSurface.ChartModifier>

The view model:

    private static IRenderableSeriesViewModel CreateBoxPlotViewModel(BoxPlotDataSeries<int, float> boxPlotDataSeries)
    {
        return new BoxPlotRenderableSeriesViewModel
        {
            DataSeries = boxPlotDataSeries,
            Stroke = Colors.SteelBlue,
            Fill = new LinearGradientBrush(Colors.White, Colors.LightSteelBlue, new System.Windows.Point(0, 0), new System.Windows.Point(0.5, 1)),
            StyleKey = "BoxSeriesStyle"
        };
    }

The data context selector:

    public Func<SeriesInfo, object> ToolTipDataContext
    {
        get
        {
            return seriesInfo =>
                   {
                       return seriesInfo switch
                       {
                           BoxPlotSeriesInfo boxInfo =>
                               new ToolTipData
                               {
                                   Fill = seriesInfo.Fill,
                                   Stroke = seriesInfo.Stroke,
                                   Maximum = (float) boxInfo.MaximumValue,
                                   P90 = (float) boxInfo.UpperQuartileValue,
                                   Median = (float) boxInfo.MedianValue,
                                   P10 = (float) boxInfo.LowerQuartileValue,
                                   Minimum = (float) boxInfo.MinimumValue
                               },
                           _ => seriesInfo
                       };
                   };
        }
    }
Version
6.3.0.13476
Images
  • You must to post comments
0
0

I got it working in another plot, with only 1 bar chart renderableseriesviewmodel.

  <Style x:Key="TooltipStyle" TargetType="s:TooltipControl">
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="s:TooltipControl">
          <Border Style="{StaticResource TransparentTooltipBorderStyle}">
            <ContentPresenter Content="{TemplateBinding DataContext}"
                              ContentTemplate="{TemplateBinding ContentTemplate}" />
          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <DataTemplate x:Key="TooltipTemplate" DataType="s:XySeriesInfo">
    <StackPanel Orientation="Vertical" Margin="0">
      <TextBlock Style="{StaticResource TransparentTooltipTextBlockStyle}">
        <Run Text="{Binding FormattedXValue, Mode=OneWay}"/>
      </TextBlock>
      <TextBlock Style="{StaticResource TransparentTooltipTextBlockStyle}">
        <Run Text="{Binding YValue, StringFormat='{}Score: {0:g}'}"/>
      </TextBlock>
    </StackPanel>
  </DataTemplate>

  <Style TargetType="s:BaseRenderableSeries" x:Key="ColumnTooltipStyle">
    <Setter Property="s:TooltipModifier.TooltipContainerStyle" Value="{StaticResource TooltipStyle}"/>
    <Setter Property="s:TooltipModifier.TooltipTemplate" Value="{StaticResource TooltipTemplate}"/>
    <Setter Property="s:TooltipModifier.IncludeSeries" Value="True"/>
  </Style>

And tooltip modifier:

<s:SciChartSurface.ChartModifier>
  <s:ModifierGroup>
    <s:TooltipModifier IsEnabled="True" />
    <s:LegendModifier IsEnabled="True" />
    <chartModifiers:ClickSelectionModifier ReceiveHandledEvents="True"
                                           ClickedSeriesTuple="{Binding SelectedSeriesTuple}"
                                           IgnoreBlankClicks="True"/>
  </s:ModifierGroup>
</s:SciChartSurface.ChartModifier>

So I’m not sure why it crashes in that other plot which has a CrossPlot (which should have default styling) and a BoxPlot (which should have custom styling)

  • You must to post comments
0
0

Fixed it by setting x:Key before DataType

Before:

<DataTemplate DataType="scalarPlot:ToolTipData" x:Key="BoxSeriesTooltipTemplate">

After:

<DataTemplate x:Key="BoxSeriesTooltipTemplate" DataType="scalarPlot:ToolTipData">
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies