[Android] Crosshair Questions


#1

Hello,

I’m wondering if the following things can be achieved easily with the Android library.

1.) Add a crosshair without showing the Y axis line.

2.) Show the Crosshair programatically without long tapping.

3.) Set the crosshair position programatically.

Thanks,


#2

Hello Blinky,

Thanks for getting in touch!

You can achieve 1) and 3) using the listerner methods in the following listener classes (which you must implement):

http://www.shinobicontrols.com/docs/ShinobiControls/ShinobiChartsAndroid/1.5.1/Premium/Normal/apidocs/docs/reference/com/shinobicontrols/charts/ShinobiChart.OnTrackingInfoChangedForCrosshairListener.html

http://www.shinobicontrols.com/docs/ShinobiControls/ShinobiChartsAndroid/1.5.1/Premium/Normal/apidocs/docs/reference/com/shinobicontrols/charts/ShinobiChart.OnTrackingInfoChangedForTooltipListener.html

Our API does not directly support option 2). You may be able to programmatically invoke a long press gesture, using the MotionEvent class in the Android framework. We suggest you experiement with this, but it is not something which we have tried.

I hope that you find this information useful.

Thanks,

Kai.


#3

Up vote for #2 - I am having to use annotations in combination with the gesture callbacks instead of the crosshair because of this one. We want a single tap to bring up the crosshair so another solution would be to allow us to specify what gesture brings up the crosshair.

Blinnky - The following code will draw a vertical line the entire height of the canvas with no y-axis line for the crosshair. 

shinobiChart.setOnCrosshairDrawListener(new ShinobiChart.OnCrosshairDrawListener() {
    @Override
    public void onDrawCrosshair(ShinobiChart shinobiChart, Canvas canvas, Rect drawingBoundary, float pixelXValue, float pixelYValue, float targetCircleRadius, Paint paint) {
        canvas.drawLine(pixelXValue, canvas.getClipBounds().top, pixelXValue, canvas.getClipBounds().bottom, paint);
    }
});

#4

It would be lovely to be able to show and hide the crosshair programatically.


#5

Hello Blinnky,

Thanks for the feedback. We do prioritise feature development based on customer demand so I’ll certainly register your interest in it.

Kind regards,

Kai.


#6

Hi guys,

Just to add to Kai’s original response regarding programmatically showing the crosshair, creating a MotionEvent in code (say, when a button is clicked) and dispatching it to the ChartView should do the trick. Something like the following:

long time = SystemClock.uptimeMillis();
float x = 500.0f;
float y = 500.0f

MotionEvent motionEventDown = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, x, y, 0);
chartView.dispatchTouchEvent(motionEventDown);
motionEventDown.recycle();

You would need to supply x and y pixels values that are inside the ChartView’s ChartCanvas (that is the plot area plus the axes). The Axis.getPixelValueForUserValue() method can be used to obtain pixel values for data values. Note, this method must be called after the chart has been laid out and so you may find the ShinobiChart.OnInternalLayoutListener callback interface useful in this respect.

Kind regards,

Patrick