为啥我的代码执行不了,刷新不了动态数据(后台数据库更改数据)

代码执行后发现并不能从后台获取最新数据,第一次编写请问哪里出了问题呢?
先前尝试使用alert,有弹出提醒,但在后台修改数据库中的data内容后,并不能刷新出来最新数据,手动刷新才能实现,

 <script type="text/javascript">
      function getData() {
          var myChart = echarts.init(document.getElementById('main'));
          var option = {
              title: {
                  text: '大网地址使用率'
              },
              tooltip: {},
              toolbox: {
                  show: true,
                  feature: {
                      dataView: {show: true, readOnly: false},
                      magicType: {show: true, type: ['line', 'bar']},
                      restore: {show: true},
                      saveAsImage: {show: true}
                  }
              },
              calculable: true,
              legend: {
                  data: ['分配率', '可达率']
              },
              xAxis: {
                  data: [
                      {% for obj in sgateway %}
                        '{{ obj.sgateway}}',
                      {% endfor %}
                        ]
      },
          yAxis:{
          }
      ,
          series:[
              {
                  name: '分配率',
                  type: 'bar',
                  data: [
                      {% for stu in allot_total %}
                        {{stu}},
                      {% endfor %}
      ],
          markPoint: {
              data: [
                  {type: 'max', name: '最大值'},
                  {type: 'min', name: '最小值'}
              ]
          }
      },
          {
              name:'可达率',
              type:'bar',
              data:
              [
                  {% for stu in online_total %}
              {{stu}},
              {% endfor %}
          ],
              markPoint: {
                  data: [
                      {type: 'max', name: '最大值'},
                      {type: 'min', name: '最小值'}
                  ]
              }
          }]
      };
          myChart.setOption(option);
      }
      setInterval(function () {
          getData();
      },500);
*view.py*
from django.db.models import Count,Sum
def echart(request):

    result1=Students.objects.aggregate(ip_num=Count('sip'))
    print(result1['ip_num'])
    aaa=[]
    bbb=[]
    result = Students.objects.values('sgateway').distinct()
    for obj in result:
        ss=obj['sgateway']
        result2 = Students.objects.filter(sgateway=ss).aggregate(count1=Sum('sallot'))
        result3=Students.objects.filter(sgateway=ss).aggregate(count2=Sum('sonline'))
        for i in result2.values():
            #print(i)
            aaa.append(i)
        for s in result3.values():
            #print(s)
            bbb.append(s)
    return render(request,'myApp/echart.html',{'sgateway':result,
                                               'allot_total':aaa,'online_total':bbb})

你可能感兴趣的:(为啥我的代码执行不了,刷新不了动态数据(后台数据库更改数据))