【发布时间】:2014-07-10 20:01:32
【问题描述】:
我正在使用 django 1.6 和 python2.7
我正在尝试使用 chartit,但没有收到任何显示。
我在 settings.py 中将 chartit 添加到 install_apps
我试图尽可能地简化我的代码,但仍然没有加载
urls.py
url(r"^chart/$", "carriermgr.views.ChartLs"),
Views.py
def ChartLs(request, template_name='carrier/carrierchart.html'):
thedata = \
DataPool(
series=
[{'options': {
'source': CarrierSnapshot.objects.all()},
'terms': [
'dbaname',
'VServiceUS',
'VSvcPercUS']}
])
cht = Chart(
datasource = thedata,
series_options =
[{'options':{
'type': 'column',
'stacking': False},
'terms':{
'dbaname': [
'VServiceUS',
'VSvcPercUS']
}}],
chart_options =
{'title': {
'text': 'Out of Service compared to National Average'},
'xAxis': {
'title': {
'text': 'carrier'}}})
return render_to_response(template_name, {'NATAVGchart':cht})
carrierchart.html
<html>
<head>
<script src ="http://code.highcharts.com/highcharts.js"></script>
<script src ="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
{% load chartit %}
{{ NATAVGchart|load_charts:"container"}}
</head>
<body>
<div id=”container”>
</div>
</body>
</html>
在检查元素期间,我可以看到从视图中加载的正确数据。所以我假设它可以正常访问模型。
检查元素
页面加载没有错误。 Jquery、Highchart 和 Chartloader 都在加载中。
<script type="text/javascript">
var _chartit_hco_array = [{"series": [{"stacking": false, "data": [0, 136], "type": "line", "name": "Vserviceus"}, {"stacking": false, "data": [0.00, 6.00], "type": "line", "name": "Vsvcpercus"}], "yAxis": [{"title": {"text": "Vserviceus & Vsvcpercus"}}], "chart": {"renderTo": "container"}, "xAxis": [{"categories": ["carrier1", " carrier2"], "title": {"text": "carrier"}}], "title": {"text": "National Average"}}];
</script>
任何指导表示赞赏! 谢谢
【问题讨论】:
-
您需要在 before highcharts 之前包含
jquery.js文件 -
仍然返回空白屏幕。我在检查元素期间看到了一个新项目...(我现在在另一台计算机上,不确定是否是版本差异)
<object type="{0C55C096-0F1D-4F28-AAA2-85EF591126E7}" cotype="cs" id="cosymantecbfw" style="width: 100%; height: 0px; display: block; position: absolute; z-index:99999; top:0px; left:0px;"></object> -
您在控制台中收到任何错误吗?
标签: jquery python django highcharts