社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Django

在演示图表中添加动态数据。django模板的js文件

Mary • 4 年前 • 2354 次点击  

我正在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公司 文件

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/135341
文章 [ 1 ]  |  最新文章 4 年前