I am trying to make a horizontal barchart that covers the entire parent layout but its not. Below is my code -
HorizontalBarChart barchart = new HorizontalBarChart(activity);
barchart.setLayoutParams(new LinearLayout.LayoutParams(0, 110, weight));
ArrayList<BarEntry> entries = new ArrayList<BarEntry>();
entries.add(new BarEntry(86.0f, 0));
BarDataSet dataset = new BarDataSet(entries, "");
dataset.setColor(Color.parseColor("#E0E0E0"));
ArrayList<String> labels = new ArrayList<String>();
labels.add("86.0");
BarData bardata = new BarData(labels, dataset);
barchart.setData(bardata);
barchart.setDescription("");
Legend legend = barchart.getLegend();
legend.setEnabled(false);
YAxis topAxis = barchart.getAxisLeft();
topAxis.setDrawLabels(false);
YAxis bottomAxis = barchart.getAxisRight();
bottomAxis.setDrawLabels(false);
XAxis rightAxis = barchart.getXAxis();
rightAxis.setDrawLabels(false);
bottomAxis.setDrawLabels(false);
barchart.setPadding(-1, -1, -1, -1);
barchart.setBackgroundColor(Color.CYAN);
return barchart;
I want my horizontal barchart (barchart) to fill the entire blue area. Can someone please help.
EDIT : @PhilippJahoda i tried your solution, but at first launch it shows up the same way it was, when i click/touch the chart then only it covers the entire area. Can you please tell me why i have to touch the chart to make it fill the entire space.
At first launch it looks like -
Screen shot:
After clicking it looks like -
Screen shot2:
Update to the latest version of the library if you have not already. Then, just remove all offsets from the chart. It's in the documentation.
Call:
chart.setViewPortOffsets(0f, 0f, 0f, 0f);