【问题标题】:How to set label the for the x-axis?如何为 x 轴设置标签?
【发布时间】:2017-02-08 03:59:36
【问题描述】:

如何为xAxis 设置标签?在左侧,它当前具有标签“数量”。如何以编程方式添加它?

【问题讨论】:

  • 这个问题已经有社区 wiki 回答 here

标签: mpandroidchart


【解决方案1】:

根据您的喜好,您可以使用 Entry 的 data 属性来存储标签,然后在您的 IAxisValueFormatter 实现中返回它:

public class LabelValueFormatter implements IAxisValueFormatter { 

     private final DataSet mData;

public LabelValueFormatter(DataSet data) {
     mData = data;
} 

@Override 
public String getFormattedValue(float value, AxisBase axis) {
    // return the entry's data which represents the label 
    return (String) mData.getEntryForXPos(value, DataSet.Rounding.CLOSEST).getData();
 } 
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-20
    • 2017-09-04
    • 2019-10-29
    • 1970-01-01
    相关资源
    最近更新 更多