How to conditionally format axis values ​​in Silverlight Toolkit LineSeries

I am trying to conditionally format numbers that appear on the NumericAxis axis for LineSeries (from the Silverlight 4 toolbox). To be more specific, I want the numbers of> = 10000 and <= 0.0001 to appear in scientific notation, but I can't do this work.

I can override the NumericAxisLabel template as follows:

    <Style x:Key="NumericAxisLabelStyle" TargetType="chartingToolkit:NumericAxisLabel">
        <Setter Property="IsTabStop" Value="False"/>            
        <Setter Property="StringFormat" Value="{}{0:0.0E+00}" />                        
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="chartingToolkit:NumericAxisLabel">
                    <TextBlock Text="{TemplateBinding FormattedContent}"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

But this will apply the scientific notation format for ALL labels on the axis. I want the string formatting expression to include only when the condition that I mentioned above occurs.

I was able to accomplish this in the LineDataPoint tooltip template quite easily using binding with a custom value converter, for example:

 <ControlTemplate TargetType="chartingToolkit:LineDataPoint">
      <Grid x:Name="Root" Opacity="0">
           <ToolTipService.ToolTip>
                <StackPanel Margin="2,2,2,2">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="X:" />                                        
                        <ContentControl Content="{Binding objResultValueX, Converter={StaticResource ToCustomStringFormat}}"/>
                     </StackPanel>
                     <StackPanel Orientation="Horizontal">
                        <TextBlock Text="Y:" />
                        <ContentControl Content="{Binding dblResultValueY, Converter={StaticResource ToCustomStringFormat}}"/>
                      </StackPanel>
                 </StackPanel>
            </ToolTipService.ToolTip>
            ...
    </Grid>
 </ControlTemplate>

"FormattedContent" NumericAxisLabelStyle, LineDataPoint... , !

?

!

+3
2

DataContext TextBlock FormattedContent. Text :

<Style x:Key="NumericAxisLabelStyle" TargetType="chartingToolkit:NumericAxisLabel"> 
    <Setter Property="IsTabStop" Value="False"/> 
    <Setter Property="Template"> 
    <Setter.Value > 
        <ControlTemplate TargetType="chartingToolkit:NumericAxisLabel"> 
            <TextBlock DataContext="{TemplateBinding FormattedContent}" Text ="{Binding Converter={StaticResource ToCustomStringFormat}}"/> 
        </ControlTemplate> 
    </Setter.Value> 
    </Setter> 
</Style> 
+4

PrepareAxisLabel() DisplayAxis Toolkit.

( ):

protected virtual void PrepareAxisLabel(Control label, object dataContext)
    {
        label.DataContext = dataContext;
        label.SetStyle(AxisLabelStyle);
    }

, - :

public class MyLinearAxis : LinearAxis
{     
    protected override void PrepareAxisLabel(Control label, object dataContext)
    {   
        (label as AxisLabel).StringFormat = "{0:c}";   // currency format, for example
        dataContext = 10.0;                            // your own custom numeric value

        base.PrepareAxisLabel(label, dataContext);
    }
}

, .

+2

All Articles