Search code examples
c#wpfxamlsyncfusion

Syncfusion Chart Trackball Style


In my Syncfusion WPF application, ChartTrackBallBehavior shows I can add some style to ChartTrackBallStyle. The Style doesn't have any documentation. I can't figure out what I can set in the chart.

Has anyone used this control and styled the Label to match their corporate look? I need to change the look of the label that shows up in the Axis. I have found the following Setters for the Style so far that changes the appearance of the ball but not the label.

    <sfc:SfChart.Behaviors>
      <sfc:ChartTrackBallBehavior ShowLine="True" LabelHorizontalAlignment="Center" LabelVerticalAlignment="Near" >
        <sfc:ChartTrackBallBehavior.ChartTrackBallStyle>
          <Style TargetType="sfc:ChartTrackBallControl" >
            <Setter Property="Control.Visibility" Value="Visible" />
            <Setter Property="Control.Background" Value="AliceBlue" />
            <Setter Property="Control.FontSize" Value="6" />
          </Style>
        </sfc:ChartTrackBallBehavior.ChartTrackBallStyle>
      </sfc:ChartTrackBallBehavior>
    </sfc:SfChart.Behaviors>

Solution

  • Use the template "TrackBallLabelTemplate", which is set in the definition of the Primary Axis, not in SfChart.Behaviors. Following is the code that worked for us:

    <sfc:SfChart.PrimaryAxis>
        <sfc:DateTimeCategoryAxis Header="SomeText" PlotOffset="10"
            LabelFormat="yyyy/MM/dd hh:MM:ss" LabelTemplate="{StaticResource labelTemplate}" LabelsIntersectAction="Hide"
            ShowTrackBallInfo="True" TrackBallLabelTemplate="{StaticResource trackTemplateX}"/>
    </sfc:SfChart.PrimaryAxis>
    

    My template is defined as follows:

    </Grid.Resources>
        <DataTemplate x:Key="trackTemplateX">
            <Grid Background="Black">
                <TextBlock Text="{Binding ValueX}" Foreground="White"  Margin="5" FontSize="14"/>
            </Grid>
        </DataTemplate>
    </Grid.Resources>