【问题标题】:how to set values for xlabels and ylabels in mpandroidchart如何在 mpandroidchart 中设置 x 标签和标签的值
【发布时间】:2014-11-21 12:49:20
【问题描述】:

我正在使用 mpandroidchart android 库。我正在实施折线图。在这里我可以自己设置 x 和 y 标签吗?目前它正在根据提供给图表的数据集添加值。能不能给点意见?

【问题讨论】:

    标签: android mpandroidchart


    【解决方案1】:

    您必须在轴对象上使用格式化程序。

    有两种格式化程序 XAxisValueFormatter 和 YAxisValueFormatter。

    这是我用来更改带后缀“h”的 X 标签编号的代码:

    //get reference on chart line view
    LineChart chart = (LineChart) pActivity.findViewById(R.id.chart);
    //set formater for x Label
    chart.getXAxis().setValueFormatter(new XAxisValueFormatter() {
    
            @Override
            public String getXValue(String original, int index, ViewPortHandler viewPortHandler) {
                //return number + "h" here
                // but you can do everything you want here. The string returned will be displayed on chart x label
                return original + "h";
            }
        });
    //axis to the bottom
    chart.getXAxis().setPosition(XAxisPosition.BOTTOM);
    //populate with data
    chart.setData(data);
    // refresh
    chart.invalidate();
    

    【讨论】:

      【解决方案2】:

      你能说得更具体点吗?对于 x-labels,您可以在您提供的数据对象中设置您想要的任何内容。对于 y 标签,请调用 setYRange(...) 设置要显示的固定值范围。

      【讨论】:

      • 嗨,实际上我正在寻找设置范围和格式。我使用了对我有用的值格式化程序。
      • 但是现在我想知道折线图中间是否可以有空值?比如说我有一个 10 x vals 和 10 yvals 的数据集。现在在 yval 中,我想将其设为 null,这意味着相同的 xval 将存在但没有 yval。折线图中不会有点。这可能吗?
      • 我认为这是一个后续问题:菲尔,我怎样才能显示更多的 XLabel,例如让它们更密集?我试过设置 getXLabels().setSpaceBetweenLabels(1);但它似乎并没有改变间距。最好的问候
      猜你喜欢
      • 1970-01-01
      • 2015-04-22
      • 2017-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-06
      • 2021-12-01
      • 2022-11-25
      相关资源
      最近更新 更多