Reputation: 29
I am using the MPAndroidChart library. I am setting the multi line chart with data using MPAndroidChart. It's working great but the background is coming white. This is what i am doing
nhChart = new LineChart(getActivity());
nhChart.setDescription("Number of Hits View");
nhChart = (LineChart) hitsView.findViewById(R.id.line_chart_number_of_hits);
//int color = Color.parseColor("#80101010");
nhChart.setBackgroundColor(Color.parseColor("#80101010"));
//nhChart.setBackgroundResource(R.drawable.background_portrate);
//nhChart.setBackground(getResources().getDrawable(R.drawable.background_portrate));
nhChart.setStartAtZero(true);
nhChart.setDrawBorder(true);
nhChart.setNoDataTextDescription("No Data available for Charts");
nhChart.setDrawYValues(false);
nhChart.setDrawBorder(true);
nhChart.setScaleEnabled(true);
nhChart.setHighlightEnabled(false);
nhChart.setTouchEnabled(true);
//nhChart.setGridColor(Color.WHITE & 0x70FFFFFF);
//nhChart.setDragScaleEnabled(true);
nhChart.setPinchZoom(true);
setData(valueDate.size(),10000);
nhChart.animateX(2500);
Legend l = nhChart.getLegend();
l.setForm(LegendForm.CIRCLE);
l.setFormSize(6f);
l.setTextColor(Color.WHITE);
YLabels y = nhChart.getYLabels();
y.setTextColor(Color.WHITE);
y.setLabelCount(6);
XLabels x1 = nhChart.getXLabels();
x1.setCenterXLabelText(true);
x1.setPosition(XLabelPosition.BOTTOM);
x1.setTextColor(Color.WHITE);
I am plotting line graphs in post execute method of AsyncTask in a fragment viewpager. Other fragment showing the graph shows the same white background. I tried setting a color for the background but nothing works. I also left it blank, but its still showing me the white background. I also updated the latest Jar but its not works. Please help. Here is the image how it looks
Upvotes: 1
Views: 4970
Reputation: 788
You want this for transparent:
chart.setDrawGridBackground(false);
And this for transparent bar:
chart.setDrawBarShadow(false);
Upvotes: 5
Reputation: 2555
You can do this with:
chart.setBackgroundColor(getResources().getColor(R.color.transparent));
Please define first:
<color name="transparent">#00000000</color>
Upvotes: 0
Reputation: 51421
Well by default, the backgroud of the chart is transparent which means that it will have whatever color you set for the view/layout below the chart.
If you want to change the background (color, or maybe drawable), you can do that in the following ways:
android:background="..."
)
--> set the background color of the chart in xml or set the backgroud color of the layout the chart is in.setBackgroundColor(...)
or setBackgroundResource(...)
I guess you want your background to be some kind of black? What happens if you call:
chart.setBackgroundColor(Color.BLACK)
?
Does setting the background-color work then? Also check the example code in the github repo here. There are some cases in the example app that change the background color.
Upvotes: 2