我有一个过去 30 天的数组,每天有 2 个键:
-日期(日期时间)
-计数(整数)
我尝试使用 Xaxis 中的日期和 Yaxis 中的 count
实例化 google 图表,但是当我尝试使用 twig 循环数组时,我的日期时间值似乎发生了更改。
这是我在 drawGraph()
函数中循环在图表上添加行的方法:
function drawChart() {
var dataTable = new google.visualization.DataTable();
dataTable.addColumn({ type: 'date', id: 'date', label: 'date'});
dataTable.addColumn({ type: 'number', id: 'Nombre d OF', label: 'Nb of'});
{% for value in chartData.data %}
console.log({{ value.date.format('Y-m-d') }});
dataTable.addRow([new Date("{{ value.date.format('Y-m-d')| date("Y-m-d") }}".replace(/-/g,"/")), {{ value.count }}]);
{% endfor %}
var options = {
title: 'Nombre d\'ordre de fabrication crées sur les 30 derniers jours ('+{{ chartData.info }}+')',
hAxis: {title: 'Jours', titleTextStyle: {color: '#333'}},
vAxis: {minValue: 0}
};
var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
chart.draw(dataTable, options);
}
我打印了每次循环迭代的日期,得到了这个结果:
我的问题是:为什么我的循环中的日期发生了变化?
最佳答案
好吧,2017 - 9 - 24
实际上是 1984
,您需要用引号将您的语句括起来,否则它将被视为子分支
console.log('{{ value.date.format('Y-m-d') }}');
关于javascript - 使用 twig 日期时间中的日期实现 googlechart x 轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46364666/