我正在Django项目中使用“start bootstrap4”模板。我想在示例图表中编辑我自己的数据。我需要在
chart-pie-demo.js
文件
我已经创建了要添加到图表中的数据列表。数据在我的
views.py
:
def chart(request):
sheet2022 = client.open('sheet 2022')
instance = sheet2022.get_worksheet(0)
mysheet = instance.get_all_records()
rpending2022 = list(filter(lambda datapending2022:
Mi=len(tuple(d for d in rpending2022 if d['Receiver'] == 'Mike'))
Lu=len(tuple(d for d in rpending2022 if d['Receiver'] == 'Lucy'))
Ja=len(tuple(d for d in rpending2022 if d['Receiver'] == 'Jack'))
mydata = [Mi, Lu, Ja]
context = {'mydata': mydata}
return render(request,'charts.html', context)
我的
图表饼图演示。js公司
文件:
var ctx = document.getElementById("myPieChart");
var myPieChart = new Chart(ctx, {
type: 'doughnut',
data: {
labels: ["Direct", "Referral", "Social"],
datasets: [{
data: [55, 30, 15],
backgroundColor: ['#4e73df', '#1cc88a', '#36b9cc'],
hoverBackgroundColor: ['#2e59d9', '#17a673', '#2c9faf'],
hoverBorderColor: "rgba(234, 236, 244, 1)",
}],
},
options: {
maintainAspectRatio: false,
tooltips: {
backgroundColor: "rgb(255,255,255)",
bodyFontColor: "#858796",
borderColor: '#dddfeb',
borderWidth: 1,
xPadding: 15,
yPadding: 15,
displayColors: false,
caretPadding: 10,
},
legend: {
display: false
},
cutoutPercentage: 80,
},
});
我想用我自己的数据替换示例数据:[55、30、15]
mydata
. 当我在我的
图表饼图演示。js公司
文件,图表不会显示。是否需要在中链接数据位置
图表饼图演示。js公司
文件