Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/468.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.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
Javascript 使用chartit在Django中显示图表时出错_Javascript_Jquery_Python_Django_Highcharts - Fatal编程技术网

Javascript 使用chartit在Django中显示图表时出错

Javascript 使用chartit在Django中显示图表时出错,javascript,jquery,python,django,highcharts,Javascript,Jquery,Python,Django,Highcharts,我有一个申请,我正试图显示每个国家的提案数量的简单图表。如前所述,我正在图表中使用数据透视图 我有一个这样的模型 class Proposal(models.Model): org = models.CharField(max_length=200) country = models.CharField(max_length=100) recdate = models.DateField(blank=False) subdate = models.DateField(blank=False) s

我有一个申请,我正试图显示每个国家的提案数量的简单图表。如前所述,我正在图表中使用数据透视图

我有一个这样的模型

class Proposal(models.Model):
org = models.CharField(max_length=200)
country = models.CharField(max_length=100)
recdate = models.DateField(blank=False)
subdate = models.DateField(blank=False)
status = models.CharField(choices = stat_val, max_length=20)
<!DOCTYPE html>

<html>
<head>
    {% load staticfiles %}
    {% load static %}
    <link rel="stylesheet" href="{% static 'bootstrap/css/bootstrap.min.css' %}" >
    <link rel="stylesheet" href="{% static 'bootstrap/css/light-bootstrap-dashboard.css' %}" >
<link rel="stylesheet" href="{% static 'bootstrap/css/animate.min.css' %}">
    <link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
    <link href='http://fonts.googleapis.com/css?family=Roboto:400,700,300' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="{% static 'bootstrap/css/pe-icon-7-stroke.css' %}">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
    <script src="{{ MEDIA_URL }}highcharts/js/highcharts.js" type="text/javascript"></script>
    {% load chartit %}
    {{ rainpivchart|load_charts:"container" }}
</head>
<body>
    {% include "proposal/main-banner.html"%}
<div id='container'></div>
<a href = "{% url 'list' %}" style="float: center; color: black;"><button>Back to Proposal List</button></a>
</body>
</html> 
正如chartit GitHub中所解释的,我已经将其添加到视图中

from django.db.models import Count
from chartit import PivotDataPool, PivotChart
from django.shortcuts import render_to_response

def proposal_pivot_chart_view(request):
# Step 1: Create a PivotDataPool with the data we want to retrieve.
proposalpivotdata = PivotDataPool(
    series=[{
        'options': {
            'source': Proposal.objects.all(),
            'categories': ['country'],
        },
        'terms': {
            'countprop': Count('id'),
        }
    }]
)

# Step 2: Create the PivotChart object
chart1 = PivotChart(
    datasource=proposalpivotdata,
    series_options=[{
        'options': {
            'type': 'column',
            'stacking': True
        },
        'terms': ['countprop']
    }],
    chart_options={
        'title': {
            'text': 'Proposals by Countries'
        },
        'xAxis': {
            'title': {
                'text': 'Country'
            }
        }
    }
)

# Step 3: Send the PivotChart object to the template.
return render_to_response({'chart1': chart1})
我创建了一个这样的模板

class Proposal(models.Model):
org = models.CharField(max_length=200)
country = models.CharField(max_length=100)
recdate = models.DateField(blank=False)
subdate = models.DateField(blank=False)
status = models.CharField(choices = stat_val, max_length=20)
<!DOCTYPE html>

<html>
<head>
    {% load staticfiles %}
    {% load static %}
    <link rel="stylesheet" href="{% static 'bootstrap/css/bootstrap.min.css' %}" >
    <link rel="stylesheet" href="{% static 'bootstrap/css/light-bootstrap-dashboard.css' %}" >
<link rel="stylesheet" href="{% static 'bootstrap/css/animate.min.css' %}">
    <link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
    <link href='http://fonts.googleapis.com/css?family=Roboto:400,700,300' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="{% static 'bootstrap/css/pe-icon-7-stroke.css' %}">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
    <script src="{{ MEDIA_URL }}highcharts/js/highcharts.js" type="text/javascript"></script>
    {% load chartit %}
    {{ rainpivchart|load_charts:"container" }}
</head>
<body>
    {% include "proposal/main-banner.html"%}
<div id='container'></div>
<a href = "{% url 'list' %}" style="float: center; color: black;"><button>Back to Proposal List</button></a>
</body>
</html> 

{%load staticfiles%}
{%load static%}
{%load chartit%}
{{rainpivchart}装载图表:“集装箱”}
{%include“proposal/main banner.html”%}
但有一些问题,我得到了错误

