Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPAndroidChart - how to draw a circle in the last entry only?

Using MPAndroidChart, Is there a way to draw only one circle in line chart?, this means that only the end of the line will be represented be a circle as shown in this image: enter image description here

@PhilJay

like image 441
Ziv Kesten Avatar asked May 03 '15 08:05

Ziv Kesten


2 Answers

I have searched and struggled a bit because of this and in my opinion the best solution is to use setIcon which is quite a recent method and won't get messed in case you have an animation. Here is an example:

dataSet.getEntryForIndex(position).setIcon(ContextCompat.getDrawable(this,R.drawable.myDrawable));

This will work for any position, in case you wish to have different points with different drawables

like image 122
Ricardo Avatar answered Sep 19 '22 10:09

Ricardo


Well a workaround could be that you always put the last entry in a separate DataSet as well which has setDrawCircles(...) enabled. So you add the last entry to a separate DataSet and to you actual DataSet as well.

As soon as there is a "new" last entry, clear the circle-dataset and add that new entry to it.

Pseudo example

public void add(Entry e) {

   actualDataSet.addEntry(e);

   circleDataSet.clear();
   circleDataSet.addEntry(e);

   chart.notifyDataSetChanged(); // let the chart know it's data changed
   chart.invalidate(); // redraw
}
like image 21
Philipp Jahoda Avatar answered Sep 19 '22 10:09

Philipp Jahoda