How to remove padding from horizontal shading of mpandroidchart?

I'm trying to make a horizontal barcher that spans the entire parent layout, but it doesn't. 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 to fill the entire blue area. Can someone help.

EDIT: @PhilippJahoda I tried your solution, but on first run it shows the same as when when I click / tap on the chart then only it covers the whole area. Could you please tell me why I have to touch the diagram to fill all the space.

On first run it looks like

Screenshot: enter image description here

After clicking it looks like

Screenshot2: enter image description here

+3


source to share


4 answers


Update to the latest version of the library if you haven't already. Then just remove all offsets from the chart. It's in the documentation .

Call:



chart.setViewPortOffsets(0f, 0f, 0f, 0f);

      

+7


source


Removing indentation works with

chart.setViewPortOffsets(0f, 0f, 0f, 0f);

      



but if the effect only appears after clicking, try invalidating the chart display (after setting the data) as follows:

post(new Runnable() {
    @Override
    public void run() {
        chartView.invalidate();
    }
});

      

+2


source


    YAxis yl = chart.getAxisLeft();
    yl.setSpaceTop(20f);

      

0


source


The best way to control padding is what I feel like:

  • Set all offsets to 0

    chart.setViewPortOffsets (0f, 0f, 0f, 0f);

  • Controlling indentation from XML

    com.github.mikephil.charting.charts.LineChart android: id = "@ + id / chart" android: layout_width = "match_parent" android: layout_height = "500dp" android: layout_marginTop = "10dp" android: layout_marginLeft = "10dp" android: layout_marginBottom = "10dp"

0


source







All Articles