Skip to content Skip to sidebar Skip to footer

Mpandroidchart Some Dot's Color Doesn't Change

I'm making scatter chart that if value over specific value, the dot's color is changed. I wrote codes like these. for (int i = 0; i < 30; i++) { float y = (float) (Ma

Solution 1:

You can create two sets for the points above and below the reference and assign colors to the two sets.

ArrayList<Entry> aboveLevel = new ArrayList<>();
ArrayList<Entry> belowLevel = new ArrayList<>();

for (int i = 0; i < 30; i++){
    float y = (float) (Math.random()*0.2+0.1);
    if (y>=0.2f) {
       aboveLevel.add(new Entry(i, y));
    } else {
       belowLevel.add(new Entry(i, y));
    }
}

ScatterDataSet set1 = new ScatterDataSet(aboveLevel, "Above");
set1.setColor(ColorTemplate.COLORFUL_COLORS[0]);

ScatterDataSet set2 = new ScatterDataSet(belowLevel, "Below");
set2.setColor(ColorTemplate.COLORFUL_COLORS[1]);

ArrayList<IScatterDataSet> dataSets = new ArrayList<>();
dataSets.add(set1); // add the data sets
dataSets.add(set2);

// create a data object with the data sets
ScatterData data = new ScatterData(dataSets);

chart.setData(data);

Post a Comment for "Mpandroidchart Some Dot's Color Doesn't Change"