SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and iOS Chart & Android Chart Components

Answered
0
0

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?

Version
3.0.1.4266
  • You must to post comments
Best Answer
1
0

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

Images
  • Erika Sankari
    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 to post comments
0
0

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

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.