0

I got custom formatter that I found in other thread, that helps with setting strings as horizontal label.

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);

This is my whole code that is handling graphView. I can't find any part that could made that weird doubling of values, but I am using this library for first time and maybe there is some tweaks to fix this.

The problem

It looks like this, when I scroll the graph it still doubling values. There are always 2 same values on screen, no matter where I scroll this.

EDIT: In this screens horizontal labels should be 1, 2, 3, 4, 5 - if it changes anything.

Damian Lesniak
  • 462
  • 2
  • 5
  • 19

1 Answers1

0

First time read this through too quickly. I think what is going on is a simple rounding from conversion of int to double and then back to int. Thus what you think is 1.00000 ends up 0.998 and the int of that is 0. Perhaps first round the value then take int?

TrustNoOne
  • 585
  • 1
  • 5
  • 15