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”
- Vincent Chan asked 3 years ago
- You must login to post comments
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
- Andrew Burnett-Thompson answered 3 years ago
- You must login to post comments
Please login first to submit.