SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components
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).
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
Please login first to submit.