我希望将格式1555596901
设置为可读的日期,例如 2019/04/19 11h52。这是代码:
am4core.useTheme(am4themes_animated);
function createChart(htmlElement){
var chart = am4core.create(htmlElement, am4charts.XYChart);
chart.dateFormatter.dateFormat = "dd/MM/yyyy";
chart.data = [
{
category: "1555596901",
value1: 1,
value2: 5,
value3: 3,
value4: 3
},
{
category: "1555611301",
value1: 10,
value2: 8,
value3: 6,
value4: 4
}
];
chart.cursor = new am4charts.XYCursor();
chart.colors.step = 2;
var categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = "category";
categoryAxis.renderer.grid.template.location = 0;
categoryAxis.dateFormatter.dateFormat = "dd/MM/yyyy";
var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
valueAxis.min = 0;
valueAxis.renderer.minWidth = 35;
var series1 = chart.series.push(new am4charts.ColumnSeries());
series1.columns.template.width = am4core.percent(80);
series1.columns.template.tooltipText = "{name}: {valueY.value}";
series1.name = "Series 1";
series1.dataFields.categoryX = "category";
series1.dataFields.valueY = "value1";
series1.stacked = true;
series1.dateFormatter.dateFormat = "dd/MM/yyyy";
var series2 = chart.series.push(new am4charts.ColumnSeries());
series2.columns.template.width = am4core.percent(80);
series2.columns.template.tooltipText = "{name}: {valueY.value}";
series2.name = "Series 2";
series2.dataFields.categoryX = "category";
series2.dataFields.valueY = "value2";
series2.stacked = true;
series2.dateFormatter.dateFormat = "dd/MM/yyyy";
var series3 = chart.series.push(new am4charts.ColumnSeries());
series3.columns.template.width = am4core.percent(80);
series3.columns.template.tooltipText = "{name}: {valueY.value}";
series3.name = "Series 3";
series3.dataFields.categoryX = "category";
series3.dataFields.valueY = "value3";
series3.stacked = true;
series3.dateFormatter.dateFormat = "dd/MM/yyyy";
var series4 = chart.series.push(new am4charts.ColumnSeries());
series4.columns.template.width = am4core.percent(80);
series4.columns.template.tooltipText = "{name}: {valueY.value}";
series4.name = "Series 4";
series4.dataFields.categoryX = "category";
series4.dataFields.valueY = "value4";
series4.stacked = true;
series4.dateFormatter.dateFormat = "dd/MM/yyyy";
return chart;
}
let chart1 = createChart("chartdiv");
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}
#chartdiv {
width: 100%;
height: 300px;
}
<script src="//www.amcharts.com/lib/4/core.js"></script>
<script src="//www.amcharts.com/lib/4/charts.js"></script>
<script src="//www.amcharts.com/lib/4/themes/animated.js"></script>
<div id="chartdiv"></div>
如您所见,它没有格式化时间戳。我在需要chart.dateFormatter.dateFormat = "dd/MM/yyyy";
用于格式化的文档中看到。