问题
I am able to plot Marks Dynamically and set Different Color to the LineChart.Now i am having issue of, not able to fill the Color in the Region where the LineChart occupies.I have used setS.setDrawFilled(true); but it Fill with only one Color.How can this issue be Solved?
int getColorRandom() {
Random rand = new Random();
int r = rand.nextInt(255);
int g = rand.nextInt(255);
int b = rand.nextInt(255);
int randomColor = Color.rgb(r, g, b);
return randomColor;
}
ArrayList<ILineDataSet> testDataSet1 = new ArrayList<>();
for (int i = 0; i < dataFilteredByTerm.size(); i++) {
ArrayList<JSONObject> values = dataFilteredByTerm.get(termIDs.get(i));
ArrayList<Entry> allMarks1 = new ArrayList<>();
for (int k = 0; k < values.size(); k++) {
allMarks1.add(new Entry(k, values.get(k).optInt("Marks")));
}
Labels.add(jsonArray.optJSONObject(i).optString("CourseName"));
System.out.println("Labels" + Labels);
// System.out.println("allMarks" + allMarks1);
setS = new LineDataSet(allMarks1, values.get(i).optString("examDescription")); // set different color for each set as your requirement testDataSet.add(set); } chart.setData(new LineData(testDataSet));
//testDataSet1.add(labels);
testDataSet1.add(setS);
setS.setMode(LineDataSet.Mode.CUBIC_BEZIER);
setS.setDrawValues(false);
// setS.setColor(Integer.parseInt((getColor.get(i))));
// int y= setS.setColors(getColor());
setS.setDrawFilled(true);
setS.setColors(getColorRandom());
}
// System.out.println("Date Filtered by Date" + dataFilteredByTerm);
YAxis leftAxis = chart.getAxisRight();
leftAxis.setEnabled(false);
//chart.setBorderColor(Color.RED);
chart.setData(new LineData(testDataSet1));
chart.getXAxis().setValueFormatter(new IndexAxisValueFormatter(Labels));
chart.notifyDataSetChanged();
chart.invalidate();
require image
getting image
I don't know where i am doing wrong.Every time the only one Color Fill all the region.How can the Region be Filled with specific line Color using MPAndroidChart
回答1:
I have Solved it myself just a simple twik and its done.
Just added this inbuilt method and output seems amazing
setS.setColors(getColorRandom());
setS.setDrawFilled(true);
setS.setFillColor(getColorRandom());
Image
来源:https://stackoverflow.com/questions/45055465/set-specific-color-to-the-region-occupied-by-linechart