0

我得到了在其他线程中找到的自定义格式化程序,这有助于将字符串设置为水平标签。

GraphViewSeries series = new GraphViewSeries(new GraphView.GraphViewData[] {
                new GraphView.GraphViewData(0, 14d),
                new GraphView.GraphViewData(1, 7d),
                new GraphView.GraphViewData(2, 12d),
                new GraphView.GraphViewData(3, 10d),
                new GraphView.GraphViewData(4, 14d),
                new GraphView.GraphViewData(5, 8d),
                new GraphView.GraphViewData(6, 25d),
                new GraphView.GraphViewData(7, 10d),
                new GraphView.GraphViewData(8, 14d),
                new GraphView.GraphViewData(9, 7d),
                new GraphView.GraphViewData(10, 5d),
        });
    GraphView graphView = new BarGraphView(this, "Demo");

    graphView.addSeries(series);
    horizontalLabels = new String[]{"1", "2", "3", "4", "5", "6",
            "7", "8", "9", "10", "11"};
    graphView.setViewPort(0, 3);
    graphView.setScrollable(true);
    graphView.setManualYAxisBounds(30, 0);
    graphView.getGraphViewStyle().setNumVerticalLabels(6);
    graphView.getGraphViewStyle().setNumHorizontalLabels(5);
    //graphView.getGraphViewStyle().setTextSize();

    graphView.setCustomLabelFormatter(new CustomLabelFormatter() {
        @Override
        public String formatLabel(double value, boolean isValueX) {
            if (isValueX) {
                return horizontalLabels[(int) value];
            } else
                return null;
        }
    });


    LinearLayout layout = (LinearLayout) findViewById(R.id.graph1);
    layout.addView(graphView);

这是我处理graphView的全部代码。我找不到任何可以使值翻倍的部分,但我是第一次使用这个库,也许有一些调整可以解决这个问题。

问题

看起来像这样,当我滚动图表时,它的值仍然加倍。无论我在哪里滚动,屏幕上总是有 2 个相同的值。

编辑:在这个屏幕中,水平标签应该是 1、2、3、4、5 - 如果它改变了任何东西。

4

1 回答 1

0

第一次读这个太快了。我认为正在发生的事情是从 int 转换为 double 然后返回 int 的简单舍入。因此,您认为 1.00000 最终为 0.998,而 int 为 0。也许首先将值舍入,然后取 int?

于 2014-08-11T19:04:45.860 回答