Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在graph(django python)中循环[(&x27;A&x27;1),(&x27;B&x27;2),(&x27;C&x27;4)]这种类型的数据?_Python_Django - Fatal编程技术网

如何在graph(django python)中循环[(&x27;A&x27;1),(&x27;B&x27;2),(&x27;C&x27;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',

我希望结果如下代码所示,这里(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',
        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
}