【问题标题】:Dateformat with category axis amcharts4日期格式与类别轴 amcharts 4
【发布时间】:2018-11-14 16:04:24
【问题描述】:

dateformat 属性在 amcharts4 中不起作用。

我了解 dateformat 是从父元素继承的,我尝试在图表级别、轴级别和系列级别设置 dateformat。

 chart.dateFormatter.dateFormat = "dd/MM/yyyy";

请看下面的codepen:

https://codepen.io/alex-wells/pen/vQmWBz

【问题讨论】:

  • 那个codepen是你的代码吗?
  • @Aroon 我已经更新了 codepen 示例,我想我可能在创建问题时出错了。
  • 日期是来自 json 还是您手动?如果是 json 你应该从 json 文件结尾更改日期格式
  • 我可以在发送到 amcharts 之前格式化日期,但我的意图是传递数据并使用 dateformatter 类来配置格式

标签: typescript amcharts


【解决方案1】:

@martynasma 在 github 上引用

您正在使用 CategoryAxis。该轴将所有类别视为 文本,因此没有应用格式。

如果你需要正确的日期轴,你需要使用 DateAxis,以及使用 系列数据字段的 dateX:

var dateAxis = chart.xAxes.push(new am4charts.DateAxis());

....

series1.dataFields.dateX = "category";
series1.dataFields.valueY = "value1";

现在,为 DateAxis 设置格式并不像 设置日期格式。这种轴类型有多个层次 粒度,所以你需要为你的目标设置一个。在你的情况下 一天。

dateAxis.dateFormats.setKey("day", "dd/MM/yyyy");
dateAxis.periodChangeDateFormats.setKey("day", "dd/MM/yyyy");

更多信息:

https://www.amcharts.com/docs/v4/reference/dateaxis/#dateFormats_property https://www.amcharts.com/docs/v4/reference/dateaxis/#periodChangeDateFormats_property

这是你的笔按上述更新:

https://codepen.io/team/amcharts/pen/pQPQdN?editors=0010

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多