Search code examples
silverlightsilverlight-toolkit

Silverlight Toolkit Chart Y-axis label styling


I am having trouble figuring out how to style the Y-axis labels on a chart (Silverlight Toolkit). Does anyone have a simple example of how to do this? All the examples out in the wild seem to be pre 2010, when the chart API was different.

Thanks,

Mike


Solution

  • Here's some sample code that changes the Y-axis to display the labels in hours instead of minutes and changes the font size to 8 (SecondsToHours converter code not included). You can do lots of other kinds of formatting in the Style. This should help you get started.

    <Style x:Key="HoursLabel" TargetType="{x:Type charting:AxisLabel}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type charting:AxisLabel}">
                    <TextBlock Text="{Binding Converter={StaticResource SecondsToHoursConverter}}" FontSize="8" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <charting:Chart.Axes>
        <charting:LinearAxis Orientation="Y" Interval="1" Minimum="0" Maximum="24" AxisLabelStyle="{StaticResource HoursLabel}" />
    </charting:Chart.Axes>