Pre loader

How can i know what is visible range?(for formatting xAxis depend on range)

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

1
0

Lets imagine that we have zoom feature and we want to format axis depend on user selected zoom. for example if year select yearly the pattern is yyyy MM dd and if selected zoom is day the pattern is something like this HH:mm:ss. how we can achieve to this goal?

Version
4.4.0.4806
  • You must to post comments
1
1

Hi Vahid

Check out our documentation on Android Charts – How to Listen to VisibleRange Changes

With this code:

val axis = NumericAxis(context)
axis.setVisibleRangeChangeListener { axis, oldRange, newRange, isAnimating ->
    // TODO handle range changes here
}

You can be notified of axis visiblerange changes.

Also you might be interested in this article on Axis Formatting for trading charts. This shows a built-in way to dynamically change textformatting based on zoom.

  • You must to post comments
1
0

Unfortunately, this line( line 7 ) is never called.
and i can’t use https://www.scichart.com/documentation/android/current/articles/chart2d/axisAPIs/Axis%20Labels%20-%20Formatting%20for%20trading%20charts.html?tabs=kotlin because I am using IndexDateAxis

open class FinanceDateXAxis(context: Context?) : IndexDateAxis(DateRange(), NonClippingXAxisModifierSurface(context)) {

init {
    // need to set empty string to use CalendarDateLabelFormatter
    textFormattingProperty.setWeakValue(StringUtil.EMPTY)
    cursorTextFormattingProperty.setWeakValue(StringUtil.EMPTY)
    labelProvider = DateAxisLabelProvider()
    this.setVisibleRangeChangeListener { axis, oldRange, newRange, isAnimating ->
        Log.i("LOGGER","" + newRange.min) // this line
    }
}

class NonClippingXAxisModifierSurface @JvmOverloads constructor(
    context: Context?,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0,
) : AxisModifierSurface(context, attrs, defStyleAttr) {

    override fun layoutChildAt(child: View?, left: Int, top: Int, right: Int, bottom: Int) {
        when {
            left < 0 -> {
                super.layoutChildAt(child, 0, top, right - left, bottom)
            }
            right > width -> {
                super.layoutChildAt(child, left - (right - width), top, width, bottom)
            }
            else -> {
                super.layoutChildAt(child, left, top, right, bottom)
            }
        }
    }
}

}

  • You must to post comments
1
0

To make the axis label format range dependant, you need to create a custom labelFormatter. This gets a reference to the axis it is attached to, so you can look at the visible range when formatting the label. Here is a basic example which formats labels as 1.0K, 1.5K etc when the visible range is greater than 1000.

class RangeDependantLabelProvider extends LabelProviderBase<INumericAxis> {

RangeDependantLabelProvider() {
    super(INumericAxis.class);
}

@Override
public CharSequence formatLabel(double dataValue) {
    if (ComparableUtil.toDouble(this.axis.getVisibleRange().getDiff()) > 1000) {
        return String.format("%.1fK", dataValue / 1000.0);
    } else {
        return String.format("%.0f", dataValue);
    }
}

@Override
public CharSequence formatCursorLabel(double dataValue) {
    return String.format("%.0f", dataValue);
}

@Override
public CharSequence formatLabel(Comparable dataValue) {
    final double doubleValue = ComparableUtil.toDouble(dataValue);
    return this.formatLabel(doubleValue);
}

@Override
public CharSequence formatCursorLabel(Comparable dataValue) {
    final double doubleValue = ComparableUtil.toDouble(dataValue);
    return formatCursorLabel(doubleValue);
}

}

Regards
David

  • You must to post comments
Showing 3 results
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