如何用字符串替换Bar GraphView底部的数字?
How to replace the numbers on the bottom of Bar GraphView with strings?
我正在使用 jjoe64 GraphView 库在我的应用程序中创建条形图 GraphView。
当我创建一个新的 DataPoint 时,它需要 2 个值:X int 和一个 Y int,如下所示:
GraphView graph = (GraphView) findViewById(R.id.graph);
BarGraphSeries<DataPoint> series = new BarGraphSeries<DataPoint>(new DataPoint[] {
new DataPoint(0, -1),
new DataPoint(1, 5),
new DataPoint(2, 3),
new DataPoint(3, 2),
new DataPoint(4, 6)
});
graph.addSeries(series);
如何将底部的 X int 替换为字符串?
编辑#1
你所说的"bottom"是"X-axis"。要标记它,请使用
StaticLabelsFormatter staticLabelsFormatter = new StaticLabelsFormatter(graph);
staticLabelsFormatter.setHorizontalLabels(new String[] {"old", "middle", "new"});
graph.getGridLabelRenderer().setLabelFormatter(staticLabelsFormatter);
进一步阅读:Documentation
或者如果您使用 GraphView 3.x:
graphView.setHorizontalLabels(new String[] {"0.5", "1", "1.5", "2.0"});
我正在使用 jjoe64 GraphView 库在我的应用程序中创建条形图 GraphView。
当我创建一个新的 DataPoint 时,它需要 2 个值:X int 和一个 Y int,如下所示:
GraphView graph = (GraphView) findViewById(R.id.graph);
BarGraphSeries<DataPoint> series = new BarGraphSeries<DataPoint>(new DataPoint[] {
new DataPoint(0, -1),
new DataPoint(1, 5),
new DataPoint(2, 3),
new DataPoint(3, 2),
new DataPoint(4, 6)
});
graph.addSeries(series);
如何将底部的 X int 替换为字符串?
编辑#1
你所说的"bottom"是"X-axis"。要标记它,请使用
StaticLabelsFormatter staticLabelsFormatter = new StaticLabelsFormatter(graph);
staticLabelsFormatter.setHorizontalLabels(new String[] {"old", "middle", "new"});
graph.getGridLabelRenderer().setLabelFormatter(staticLabelsFormatter);
进一步阅读:Documentation
或者如果您使用 GraphView 3.x:
graphView.setHorizontalLabels(new String[] {"0.5", "1", "1.5", "2.0"});