Pre loader

How can I set axis label's color by its value?

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


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.