Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get x axis label into center of the bar chart #4394

Closed
narayanancr opened this issue Jun 13, 2020 · 1 comment
Closed

Cannot get x axis label into center of the bar chart #4394

narayanancr opened this issue Jun 13, 2020 · 1 comment

Comments

@narayanancr
Copy link

What I did?

        barDataSet = new BarDataSet(barEntries, "");
        barData = new BarData(barDataSet);
        barData.setBarWidth(.5f);
        barChart.setData(barData);
        barDataSet.setColors(getResources().getColor(R.color.colorPrimary));
        barDataSet.setValueTextColor(Color.BLACK);
        barDataSet.setDrawValues(false);
        barChart.getXAxis().setDrawAxisLine(false);
        barChart.setDrawGridBackground(false);
        barChart.getXAxis().setDrawGridLines(false);
        barChart.getAxisLeft().setDrawGridLines(false);
        barChart.getAxisRight().setDrawGridLines(false);
        barChart.getAxisLeft().setEnabled(false);
        barChart.getAxisRight().setEnabled(false);
        barChart.getLegend().setEnabled(false);
        barChart.setPinchZoom(false);
        barChart.setDescription(null);
        barChart.setTouchEnabled(false);
        barChart.setDoubleTapToZoomEnabled(false);
        barChart.setExtraOffsets(20, 0, 0, 30);

        XAxis xAxis = barChart.getXAxis();
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        xAxis.setTextSize(14f);
        xAxis.setTextColor(Color.BLACK);
        // Set the value formatter
        xAxis.setYOffset(5);
        xAxis.setDrawLabels(true);
        xAxis.setGranularityEnabled(true);
        xAxis.setGranularity(1f);
        xAxis.setXOffset(30);
        xAxis.setValueFormatter(new IndexAxisValueFormatter(xAxisLabel));
        xAxis.setCenterAxisLabels(true);

        barChart.invalidate();

What I expected to happen?

I wanted to get the labels in centre like this
image

What happened instead?

image

I only see solutions to centre labels in grouped bar charts or combined charts.

@sanket003
Copy link

I'm facing the same issue. In grouped bar chart the first bar is leaving some space at beginning. Any solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants