【发布时间】:2023-03-22 03:13:01
【问题描述】:
谁能帮助我解释为什么我的 xAxis 对齐不正确。我希望这些点与每个相应的文本标签(星期几)对齐
这是图表的样子:GRAPH PICTURE
以及产生它的代码
private void setupChart() {
final ArrayList<Entry> points = new ArrayList<>();
//Add the values into the graph
points.add(new Entry(1, 17));
points.add(new Entry(2, 14));
points.add(new Entry(3, 10));
points.add(new Entry(4, 2));
points.add(new Entry(5, 20));
//Format the dataset to look nice
LineDataSet lineDataSet = new LineDataSet(points, "Experiments");
lineDataSet.setColor(Color.MAGENTA);
lineDataSet.setCircleColor(Color.GREEN);
lineDataSet.setCircleRadius(5);
lineDataSet.setValueTextSize(10);
lineDataSet.setLineWidth(3);
//Add the LineDataSet to the DataSets
final ArrayList<ILineDataSet> dataSets = new ArrayList<>();
dataSets.add(lineDataSet);
final LineData lineData = new LineData(dataSets);
chart.setData(lineData);
//Format the chart nicely
chart.setDrawGridBackground(false);
chart.setDrawBorders(false);
chart.getAxisRight().setEnabled(false);
chart.getLegend().setEnabled(false);
chart.getDescription().setEnabled(false);
chart.setExtraBottomOffset(10);
chart.setPinchZoom(false);
//Get the XAxis of the grid
XAxis xaxis = chart.getXAxis();
//Format the xAxis
final String[] dateStrings = new String[]{"Mon", "Tue", "Wed", "THU", "Fri"};
xaxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xaxis.setLabelCount(5);
xaxis.setLabelRotationAngle(-8);
xaxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return dateStrings[(int) value];
}
});
}
我在我的依赖项中使用 com.github.PhilJay:MPAndroidChart:v3.0.2
【问题讨论】: