SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components


I have a YAxis(NumericAxis) that indicates price, now I want to set different color to the label text(please see the uploaded image):

I’ve seen the ILabelProvider, but it seems to set string format.
How should I do?

  • You must to post comments
Best Answer

Hi there,

We haven’t tested it, but you may be able to achieve this by templating the Axis Labels.

Have a look at the XamlStyling example in our WPF Examples Suite.

      <Style x:Key="RotatedTickLabelStyle" TargetType="s:DefaultTickLabel">
         <Setter Property="Foreground" Value="Orange"></Setter>
         <Setter Property="FontSize" Value="16"/>
         <Setter Property="FontFamily" Value="Segoe UI"/>
         <Setter Property="LayoutTransform">
               <RotateTransform Angle="90"/>
       <!-- Optionally override ControlTemplate for the label -->
       <Setter Property="Template">
            <ControlTemplate TargetType="labelProviders:DefaultTickLabel">
               <ContentControl Content="{Binding}"
                  ContentTemplate="{TemplateBinding ContentTemplate}"
                  Foreground="{TemplateBinding Foreground}" IsTabStop="False" />

   <!--  Create the chart surface  -->
   <!-- where xmlns:s="" -->

   <!--  Create XAxis  -->
      <s:NumericAxis AxisTitle="Styled XAxis" TextFormatting="0.000" TickLabelStyle="{StaticResource RotatedTickLabelStyle}"/>

   <!--  Create YAxis  -->
      <s:NumericAxis AxisTitle="Primary YAxis" AxisAlignment="Left"/>
      <s:NumericAxis Id="SecondaryYAxisId" AxisTitle="Secondary YAxis" AxisAlignment="Right" />


The data context for a DefaultTickLabel is a DefaultTickLabelViewModel. This has property Text which is the string formatted value of the label. You could potentially bind to this to set the color, e.g.

<Style x:Key="YourTickLabelStyle" TargetType="s:DefaultTickLabel">
         <Setter Property="Foreground" Value="{Binding Text, Converter={StaticResource TextToColorConverter}"></Setter>

where TextToColorConverter accepts string label value and outputs a brush for the foreground.

Let me know if this helps. If you have anything to add to the above solution, please do in the answers!

Best regards,

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.