vish
vish

Reputation: 45

Graphview horizontal labels not scrolling

I am working on project which requires graph drawing. I have used this Library. Its working perfectly only problem i am facing is that, the horizontal labels are not scrolling.This X-axis labels are always fixed. Whereas vertical labels are automatically adjusted when i zoom in and out.

Upvotes: 3

Views: 3181

Answers (1)

user3570982
user3570982

Reputation: 559

It seems that the labels cannot scroll, but they can update to reflect the data in the current viewport; however, this cannot be done with a static horizontal label assignment. For example, the following will not work:

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

Instead, it is necessary to use a CustomLabelFormatter as follows:

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

You can then specify the amount of labels to show and allow scrolling as follows:

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

Hope that helps.

Upvotes: 2

Related Questions