Graphview水平标签不滚动

时间:2014-05-15 05:07:31

标签: android label android-graphview

我正在处理需要图形绘制的项目。我使用过this库。它完全唯一能解决的问题是,水平标签不会滚动。这个X轴标签总是固定的。而我放大和缩小时会自动调整垂直标签。

1 个答案:

答案 0 :(得分:2)

标签似乎无法滚动,但它们可以更新以反映当前视口中的数据;但是,使用静态水平标签分配无法做到这一点。例如,以下内容不起作用:

horizontalLables = new String[] {"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"};
graphView.setHorizontalLabels(horizontalLables);

相反,有必要使用CustomLabelFormatter,如下所示:

graphView.setCustomLabelFormatter(new CustomLabelFormatter() {
    @Override
    public String formatLabel(double value, boolean isValueX) {
        if (isValueX) {
            // Assuming only 7 total values here
            return horizontalLables[(int) value];
        } else
            return String.format("%.2f", value);
    }
});

然后,您可以指定要显示的标签数量并允许滚动,如下所示:

graphView.getGraphViewStyle().setNumHorizontalLabels(4);
graphView.setViewPort(0, 3);
graphView.setScrollable(true);

希望有所帮助。