如何在graph(django python)中循环[(&x27;A&x27;1),(&x27;B&x27;2),(&x27;C&x27;4)]这种类型的数据?
我希望结果如下代码所示,这里(A,1)A是标签,1是数据,因此我可以在我的图表中显示它,如果您有任何其他解决方案来显示此数据[('A',1),('B',2),('C',4)],请让我知道如何在graph(django python)中循环[(&x27;A&x27;1),(&x27;B&x27;2),(&x27;C&x27;4)]这种类型的数据?,python,django,Python,Django,我希望结果如下代码所示,这里(A,1)A是标签,1是数据,因此我可以在我的图表中显示它,如果您有任何其他解决方案来显示此数据[('A',1),('B',2),('C',4)],请让我知道 var myChart = new Chart(ctx, { type: 'bar', data: { labels: ["A","B","C"], datasets: [{ label: '# of Votes',
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ["A","B","C"],
datasets: [{
label: '# of Votes',
data: [1,2,4],
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: 2
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
})) 你可以试着使用字典 其中,
Label
是键,Data
是值
yourDict = {
"A": 1,
"B": 2,
"C": 4
}