I have stock charts and want to prevent the user to go beyond the Min/Max datetimes (left, right). I tried applying setVisibleRangeLimitMode() to XAxis but it has no effect:
private final DoubleRange sharedXRange = new DoubleRange();
//sharedXRange.setMinMax(0d, response.body().getData().size()-1d); // not helping
...
final CategoryDateAxis xAxis = sciChartBuilder.newCategoryDateAxis()
.withVisibility(isMainPane ? View.VISIBLE : View.GONE)
.withVisibleRange(sharedXRange)
.withGrowBy(0.1d, 0.1d)
.build();
xAxis.setMinimalZoomConstrain(10d); // minimum 10 points
xAxis.setVisibleRangeLimitMode(RangeClipMode.MinMax); // not working
//xAxis.setVisibleRangeLimit(new DoubleRange(-5d,5d));
...
I am thinking that maybe I should set Min and Max to sharedXRange, but couldn’t find in the docs what value to put into (tried with index, and Date without luck).
- Primoz asked 5 years ago
- last edited 5 years ago
- Let me also point out that I am premium user (here it says my Tiral expired??), my order ID is ABT181022-9293-43119.
- You must login to post comments
Hi Primos,
By default VisibleRangeLimit isn’t applied when you set VisibleRange because we assume that when you set it manually then you know what you’re doing. VisibleRangeLimit is applied during auto range calculations and modifier interaction ( when you scroll, zoom or pan chart ) when VisibleRange is changed indirectly.
If you want to apply VisibleRangeLimit anyway you can create custom axis and override method which checks whether new VisibleRange value satisfies constrains and add check for limit. Then you can override coerceVisibleRange() method which is called when check is failed and apply VisibleRangeLimit constrain there:
class CustomCategoryDateAxis extends CategoryDateAxis {
public CustomCategoryDateAxis(Context context) {
super(context);
}
@Override
protected boolean isZoomConstrainSatisfied(IRange<Double> range) {
final IRange<Double> limit = getVisibleRangeLimit();
final boolean isRangeWithinLimit = limit == null || (limit.isValueWithinRange(range.getMin()) && limit.isValueWithinRange(range.getMax()));
return isRangeWithinLimit && super.isZoomConstrainSatisfied(range);
}
@Override
protected void coerceVisibleRange(IRange<Double> visibleRange) {
super.coerceVisibleRange(visibleRange);
tryApplyVisibleRangeLimitTo(visibleRange);
}
}
Hope this will help you!
Best regards,
Yura
- Yura Khariton answered 5 years ago
- last edited 5 years ago
- Thank you for your answer. I tried to implement this but still does not seem to work. Is your answer applicable to MultiPaneStockFragment example (https://github.com/ABTSoftware/SciChart.Android.Examples/blob/master/v2.x/Examples/app/src/main/java/com/scichart/examples/fragments/CreateMultiPaneStockChartFragment.java)?
- I didn’t tested it but I think it should work for any case – it just adds additional check if VisibleRange is within VisibleRangeLimit and if it is not then it tries to apply it to VisibleRange. The only addition I would add is check if limit is null because it could potentially cause NPE if you set VisibleRange before setting VisibleRangeLimit.
- I’ve updated my answer and added additional null check for isRangeWithinLimit
- You must login to post comments
Please login first to submit.