Ziv Kesten
Ziv Kesten

Reputation: 1242

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

Upvotes: 7

Views: 4327

Answers (2)

Ricardo
Ricardo

Reputation: 9676

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

Upvotes: 10

Philipp Jahoda
Philipp Jahoda

Reputation: 51421

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
}

Upvotes: 10

Related Questions