Reputation: 21
I am using Mphil chart lib, I have added this code for my line chart.
But its not changing the color, its showing default purple color, is there something i missed or error in my code
LineDataSet set1;
if (mChart.getData() != null &&
mChart.getData().getDataSetCount() > 0) {
set1 = (LineDataSet) mChart.getData().getDataSetByIndex(0);
set1.setValues(values);
mChart.getData().notifyDataChanged();
mChart.notifyDataSetChanged();
} else {
set1 = new LineDataSet(values, "");
set1.setDrawIcons(false);
set1.setLabel("");
set1.setDrawValues(false);
set1.setHighLightColor(R.color.extracyan);
mChart.getLegend().setEnabled(false);
// set1.enableDashedLine(10f, 5f, 0f);
//set1.enableDashedHighlightLine(10f, 5f, 0f);
set1.setColor(R.color.extracyan);
set1.setCircleColor(R.color.extracyan);
set1.setLineWidth(3.5f);
set1.setDrawCircles(false);
set1.setCircleRadius(3.5f);
set1.setDrawCircleHole(false);
set1.setValueTextSize(0f);
set1.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
set1.setDrawFilled(false);
set1.setFormLineWidth(2.5f);
set1.setFormLineDashEffect(new DashPathEffect(new float[]{10f, 5f}, 0f));
set1.setFormSize(15.f);
/*if (Utils.getSDKInt() >= 18) {
Drawable drawable = ContextCompat.getDrawable(this, R.drawable.fade_blue);
set1.setFillDrawable(drawable);
} else {
set1.setFillColor(R.color.cyan);
}*/
ArrayList<ILineDataSet> dataSets = new ArrayList<>();
dataSets.add(set1);
LineData data = new LineData(dataSets);
mChart.setData(data);
progresslayout.setVisibility(View.GONE);
txtProgress.setVisibility(View.GONE);
}
I tried adding diff color, diff method, but still the same, I tried adding 2 set with diff color but change , they both where in same color
Upvotes: 2
Views: 63
Reputation: 1068
You can add multiple colors for your charts
by this:
ArrayList<Integer> colors = new ArrayList<>();
for (int c : ColorTemplate.JOYFUL_COLORS)
colors.add(c);
for (int c : ColorTemplate.LIBERTY_COLORS)
colors.add(c);
for (int c : ColorTemplate.COLORFUL_COLORS)
colors.add(c);
for (int c : ColorTemplate.VORDIPLOM_COLORS)
colors.add(c);
for (int c : ColorTemplate.PASTEL_COLORS)
colors.add(c);
set1.setColors(colors);
replace this code by set1.setColor(R.color.extracyan);
that.
Upvotes: 1