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

Answered
0
0

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?

Images
  • You must to post comments
Best Answer
0
0

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.

<Grid>
   <Grid.Resources>
      <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">
            <Setter.Value>
               <RotateTransform Angle="90"/>
            </Setter.Value>
         </Setter>
       <!-- Optionally override ControlTemplate for the label -->
       <Setter Property="Template">
         <Setter.Value>
            <ControlTemplate TargetType="labelProviders:DefaultTickLabel">
               <ContentControl Content="{Binding}"
                  ContentTemplate="{TemplateBinding ContentTemplate}"
                  Foreground="{TemplateBinding Foreground}" IsTabStop="False" />
            </ControlTemplate>
         </Setter.Value>
       </Setter>
      </Style>
   </Grid.Resources>

   <!--  Create the chart surface  -->
   <!-- where xmlns:s="http://schemas.abtsoftware.co.uk/scichart" -->
   <s:SciChartSurface>

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

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

   </s:SciChartSurface>
</Grid>

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,
Andrew

  • You must to post comments
Showing 1 result
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