Prince
Prince

Reputation: 20882

How to setDrawCircles() for only one (maximum) value in the chart?

I am using mpandroidchart and I want to draw a circle only for one Entry in the LineDataSet but not the rest. I have tried to accomplish it using two LineDataSets but it hasn't worked so far. Here's my code:

LineDataSet scoreDataSet = new LineDataSet(values, "Score");
scoreDataSet.setDrawCircles(false);

// Entry with max value is the last one
Entry circleEntry = scoreDataSet.getEntryForXIndex(scoreDataSet.getEntryCount()-1);

LineDataSet circularDataSet = new LineDataSet(values, "Score");
circularDataSet.setDrawCircles(true);
int size = circularDataSet.getEntryCount()-1;
for (int i=0; i<size; i++) {
    if (i != circleEntry.getXIndex()) {
            circularDataSet.removeEntry(circularDataSet.getEntryForXIndex(i));
    }
}
.
.
.
ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>();
dataSets.add(scoreDataSet);
dataSets.add(circularDataSet);

This just prints a dot(circularDataSet) and not the scoreDataSet. I was expecting it to merge both the DataSets so as to mark the highest value with a circle and drawing the rest as a line chart.

Upvotes: 1

Views: 1091

Answers (1)

Philipp Jahoda
Philipp Jahoda

Reputation: 51421

Your approach looks good in general, there are just a few flaws.

Don't create the "circularDataSet" and initialize it with the same values like the "scoreDataSet" and then remove all except one.

What you should do instead is find the largest entry in your "scoreDataSet", and then only add this single entry to the "circularDataSet".

Upvotes: 2

Related Questions