Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I draw a circle on highlight point in line chart?

I'm using mpchart to draw my charts.I wanted to increase the circle size of intersection point of highlighter and line dataset. How can I achieve this?enter image description here

I read somewhere that we can add another dataset with highlighted point and increase its circle size. Is that really a good approach if my highlighter will be dragged back and forth and I'll have to update the new dataset very frequently?

like image 330
Heisenberg Avatar asked Jun 29 '16 13:06

Heisenberg


1 Answers

When using the MpChart Library, the library contains a MarkerView class that helps us to insert the markers for displaying the selected value in the chart. We can use this MarkerView class to display any kind of view for the selected chart data.

So for the dot I created a new ChartMarker class and extended MarkerView class. Then in the constructor I passed the layout containing an image view with the dot as the src to the super.

public ChartMarker(Context context) {
    //the super will take care of displaying the layout
    super(context, R.layout.layout_dot);
}

Finally set the ChartMarker instance to the chart through chart.setMarkerView()

ChartMarker elevationMarker = new ChartMarker(getActivity());
elevationChart.setMarkerView(elevationMarker);

And for the layout_dot.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

<ImageView
    android:background="@drawable/dot"
    android:layout_width="5dp"
    android:layout_height="5dp" />

</LinearLayout>
like image 64
Yogesh Avatar answered Nov 08 '22 15:11

Yogesh