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
- Guest asked 8 years ago
- You must login to post comments
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
- Andrew Burnett-Thompson answered 8 years ago
-
Thanks!
- You must login to post comments
Hi Patrik,
The current convention for modifying DateTimeAxis formatting dynamically is to use the LabelProvider API.
To use this:
- Create a class which inherits DateLabelProvider
- Override formatLabel and formatCursorLabel
- 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.
- Attach your class to DateTimeAxis.setLabelProvider
Let me know if this helps.
Best regards,
Andrew
- Andrew Burnett-Thompson answered 8 years ago
- You must login to post comments
Please login first to submit.