Hi again,
Is it possible to move the rollover modifier without a touch when I know the x-axis and y-axis values?
At the moment user can tap the chart and the rollover modifier shows up and snaps to the closest point. Then I leave the rollover modifier visible by ignoring the onTouchUp() event. I have an external component that has the same data as the graph and now if user selects an item from that external component I would like to move the rollover modifier to that point. How can I do this?
- Erika Sankari asked 4 years ago
- You must login to post comments
Hi Erika,
I tried to modify one of our examples to test how place RolloverModifier programatically:
public class MountainChartFragment extends ExampleBaseFragment {
@BindView(R.id.chart)
SciChartSurface surface;
@Override
protected int getLayoutId() {
return R.layout.example_single_chart_fragment;
}
@Override
protected void initExample() {
final IAxis xBottomAxis = sciChartBuilder.newDateAxis().withGrowBy(0.1d, 0.1d).build();
final IAxis yRightAxis = sciChartBuilder.newNumericAxis().withGrowBy(0.1d, 0.1d).build();
final PriceSeries priceData = DataManager.getInstance().getPriceDataIndu(getActivity());
final IXyDataSeries<Date, Double> dataSeries = sciChartBuilder.newXyDataSeries(Date.class, Double.class).build();
dataSeries.append(priceData.getDateData(), priceData.getCloseData());
final FastMountainRenderableSeries rSeries = sciChartBuilder.newMountainSeries()
.withDataSeries(dataSeries)
.withStrokeStyle(0xAAFFC9A8, 1f, true)
.withAreaFillLinearGradientColors(0xAAFF8D42, 0x88090E11)
.build();
final CustomRolloverModifier modifier = new CustomRolloverModifier();
UpdateSuspender.using(surface, new Runnable() {
@Override
public void run() {
Collections.addAll(surface.getXAxes(), xBottomAxis);
Collections.addAll(surface.getYAxes(), yRightAxis);
Collections.addAll(surface.getRenderableSeries(), rSeries);
Collections.addAll(surface.getChartModifiers(), sciChartBuilder.newModifierGroupWithDefaultModifiers().withModifier(modifier).build());
}
});
Dispatcher.postDelayedOnUiThread(new Runnable() {
@Override
public void run() {
final int index = 0;
modifier.setRolloverAt(priceData.getDateData().get(index), priceData.getCloseData().get(index));
}
}, 1000);
}
static class CustomRolloverModifier extends RolloverModifier {
public void setRolloverAt(Date xValue, double yValue) {
final float x = getXAxis().getCoordinate(xValue);
final float y = getYAxis().getCoordinate(yValue);
handleMasterTouchDownEvent(new PointF(x, y)); // place RolloverModifier at specified point
}
}
}
I tried to place RolloverModifier at first point of data series with some initial delay ( 1s after showing chart on screen ). It seems to works as it should ( please take a look on screenshot ).
Best regards,
Yura
- Yura Khariton answered 4 years ago
-
Thank you for the clear example! I had everything in place, but was testing it without the delay… So of course the rollover showed up in a weird place>.< But now it works:)
- You must login to post comments
Hi Erika,
Unfortunately we don’t support such behavior because RolloverModifier is touch modifier and it depends on MotionEvent lifecycle. So the only way to move it programatically is to simulate sequence of MotionEvents for this modifier or create custom modifier and call internal methods such as handleMasterTouchDownEvent, handleMasterTouchMoveEvent, handleMasterTouchUpEvent and clearAll with point which has coordinates relative to the center of chart, but they should be called in same order as appropriate touch events are executed ( so first should be handleMasterTouchDownEvent, then handleMasterTouchMoveEvent and end with handleMasterTouchUpEvent or clearAll if need to clear screen ).
So I would suggest to try to simulate the required output of RolloverModifier using Annotations API if this is possible. They can be easily moved programatically by setting X/Y value.
Also you can create a feature request and if it gets enough votes we’ll implement it in our library.
Best regards,
Yura
- Yura Khariton answered 4 years ago
-
Thanks again Yura for the fast reply! I decided to stick with the rollover modifier and to simulate a sequence of MotionEvents. I translate the x and y value to coordinates inside CustomRolloverModifier like this: val x = xAxis?.getCoordinate(dateValue) val y = yAxis?.getCoordinate(numberValue) How do I convert these coordinates to be relative to the center of the chart? Because when I create a PointF based on those coordinates, the rolloverModifier appears in wrong position.
-
We have a method which accepts ModifierTouchEventArgs and translates its coords relative to center of chart, then sets tranlated coords to PointF ( https://www.scichart.com/documentation/android/current/webframe.html#SciChart.Charting~com.scichart.charting.modifiers.MasterSlaveTouchModifierBase~updateCurrentPoint.html ). Or you can use getPointRelativeTo ( https://www.scichart.com/documentation/android/current/webframe.html#SciChart.Charting~com.scichart.charting.modifiers.ChartModifierBase~getPointRelativeTo.html ) and translate point relative to ModifierSurface ( https://www.scichart.com/documentation/android/current/webframe.html#SciChart.Charting~com.scichart.charting.modifiers.IChartModifierCore~getModifierSurface.html ), that is placed in the center of chart ( you will need to set currentPoint with coords relative to chart before getPointRelativeTo() and after the call point contain coords relative to specified target, e.g. ModifierSurface).
-
Sorry I still don’t quite understand. My chart is a line chart with a date xAxis and a numeric yAxis. Now I know the date and the numeric value and I want to get the x coordinate of the date and y coordinate of the numeric value. The idea is to move the rollover modifier to that point. Inside my rollover modifier I get these coordinates like I mentioned above: val x = xAxis?.getCoordinate(dateValue) val y = yAxis?.getCoordinate(numericValue) (is this the correct way to get the coordinates?). The getPointRelativeTo() returns a boolean. What should I now pass on to the rolloverModifier’s handleMasterTouchDownEvent()?
-
getPointRelativeTo() updates PointF instance with coords relative to specified target. It returns true if transformation is successfull, but since you use axis.getCoordinate() you don’t need to do this transformation, because axis is placed relative to center of chart by default.
- You must login to post comments
Please login first to submit.