我在django中显示高图时遇到问题。我正在使用twitter bootstrap.Chart没有在chart.html中显示。任何人都可以帮助我,我在这里做错了吗?请找到以下版本的django
的Django == 1.8.7
django-highcharts == 0.1.7
base.html:
<!DOCTYPE html>
{% load staticfiles %}
<html>
<head>
{% block title %}<title>mbr page </title>{% endblock %}
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="{% static "mbr/css/boostrap-fluid-adj.css" %}" rel="stylesheet">
<link href="{% static "mbr/css/bootstrap.min.css" %}" rel="stylesheet" media="screen">
<link href="{% static "mbr/css/bootstrap-responsive.css" %}" rel="stylesheet">
<style>
body {
padding-top: 50px;
}
@media (max-width: 980px) {
body {
padding-top: 0;
}
}
</style>
</head
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container-fluid">
<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="nav-collapse collapse">
<ul class="nav pull-right">
<li><a href="/admin/">Login</a></li>
</ul>
<ul class="nav navbar-nav">
<li class="active"><a href="/mbr/">Home</a></li>
<li><a href="{% url 'search_form' %}">Search s</a></li>
<li><a href="{% url 'results_list' %}">Results History</a></li>
<li><a href="{% url 'chart_test' %}">Statistics</a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row-fluid">
<div class="span3">
<div class="well sidebar-nav">
<h3> Name</h3>
<p class="active"><a href="/mbr/4/">TEST1</a></p>
<p><a href="/mbr/3/">TEST2</a></p>
<p><a href="/mbr/2/">TEST3</a></p>
<p><a href="/mbr/1/">TEST4</a></p>
</div>
</div>
<div class="span9">
{% block content %}
{% endblock %}
</div>
</div>
</div>
<hr>
<script src="{% static 'mbr/js/jquery-3.2.0.js' %}"></script>
<script src="{% static 'mbr/js/bootstrap.min.js' %}"></script>
</body>
</html>
chart_test.html:
{% extends "base.html" %}
{% load staticfiles %}
{% block content %}
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<!--<script src="{% static "js/jquery.min.js" %}"></script>-->
<!--<script src="{% static "js/highcharts.js" %}"></script>-->
</head>
<body>
<script type="text/javascript">
$(function () {
$('#chart_container').highcharts({
chart: {
type: 'bar'
},
title: {
text: 'Monthly Sales'
},
xAxis: {
categories: ['Jan','Feb','Mar','Apr']
},
yAxis: {
title: {
text: 'numbers'
}
},
series: [{
name: 'John',
data: [1, 0, 4]
}, {
name: 'King',
data: [5, 7, 3]
}]
});
});
</script>
<div id="chart_container" style="height: 300px"></div>
</body>
</html>
{% endblock %}
视图:
def chart_test(request):
return render(request,'mbr/chart_test.html')
答案 0 :(得分:0)
chart_test.html扩展base.html - 它不应再包含html / body标签了,你加载jquery两次 - 一次在base中,一次在chart_test中... 尝试类似的事情:
{% extends "base.html" %}
{% load staticfiles %}
{% block content %}
<div id="chart_container" style="height: 300px"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script type="text/javascript">
$(function() {
$('#chart_container').highcharts({
chart: {
type: 'bar'
},
title: {
text: 'Monthly Sales'
},
xAxis: {
categories: ['Jan','Feb','Mar','Apr']
},
yAxis: {
title: {
text: 'numbers'
}
},
series: [{
name: 'John',
data: [1, 0, 4]
}, {
name: 'King',
data: [5, 7, 3]
}]
});
});
</script>
{% endblock %}
答案 1 :(得分:0)
通过将jquery-3.2.0.js放在base.html文件的开头
来解决<!DOCTYPE html>
{% load staticfiles %}
<html>
<head>
{% block title %}<title>mbr page </title>{% endblock %}
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="{% static "mbr/css/boostrap-fluid-adj.css" %}" rel="stylesheet">
<link href="{% static "mbr/css/bootstrap.min.css" %}" rel="stylesheet" media="screen">
<link href="{% static "mbr/css/bootstrap-responsive.css" %}" rel="stylesheet">
<script src="{% static 'mbr/js/jquery-3.2.0.js' %}"></script>
<style>
body {
padding-top: 50px;
}
@media (max-width: 980px) {
body {
padding-top: 0;
}
}
</style>
</head
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container-fluid">
<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="nav-collapse collapse">
<ul class="nav pull-right">
<li><a href="/admin/">Login</a></li>
</ul>
<ul class="nav navbar-nav">
<li class="active"><a href="/mbr/">Home</a></li>
<li><a href="{% url 'search_form' %}">Search s</a></li>
<li><a href="{% url 'results_list' %}">Results History</a></li>
<li><a href="{% url 'chart_test' %}">Statistics</a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row-fluid">
<div class="span3">
<div class="well sidebar-nav">
<h3> Name</h3>
<p class="active"><a href="/mbr/4/">TEST1</a></p>
<p><a href="/mbr/3/">TEST2</a></p>
<p><a href="/mbr/2/">TEST3</a></p>
<p><a href="/mbr/1/">TEST4</a></p>
</div>
</div>
<div class="span9">
{% block content %}
{% endblock %}
</div>
</div>
</div>
<hr>
<script src="{% static 'mbr/js/bootstrap.min.js' %}"></script>
</body>
</html>