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?
- Yuhang Ji asked 9 years ago
- You must login to post comments
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
- Andrew Burnett-Thompson answered 9 years ago
-
It works, thank you!
- You must login to post comments
Please login first to submit.