首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >MpAndroidChart值格式化程序xAxis出现问题

MpAndroidChart值格式化程序xAxis出现问题
EN

Stack Overflow用户
提问于 2020-06-11 20:38:39
回答 2查看 54关注 0票数 0

我的工作是将浮点数据转换为日期格式的字符串数据。

例如200611是20/06/11,9610604是96/06/04

我写了代码,但它没有给出预期的结果

我在互联网上搜索了一下,但只找到了旧版本的代码

我的版本是3.1.0

以下是我的代码

代码语言:javascript
运行
复制
xAxis.setValueFormatter(new ValueFormatter(){

        public String getFormatterValue(int value) throws ParseException {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yy/MM/dd");
            Date date = simpleDateFormat.parse(Integer.toString(value));

            SimpleDateFormat newFormat = new SimpleDateFormat("yy/MM/dd");
            String dateString = newFormat.format(date);
            return dateString;
        }

    });
EN

回答 2

Stack Overflow用户

发布于 2020-06-11 20:43:28

看起来您需要先使用yyMMdd格式(而不是yy/MM/dd)进行解析,然后使用yy/MM/dd进行格式化。

票数 0
EN

Stack Overflow用户

发布于 2020-07-07 17:06:11

这是我在我的项目中用来将Float值格式化为String类型的时间。您需要为XAxisValueFormatter创建一个单独的类,并在其中进行转换。

代码语言:javascript
运行
复制
class XAxisValueFormatter: ValueFormatter() {
  override fun getAxisLabel(value: Float, axis: AxisBase?): String {

       var formatter = DateTimeFormatter.ofPattern("dd-yyyy-MM")

       var formattedDate = value.format(formatter)
       return formattedDate
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62324611

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档