I am trying to get my labels in my chart to appear based on my query on the back end.
(我正在尝试根据后端查询在图表中显示标签。)
This is what my javascript looks like right now.(这就是我的JavaScript现在的样子。)
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ['C00891', 'C01013', 'C00364', 'A00152', 'C00985'],
datasets: [{
label: 'Top 5 Dealerships By Earn',
data: [{% for key, value in info %}{% if not loop.first %},{% endif %}{{ value['total']|e }} {% endfor %}],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
My data: loop works and I am able to pass in my twig variable and update the data.
(我的数据:循环有效,我可以传入我的树枝变量并更新数据。)
When I try to do this with the label(当我尝试使用标签进行此操作时)
label: {% for value in info %}{{ value['d_id']|e }} {% endfor %}
My chart does not load.
(我的图表未加载。)
id like to be able to pass in my variable to my twig template dynamically as well, just like the data.
(id也希望能够像数据一样将变量动态地传递给我的树枝模板。)
Any ideas?
(有任何想法吗?)
My twig variable is set like this and it passes the data from my php (symfony) controller
(我的树枝变量设置如下,它从我的php(symfony)控制器传递数据)
{% set info = data %}
ask by jesus2kus translate from so