如何解决Android MPAndroidChart中条形图 xAxis标签未居中的问题

x标签未在条形图中间正下方显示

代码:
/**
* 单数据集。设置柱状图样式,X轴为字符串,Y轴为数值
*
* @param barChart
* @param xAxisValue
* @param yAxisValue
*/
public void setBarChart(BarChart barChart, List xAxisValue, List yAxisValue) {
barChart.getDescription().setEnabled(false);//设置描述
barChart.setPinchZoom(true);//设置按比例放缩柱状图

    //设置自定义的markerView
    MyMarkerView markerView = new MyMarkerView(barChart.getContext(), R.layout.custom_marker_view);
    barChart.setMarker(markerView);

// MyMarkerView mv = new MyMarkerView(mContext, R.layout.custom_marker_view);
// mv.setChartView(chart); // For bounds control
// manager.setMarker(mv); // Set the marker to the

    //x坐标轴设置
    IAxisValueFormatter xAxisFormatter = new StringAxisValueFormatter(xAxisValue);//设置自定义的x轴值格式化器
    XAxis xAxis = barChart.getXAxis();//获取x轴
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);//设置X轴标签显示位置
    xAxis.setDrawGridLines(false);//不绘制格网线
    xAxis.setGranularity(1f);//设置最小间隔,防止当放大时,出现重复标签。
    xAxis.setValueFormatter(xAxisFormatter);
    xAxis.setDrawLabels(true);

// xAxis.setXOffset(-10);
xAxis.setTextSize(8f);//设置标签字体大小
xAxis.setLabelCount(xAxisValue.size(),false);//设置标签显示的个数
// xAxis.setAxisMinimum(0f);
// xAxis.setAxisMaximum(1000f);
// xAxis.setAxisMinimum(1f);
// xAxis.setAxisMaximum(xAxisValue.size() - 1.1f);
xAxis.setValueFormatter(new IndexAxisValueFormatter(xAxisValue));

    xAxis.setCenterAxisLabels(true);//设置标签居中

    xAxis.setDrawAxisLine(true);

    xAxis.setLabelRotationAngle(60);




    //y轴设置
    YAxis leftAxis = barChart.getAxisLeft();//获取左侧y轴
    leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);//设置y轴标签显示在外侧
    leftAxis.setAxisMinimum(0f);//设置Y轴最小值
    leftAxis.setDrawGridLines(true);
    leftAxis.setDrawLabels(true);//禁止绘制y轴标签
    leftAxis.setDrawAxisLine(true);//禁止绘制y轴

    barChart.getAxisRight().setEnabled(false);//禁用右侧y轴

    //图例设置
    Legend legend = barChart.getLegend();
    legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);//图例水平居中
    legend.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);//图例在图表上方
    legend.setOrientation(Legend.LegendOrientation.HORIZONTAL);//图例的方向为水平
    legend.setDrawInside(false);//绘制在chart的外侧
    legend.setDirection(Legend.LegendDirection.LEFT_TO_RIGHT);//图例中的文字方向

    legend.setForm(Legend.LegendForm.SQUARE);//图例窗体的形状
    legend.setFormSize(0f);//图例窗体的大小
    legend.setTextSize(16f);//图例文字的大小
    //legend.setYOffset(-2f);

    //设置柱状图数据
    setBarChartData(barChart, yAxisValue, "", null);

    barChart.setExtraBottomOffset(10);//距视图窗口底部的偏移,类似与paddingbottom
    barChart.setExtraTopOffset(30);//距视图窗口顶部的偏移,类似与paddingtop
    barChart.setFitBars(true);//使两侧的柱图完全显示
    barChart.animateX(100);//数据显示动画,从左往右依次显示
}


    问题截图:
    ![图片说明](https://img-ask.csdn.net/upload/201911/17/1573960883_278806.png)

https://blog.csdn.net/tangzeyu7/article/details/78855955

xAxis你要显示的是字符串,那开始时就要对字符串进行声明和定义吧?
建议你把xAxis变成与yAxis一样的、显示数字的(不显示字符串)进行调试,看是不是这个原因。