Pre loader

Custom AxisLabelTemplate and LabelProvider

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
1
0

Hi

I want to override the default AxisLabelTemplate for a DateTimeAxis beyond the normal circumstances.
Setting the AxisLabelTemplate to a StaticResource is easy enough, but all I have inside the Template is the CursorFormattedDataValue and I want to be able to send in something more then a simple string.

<ControlTemplate x:Key="RolloverModifierAxisLabelTemplateDefault">
    <Border Background="LightGray" 
            Opacity="0.80" 
            BorderThickness="0"
            CornerRadius="5"
            Padding="2"
            Visibility="{Binding IsXAxis, Converter={StaticResource BoolToVisibilityConverter}}">
        <TextBlock Text="{Binding CursorFormattedDataValue}" />
    </Border>
</ControlTemplate>

Extending the LabelProviderBase gives me the opportunity to override the FormatCursorLabel method, but it only returns a string and not an object and therefore I can not pass my own data structure to be used inside the AxisLabelTemplate.

How can we solve this issue? Is there a workaround, or is this something you need to implement?

  • You must to post comments
Best Answer
2
0

Hi Sander,

We’ve investigated the issue and done slight changes in order to allow creating a custom AxisInfo. You should derive your own type from AxisInfo, it will act as a ViewModel. Then override the HitTest method on an axis, create and initialize the instance of that type there and return it.

So if you try out the nightly build tomorrow, the following code should do the trick:

    public class CustomAxis : NumericAxis
{
    public override AxisInfo HitTest(IComparable dataValue)
    {
        var result = new CustomAxisInfo { MyProperty1 = "MyProperty1", MyProperty2 = "MyProperty2" };

        var axisInfo = base.HitTest(dataValue);

        // Copy all the values from axisInfo here

        return result;
    }
}

public class CustomAxisInfo : AxisInfo
{
    public string MyProperty1 { get; set; }

    public string MyProperty2 { get; set; }
}

And here is a label template sample:

            <ControlTemplate x:Key="AxisLabelTemplate" TargetType="s:TemplatableControl">
            <Grid>
                <Rectangle Width="100" Height="50" Fill="Yellow"/>
                <TextBlock Text="{Binding MyProperty1}"/>
            </Grid>
        </ControlTemplate>

Also we will consider if we can provide a bit more convenient way to do this in next versions, for instance via a custom LabelProvider.

Please let us know your thoughts about this solution,

Best regards,
Yuriy

  • Sander Struijk
    Looks good and thanks for fast response! I will try this out tomorrow then. I also agree that for future versions this could be streamlined a bit more with a LabelProvider or something.
  • 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