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
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.