MPAndroidChart white Background - android

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

You want this for transparent:
chart.setDrawGridBackground(false);
And this for transparent bar:
chart.setDrawBarShadow(false);

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:
in .xml (android:background="...")
--> set the background color of the chart in xml or set the backgroud color of the layout the chart is in.
by calling 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.

You can do this with:
chart.setBackgroundColor(getResources().getColor(R.color.transparent));
Please define first:
<color name="transparent">#00000000</color>

Related

Fill the transparent part of the drawable image a specific color

Currently, I have this back arrow that I'm going to use in my toolbar
What I want is to fill the middle part which a specific color which is the middle part is a transparent part.
currently what i have is this :
Drawable backArrow = getResources().getDrawable(R.drawable.ic_back);
backArrow.setColorFilter(getResources().getColor(R.color.aub_red), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(backArrow);
it only changes the color of the white color part into the red color which is wrong. what I want to fill the transparent part a color not the non - transparent part.
Used this
Drawable backArrow = getResources().getDrawable(R.drawable.ic_back);
backArrow.setColorFilter(getResources().getColor(R.color.colorAccent), PorterDuff.Mode.LIGHTEN);
getSupportActionBar().setHomeAsUpIndicator(backArrow);
for more information click hear
you can use :
DrawableCompat.setTint(yourdrawable,getResources().getColor(R.color.primary));
in java code, or in xml tag :
android:backgroundTint="#color/primary"

MPAndroidChart limit line color not quite correct

MPAndroidCharts is so great.
I've changed my LineChart Limit line (and Text) color to an accent color used all over my app. However, the color of the line (and text) is much darker when compared to the rest. I suspect this is because the color is mixing with the chart background color have set - not sure though
What I've tried so far.
1) Set the drawable in the xml and programmatically. No change.
2) setDrawLimitLinesBehindData(false); No change.
3) changing the background color to a different shade. No apparent change.
The color you want to apply, add that in your colors.xml. After that add following line:
ll.setLineColor(getContext().getResources().getColor(R.color.your_color));

MPAndroidChart - Set a background image [duplicate]

I'm using the amazing library MPAndroidChart. It works like a charm, except when I'm trying to change the background color of the BarData. Default color is white, and I want to change it to Transparent.
I've tried this :
Paint p1 = mChart.getPaint(Chart.PAINT_GRID_BACKGROUND);
p1.setColor(Color.RED);
and this:
<com.github.mikephil.charting.charts.BarChart
android:id="#+id/chart1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"/>
... but it seems that doesnt works.
Any ideas ?
Thanks =)
Since release v1.6.5, the background of the Chart is transparent by default. Meaning, that everything in the background (chart background, other Views, etc.) that is not overlayed by data drawn into the Chart, will be visible.
If you want to change the background (color, or maybe drawable), you can either do that by changing the chart-background
in .xml (android:background="...")
by calling setBackgroundColor(...) or setBackgroundResource(...)
Another way could be to change the background of the parent layout that contains the Chart.
Code to change Background color:
chart.setBackgroundColor(Color.TRANSPARENT); //set whatever color you prefer
chart.setDrawGridBackground(false);// this is a must
if you want to Change Whole Screen Background Color
Barchart chart;
chart.setBackgroundColor(Color.rgb(0, 0, 0));//Set as a black
chart.setDrawGridBackground(false);//set this to true to draw the grid background, false if not
Happy to help Thanks
So, after some research, I've found that it's not possible yet: https://github.com/PhilJay/MPAndroidChart/issues/53
Hope It will be possible soon ! =)

MPAndroidChart how to set label color?

got the following code:
graph = (LineChart) convertView.findViewById(R.id.graph);
graph.getPaint(Chart.PAINT_LEGEND_LABEL).setColor(Color.BLUE);
graph.getPaint(Chart.PAINT_YLABEL).setColor(Color.BLUE);
graph.getPaint(Chart.PAINT_XLABEL).setColor(Color.BLUE);
But still the color of X/Y-value-lables and also the lable of the legend stay in black color. Do I miss something? Is there an other way to set the color of these?
This line for example works and results in blue value-lables for each data-point:
graph.getPaint(Chart.PAINT_VALUES).setColor(Color.BLUE);
Thanks in advance!
Try this to set the colors of axis and legend:
chart.getAxisLeft().setTextColor(...); // left y-axis
chart.getXAxis().setTextColor(...);
chart.getLegend().setTextColor(...);
chart.getDescription().setTextColor(...);
If you want to set the color of the drawn values inside the chart, check out the setting colors documentation or the setting data documentation.
Incase for a pie chat to change its label colors you can do this
pieChart.getLegend().setTextColor(Color.WHITE);

How to change chart background with MPAndroidChart library?

I'm using the amazing library MPAndroidChart. It works like a charm, except when I'm trying to change the background color of the BarData. Default color is white, and I want to change it to Transparent.
I've tried this :
Paint p1 = mChart.getPaint(Chart.PAINT_GRID_BACKGROUND);
p1.setColor(Color.RED);
and this:
<com.github.mikephil.charting.charts.BarChart
android:id="#+id/chart1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"/>
... but it seems that doesnt works.
Any ideas ?
Thanks =)
Since release v1.6.5, the background of the Chart is transparent by default. Meaning, that everything in the background (chart background, other Views, etc.) that is not overlayed by data drawn into the Chart, will be visible.
If you want to change the background (color, or maybe drawable), you can either do that by changing the chart-background
in .xml (android:background="...")
by calling setBackgroundColor(...) or setBackgroundResource(...)
Another way could be to change the background of the parent layout that contains the Chart.
Code to change Background color:
chart.setBackgroundColor(Color.TRANSPARENT); //set whatever color you prefer
chart.setDrawGridBackground(false);// this is a must
if you want to Change Whole Screen Background Color
Barchart chart;
chart.setBackgroundColor(Color.rgb(0, 0, 0));//Set as a black
chart.setDrawGridBackground(false);//set this to true to draw the grid background, false if not
Happy to help Thanks
So, after some research, I've found that it's not possible yet: https://github.com/PhilJay/MPAndroidChart/issues/53
Hope It will be possible soon ! =)

Categories

Resources