Pre loader

Discontinuous DateTimeAxis Text Formatting

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

Hi, I found that the text formatting of discontinous DateTimeAxis is not working in WPF
I put the following format in DateTimeAxis and it displays correctly but not in discontinous DateTimeAxis
TextFormatting=”dd-MM”
SubDayTextFormatting=”HH:mm”

Version
6
  • You must to post comments
Best Answer
0
0

Hi Vincent

The DiscontinuousDateTimeAxis and the CategoryDateTimeAxis both use a slightly different way to format labels. They both use the Label Provider feature in SciChart WPF.

Internally in the DiscontinuousDateTimeAxis constructor we have this code:

    public DiscontinuousDateTimeAxis()
    {
        this.LabelProvider = new DiscontinuousDateTimeLabelProvider();
    }

Where DiscontinuousDateTimeLabelProvider is defined as this

/// <summary>
/// The DiscontinuousDateTimeLabelProvider is a pass-through which uses the <see cref="AxisCore.TextFormatting"/> and <see cref="AxisCore.CursorTextFormatting"/> properties
/// to format axis and cursor label texts. It also uses the <see cref="DateTimeAxis.SubDayTextFormatting"/> property to alter text-formatting when the date-range 
/// switches to intra-day
/// </summary>
public class DiscontinuousDateTimeLabelProvider : LabelProviderBase
{
    /// <summary>
    /// Formats a label for the cursor, from the specified data-value passed in
    /// </summary>
    /// <param name="dataValue">The data-value to format</param>
    /// <returns>
    /// The formatted cursor label string
    /// </returns>
    public override string FormatCursorLabel(IComparable dataValue)
    {
        var dateTime = dataValue.ToDateTime();

        var formattedText = ParentAxis.CursorTextFormatting.IsNullOrEmpty()
            ? FormatLabel(dataValue)
            : dateTime.ToString(ParentAxis.CursorTextFormatting);

        return formattedText;
    }

    /// <summary>
    /// Performs a type check of <see cref="ProviderBase.ParentAxis"/>. 
    /// Throws <see cref="InvalidOperationException"/> if the type is not derived from <see cref="DiscontinuousDateTimeAxis"/>.
    /// </summary>
    protected void CheckAxisType()
    {
        if (!(ParentAxis is DiscontinuousDateTimeAxis))
        {
            throw new InvalidOperationException(String.Format("The {0} is only valid on instances of {1}", GetType().Name, typeof(DiscontinuousDateTimeAxis).Name));
        }
    }

    /// <summary>
    /// Formats a label for the axis from the specified data-value passed in
    /// </summary>
    /// <param name="dataValue">The data-value to format</param>
    /// <returns>
    /// The formatted label string
    /// </returns>
    /// <exception cref="System.InvalidOperationException">The DiscontinuousDateTimeLabelProvider is only valid on instances of DiscontinuousDateTimeAxis</exception>
    public override string FormatLabel(IComparable dataValue)
    {
        CheckAxisType();

        var dtAxis = ParentAxis as DiscontinuousDateTimeAxis;

        var dt = dataValue.ToDateTime();
        var calendar = dtAxis.Calendar;
        var tickRange = dtAxis.VisibleRange;

        return DiscontinuousTickHelper.GetLabelFormat(calendar, tickRange, dt);
    }
}

So if you want to make changes to the label formatting this is the place to do it. Create a class which inherits LabelProviderBase and apply to the axis.

More info how to do this in our docs at Label Provider API

Best regards,
Andrew

  • 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