TemplateDoesNotExist at /chart1/
{'chart1': <chartit.charts.PivotChart object at 0x046ADF30>}
Request Method:
GET
Request URL:
http://127.0.0.1:8000/chart1/
Django Version:
1.10.6
Exception Type:
TemplateDoesNotExist
Exception Value:
{'chart1': <chartit.charts.PivotChart object at 0x046ADF30>}
Exception Location:
C:\Users\Parag\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-1.10.6-py3.6.egg\django\template\loader.py in get_template, line 25
Python Executable:
C:\Users\Parag\AppData\Local\Programs\Python\Python36-32\python.exe
Python Version:
3.6.0
Python Path:
['C:\\Users\\Parag\\AppData\\Local\\Programs\\Python\\Python36-32\\Lib\\site-packages\\Django-1.10.6-py3.6.egg\\django\\bin\\myoffice',
 'C:\\Users\\Parag\\AppData\\Local\\Programs\\Python\\Python36-32\\python36.zip',
 'C:\\Users\\Parag\\AppData\\Local\\Programs\\Python\\Python36-32\\DLLs',
 'C:\\Users\\Parag\\AppData\\Local\\Programs\\Python\\Python36-32\\lib',
 'C:\\Users\\Parag\\AppData\\Local\\Programs\\Python\\Python36-32',
 'C:\\Users\\Parag\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site-packages',
 'C:\\Users\\Parag\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site-packages\\django-1.10.6-py3.6.egg']
Server time:
Tue, 18 Apr 2017 16:09:08 +0400
Template-loader postmortem
Django tried loading these templates, in this order:
Using engine django:
django.template.loaders.app_directories.Loader: C:\Users\Parag\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-1.10.6-py3.6.egg\django\contrib\admin\templates\{'chart1': <chartit.charts.PivotChart object at 0x046ADF30>} (Source does not exist)
django.template.loaders.app_directories.Loader: C:\Users\Parag\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-1.10.6-py3.6.egg\django\contrib\auth\templates\{'chart1': <chartit.charts.PivotChart object at 0x046ADF30>} (Source does not exist)
django.template.loaders.app_directories.Loader: C:\Users\Parag\AppData\Local\Programs\Python\Python36-32\lib\site-packages\highcharts\templates\{'chart1': <chartit.charts.PivotChart object at 0x046ADF30>} (Source does not exist)
templateDoesnotexistat/chart1/
{'chart1':}
请求方法:
得到
请求URL:
http://127.0.0.1:8000/chart1/
Django版本:
1.10.6
异常类型:
TemplateDoesNotExist
异常值:
{'chart1':}
异常位置:
C:\Users\Parag\AppData\Local\Programs\Python\Python36-32\lib\site packages\django-1.10.6-py3.6.egg\django\template\loader.py,在get\u模板的第25行
Python可执行文件:
C:\Users\Parag\AppData\Local\Programs\Python\Python36-32\Python.exe
Python版本:
3.6.0
Python路径:
['C:\\Users\\Parag\\AppData\\Local\\Programs\\Python\\Python36-32\\Lib\\site packages\\Django-1.10.6-py3.6.egg\\Django\\bin\\myoffice',
'C:\\Users\\Parag\\AppData\\Local\\Programs\\Python\\Python36-32\\Python36.zip',
'C:\\Users\\Parag\\AppData\\Local\\Programs\\Python\\Python36-32\\DLLs',
'C:\\Users\\Parag\\AppData\\Local\\Programs\\Python\\Python36-32\\lib',
'C:\\Users\\Parag\\AppData\\Local\\Programs\\Python\\Python36-32',
'C:\\Users\\Parag\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site packages',
'C:\\Users\\Parag\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site packages\\django-1.10.6-py3.6.egg']
服务器时间:
2017年4月18日星期二16:09:08+0400
模板加载程序后期处理
Django尝试按以下顺序加载这些模板:
使用引擎django:
django.template.loaders.app_directories.Loader:C:\Users\Parag\AppData\Local\Programs\Python36-32\lib\site packages\django-1.10.6-py3.6.egg\django\contrib\admin\templates\{'chart1':}(源代码不存在)
django.template.loaders.app_directories.Loader:C:\Users\Parag\AppData\Local\Programs\Python\Python36-32\lib\site packages\django-1.10.6-py3.6.egg\django\contrib\auth\templates\{'chart1':}(源代码不存在)
django.template.loaders.app_directories.Loader:C:\Users\Parag\AppData\Local\Programs\Python\Python36-32\lib\site packages\highcharts\templates\{'chart1':}(源代码不存在)

我尝试像这样更改渲染行
将渲染返回到响应('proposition/chart1',{chart1})
但仍然得到相同的错误。在模板中,Django正在显示Django.template.loaders.app\u目录。Loader:C:\Users\Parag\AppData\Local\Programs\Python36-32\lib\site packages\Django-1.10.6-py3.6.egg\Django\contrib\admin\templates\proposal\chart1(源代码不存在)但是chart1.html模板文件位于相同的位置我尝试过像这样更改渲染行
返回render\u to\u response('proposition/chart1',{chart1})
,但仍然得到相同的错误。在模板中,Django正在显示Django.template.loaders.app_directories.Loader:C:\Users\Parag\AppData\Local\Programs\Python36-32\lib\site packages\Django-1.10.6-py3.6.egg\Django\contrib\admin\templates\proposal\chart1(源代码不存在),但chart1.html模板文件位于同一位置