【问题标题】:MPAndroid Chart by DateMPAndroid 图表按日期
【发布时间】:2019-01-22 16:36:55
【问题描述】:

我有一个包含级别(y 轴)、类型(颜色)和日期(x 轴)的日期对象。

我知道我可以使用 MPAndroidChart 创建一个grouped barchart,但是如何更改 x 值以显示日期?

【问题讨论】:

  • 您的链接,页面几行,有一个IAxisValueFormatter 示例。这应该会有所帮助

标签: android mpandroidchart


【解决方案1】:

像这样使用 IAxisValueFormatter:

public class MyYAxisValueFormatter implements IAxisValueFormatter {

    private SimpleDateFormat mFormat;

    public MyAxisValueFormatter() {

        // format values to 1 decimal digit
        mFormat = new SimpleDateFormat("MMM dd");
    }

    @Override
    public String getFormattedValue(float value, AxisBase axis) {
        // "value" represents the position of the label on the axis (x or y)
        return mFormat.format(value);
    }

    /** this is only needed if numbers are returned, else return 0 */
    @Override
    public int getDecimalDigits() { return 0; }
}

【讨论】:

    猜你喜欢
    • 2016-06-23
    • 2016-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-13
    相关资源
    最近更新 更多