
我需要绘制像我上传的图像一样的图形,我正在使用MP图表库并开发一个图形,但我想根据我的需求自定义它,但无法找到我的需求的解决方案我的基本要求是x轴,我想显示像5-11 12-18轴的自定义数值,但我将值传递给x轴,如下所示
private ArrayList<String> setXAxisValues() {
        ArrayList<String> xVals = new ArrayList<String>();
        xVals.add("10");
        xVals.add("20");
        xVals.add("30");
        xVals.add("30.5");
        xVals.add("40");
        return xVals;
    }所以它显示了x值,像这样的10 20 30等等,所以我希望我的图形是建立在使用这些x值的基础上的,这些x值现在正在发生,但希望在底部显示自定义值,如5-11等,该值是来自Api响应的动态值,因此请帮助我,提前等待积极和早期的响应谢谢
发布于 2018-08-09 22:16:51
要格式化x轴值,您应该使用setValueFormatter方法,该方法需要一个回调接口,因为您必须实现在绘制x轴值之前调用的getFormattedValue方法。
xAxis.setValueFormatter((value, axis) -> {
        String res = "";
        try {
            // get current position of x-axis
            int currentPosition = (int) value;
            // check if position between array bounds
            if (currentPosition > -1 && currentPosition < maxSize) {
               // get value from formatted values array
               res = xVals.get(currentPosition);
            }
        } catch (Exception e) {
            // handle exception
        }
        return res;
    });https://stackoverflow.com/questions/51768689
复制相似问题