Pre loader

Autodate format

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

0
1

I want to display auto format date on xAxis (DateAxis) while zooming but I cannot find SubDayTextFormatting function.Is there any way to display minutes and seconds after init months ?there is no DateTime Axis on Android like on iOS ..Should I change to CategoryDate Axis?

Thanks in advance

Version
1.0.0.1063
  • You must to post comments
1
0

Update: Turns out the API is slightly different to the above. The Android team informs me:

Default SciChart label providers don’t use formatLabel/formatCursor because of performance reasons – formatting of labels is one of the slowest operation because we use standard Java Format implementations support standart format strings and they are really slow. If you want to implement custom label formatter which will use formatLabel then I would suggest to start from class similar to this one:

class CustomLabelProvider extends LabelProviderBase {

    // list with all formatted tick labels - we format them once and store them for further reusage
    private final List<String> formattedTickLabels = new ArrayList<>();

    @Override
    public void update() {
        super.update();

        // clear old labels
        formattedTickLabels.clear();

        // iterate over ticks and format them
        final AxisTicks ticks = axis.getTickProvider().getTicks();
        final DoubleValues majorTicks = ticks.getMajorTicks();
        final int size = majorTicks.size();
        final double[] majorTicksArray = majorTicks.getItemsArray();

        for (int i = 0; i < size; i++) {
            final double valueToFormat = majorTicksArray[i];
            final String formattedValue = formatLabel(valueToFormat);
            formattedTickLabels.add(formattedValue);
        }
    }

    @Override
    public String formatLabel(Comparable dataValue) {
        return dataValue.toString() + " vvvv";
    }

    @Override
    public String formatCursorLabel(Comparable dataValue) {
        return dataValue.toString() + " vvvv";
    }

    @Override
    public List<String> getFormattedTickLabels() {
        return formattedTickLabels;
    }
}

From this hopefully you should be able to format labels dynamically. Don’t forget you can access the axis instance from the base class (it’s a protected field) so you can call axis.getVisibleRange() to know how zoomed in you are when formatting labels.

Best regards,
Andrew

    • Guest
    • 8 years ago
    • 1
    Thanks!
  • You must to post comments
0
0

Hi Patrik,

The current convention for modifying DateTimeAxis formatting dynamically is to use the LabelProvider API.

To use this:

  1. Create a class which inherits DateLabelProvider
  2. Override formatLabel and formatCursorLabel
  3. Also override attachToAxis. Here you can grab a reference to the axis. When formatting labels you can call axis.getVisibleRange() to know the current range before formatting.
  4. Attach your class to DateTimeAxis.setLabelProvider

Let me know if this helps.

Best regards,
Andrew

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.