带分类轴的日期格式 amcharts4

Dateformat with category axis amcharts4

日期格式 属性 在 amcharts4 中不起作用。

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

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

请参阅下面的codepen:

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

引自@martynasma github

You are using CategoryAxis. This axis treats all of the categories as text, hence no formatting applied.

If you need proper date axis, you need to use DateAxis, as well as use dateX for series' dataFields:

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

....

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

Now, setting format for the DateAxis is not as straightforward as setting dateFormat. This axis type have multiple levels of granularity, so you need to set for your target one. In your case it's a day.

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

More info:

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

And here's your pen updated as per above:

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