Android - Show cursor line


Ok, so this is what I’d like to happen for this particular graph. It’s a line graph with Floats on the Y axis, and Dates on the X.

I’d like to display a “cursor” line through the middle data point. When scrolling the graph, the line should stay locked onto the center point. (The screen this graph is in will display data for that center point the cursor is on).

Except for the crosshair not showing up until a long press, I got close using the crosshair, but when the crosshair is active, the graph doesn’t scroll left/right.

Any ideas on how best to implement this?




It’s not ideal, but I got the “cursor” line drawing by overriding the draw method of ChartView, and manually drawing the line at the center-most data point.

ChartView view = new ChartView(context) {
    public void draw(Canvas canvas) {
        Data<Date, Float> p = getCenterPoint();
        float x = xAxis.getPixelValueForUserValue(p.getX());
        canvas.drawLine(x, 0, x, getHeight(), paint);


Hi ryanbis,

I just added a comment to your other post - you might find our Annotations feature will be useful for doing this.

Kind regards,