How can I draw a circle on highlight point in line

2019-02-14 08:03发布

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?

1条回答
贼婆χ
2楼-- · 2019-02-14 08:35

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>
查看更多
登录 后发表回答