Android使用条形图视图字母

问题描述 投票:1回答:1

我有一个程序android使用图表视图,但默认标签图表视图使用int数字,如1,2或3.我想将标签从1,2,3改为A,B,C水平标签像这样http://prntscr.com/bwxclx

我的代码是这样的

GraphView bar_graph = (GraphView) findViewById(R.id.graph);
    BarGraphSeries<DataPoint> bar_series = new BarGraphSeries<DataPoint>(new DataPoint[] {
            new DataPoint(0, 0),
            new DataPoint(1, 7), // 1st war
            new DataPoint(1.5, 0),
            new DataPoint(2, 5), // 2nd war
            new DataPoint(2.5, 0),
            new DataPoint(3, 8), // 3rd war
            new DataPoint(3.5, 0),
            new DataPoint(4, 0)
    });

任何人都可以帮助我如何将标签1,2,3更改为A,B,C

android graph
1个回答
0
投票

您可以使用StaticLabelsFormatter()静态设置标签。

在我的情况下,“plotArrayX”是一个包含我想要的值的数组。它们可以是文本,数字或空。

我用它来生成设置的时间戳。

下面的代码是kotlin,但它与java非常相似。

val staticLabelsFormatter = StaticLabelsFormatter(graph)
staticLabelsFormatter.setHorizontalLabels(plotArrayX)
graph.getGridLabelRenderer().setLabelFormatter(staticLabelsFormatter)

我的实际X轴数据点只是一个增量整数。然后在最终视图中自动与标签交换标签。

© www.soinside.com 2019 - 2024. All rights reserved.