我正在使用列表创建图形:
list: [[7, 8, 9, 6, 5], [8, 8.8, 7.9, 9, 5]]
例如:长度为2的列表,并且列表是动态生成的,长度可以为2或更大。
以及如何使用动态列表绘制图形。
var ctx = document.getElementById('radar-chart');
var arr = {{ rating }};
var lab = '{{ brand_name }}';
console.log(lab);
Chart.defaults.global.defaultFontColor = '#000';
new Chart(ctx, {
type: 'radar',
data: {
labels: ["Design", "Performance", "Camera", "Connectivity", "Battery"],
datasets: [
{
label: "{{ brand_name.0 }}",
fill: true,
backgroundColor: "rgba(179,181,198,0.2)",
borderColor: "rgba(179,181,198,1)",
pointBorderColor: "#fff",
pointBackgroundColor: "rgba(179,181,198,1)",
data: list[0]
}, {
label: "{{ brand_name.1 }}",
fill: true,
backgroundColor: "rgba(255,99,132,0.2)",
borderColor: "rgba(255,99,132,1)",
pointBorderColor: "#fff",
pointBackgroundColor: "rgba(255,99,132,1)",
pointBorderColor: "#fff",
data: list[1]
},
]
},
options: {
responsive: true,
maintainAspectRatio: false,
responsiveAnimationDuration: 1
},
legend:
{
labels:{
color: '#000'
}
},
layout:{
height: 200,
padding:{
left: 50,
right: 0,
bottom: 0,
top: 0
}
}
});