[Android] Crosshair Questions



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.



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):



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.




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() {
    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);


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


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,



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);

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,