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

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy. We also have a tag=SciChart on Stackoverflow.com where you can earn rep for your questions!

Please note: SciChart team will only answer questions from customers with active support subscriptions. Expired support questions will be ignored. If your support status shows incorrectly, contact us and we will be glad to help.

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.