Java X轴标签未显示,使用MPAndroidChart
我希望在折线图上有x轴标签(使用),但无论我做什么,都无法显示它们。我有一个名为setupChart的方法,它处理该图表的所有内容,它看起来是这样的:Java X轴标签未显示,使用MPAndroidChart,java,android,mpandroidchart,Java,Android,Mpandroidchart,我希望在折线图上有x轴标签(使用),但无论我做什么,都无法显示它们。我有一个名为setupChart的方法,它处理该图表的所有内容,它看起来是这样的: private void setupChart(LineChart chart, LineData data, int color) { ((LineDataSet) data.getDataSetByIndex(0)).setCircleColorHole(Color.WHITE); ((LineDataSet) data.g
private void setupChart(LineChart chart, LineData data, int color) {
((LineDataSet) data.getDataSetByIndex(0)).setCircleColorHole(Color.WHITE);
((LineDataSet) data.getDataSetByIndex(0)).setCircleColor(color);
((LineDataSet) data.getDataSetByIndex(0)).setColors(dataColors);
data.getDataSetByIndex(0).setAxisDependency(YAxis.AxisDependency.LEFT);
((LineDataSet) data.getDataSetByIndex(0)).setDrawCircles(false);
// no description text
chart.getDescription().setEnabled(false);
// mChart.setDrawHorizontalGrid(false);
//
// enable / disable grid background
chart.setDrawGridBackground(false);
// enable touch gestures
chart.setTouchEnabled(true);
// disable scaling and dragging
chart.setDragEnabled(false);
chart.setScaleEnabled(false);
chart.setAutoScaleMinMaxEnabled(false);
// if disabled, scaling can be done on x- and y-axis separately
chart.setPinchZoom(false);
chart.setBackgroundColor(Color.parseColor("#dddddd"));
// set custom chart offsets (automatic offset calculation is hereby disabled)
chart.setViewPortOffsets(10, 0, 10, 0);
// add data
chart.setData(data);
// get the legend (only possible after setting data)
Legend l = chart.getLegend();
l.setEnabled(false);
chart.getAxisLeft().setEnabled(false);
chart.getAxisRight().setEnabled(false);
chart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
chart.getXAxis().setEnabled(false);
chart.getXAxis().setDrawLabels(true);
chart.getXAxis().setTextColor(context.getResources().getColor(R.color.colorPrimary));
chart.getXAxis().setTypeface(Typeface.SANS_SERIF);
YAxis yAxis = chart.getAxisLeft();
yAxis.setAxisMinimum(0f);
yAxis.setAxisMaximum(100f);
final String[] weeks = new String[52];
for(int i = 0; i < weeks.length; i++) weeks[i] = "Week " + (i+1);
IAxisValueFormatter formatter = new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return weeks[(int) value];
}
};
XAxis xAxis = chart.getXAxis();
xAxis.setGranularity(1f);
xAxis.setValueFormatter(formatter);
// animate calls invalidate()...
chart.animateXY(2000,2500);
}
private void setupChart(线条图、线条数据、int-color){
((LineDataSet)data.getDataSetByIndex(0)).setCircleColorHole(Color.WHITE);
((LineDataSet)data.getDataSetByIndex(0)).setCircleColor(颜色);
((LineDataSet)data.getDataSetByIndex(0)).setColors(dataColors);
data.getDataSetByIndex(0.setAxisDependency(YAxis.AxisDependency.LEFT);
((LineDataSet)data.getDataSetByIndex(0)).setDrawCircles(false);
//无描述文本
chart.getDescription().setEnabled(false);
//mChart.setDrawHorizontalGrid(假);
//
//启用/禁用网格背景
chart.setDrawGridBackground(假);
//启用触摸手势
chart.setTouchEnabled(真);
//禁用缩放和拖动
图表。setDragEnabled(假);
图表.setScaleEnabled(错误);
chart.setAutoScaleMinMaxEnabled(false);
//如果禁用,可以分别在x轴和y轴上进行缩放
chart.setPinchZoom(假);
图表.setBackgroundColor(Color.parseColor(#dddddddd”);
//设置自定义图表偏移(因此禁用自动偏移计算)
图表.SetViewPortOffset(10,0,10,0);
//添加数据
图表.设置数据(数据);
//获取图例(仅在设置数据后才可能)
Legend l=chart.getLegend();
l、 setEnabled(假);
chart.getAxisLeft().setEnabled(false);
chart.getAxisRight().setEnabled(false);
chart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
chart.getXAxis().setEnabled(false);
chart.getXAxis().setDrawLabels(true);
chart.getXAxis().setTextColor(context.getResources().getColor(R.color.colorPrimary));
chart.getXAxis().setTypeface(Typeface.SANS_SERIF);
YAxis YAxis=chart.getAxisLeft();
yAxis.setaxis最小值(0f);
yAxis.SetAxis最大值(100f);
最终字符串[]周=新字符串[52];
对于(int i=0;i
我不确定我做错了什么 我通过增加偏移量解决了这个问题:
chart.setViewPortOffsets(60, 0, 50, 60);
我通过增加偏移量解决了这个问题:
chart.setViewPortOffsets(60, 0, 50, 60);
我的图表没有显示x轴和y轴。我去掉这条线,x轴和y轴出现了 当该行存在时
lineChart.setViewPortOffset(0,0,0,0)
图表如下所示
当我删除这行时lineChart.setViewPortOffset(0,0,0,0)
图表如下所示
我的图表没有显示x轴和y轴。我去掉这条线,x轴和y轴出现了 当该行存在时
lineChart.setViewPortOffset(0,0,0,0)
图表如下所示
当我删除这行时lineChart.setViewPortOffset(0,0,0,0)
图表如下所示
修改偏移也将帮助您解决此问题
调整(ff)浮点值以获得所需的空间
修改偏移也将帮助您解决此问题
调整(ff)浮点值以获得所需的空间。您使用的库的哪个版本?@santalu 3.0.1版可能会解决问题。您使用的库的哪个版本?@santalu 3.0.1版可能会解决问题。