javascript 高图不显示
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27126224/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Highcharts not showing up
提问by Roland
I have a .tpl file and I want to add a couple of charts to it. The values are to be fetched from MySQL database. For the charts, I am using Highcharts.
我有一个 .tpl 文件,我想向其中添加几个图表。这些值将从 MySQL 数据库中获取。对于图表,我使用的是 Highcharts。
Here is the fiddle I want my charts to look exactly like it, ofcourse the values would change.
这是我希望我的图表看起来完全一样的小提琴,当然值会改变。
So my code is:
所以我的代码是:
<head>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
</head>
<body>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
<script type="text/javascript">
$(function () {
$('#container').highcharts({
chart: {
type: 'column'
},
title: {
text: 'Monthly Average Rainfall'
},
subtitle: {
text: 'Source: WorldClimate.com'
},
xAxis: {
categories: [
'Jan',
'Feb',
'Mar',
'Apr',
'May'
]
},
yAxis: {
min: 0,
title: {
text: 'Rainfall (mm)'
}
},
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [{
name: 'Tokyo',
data: [49.9, 71.5, 106.4, 129.2, 144.0]
}]
});
});
<script>
</script>
</body>
When I put this in my .tpl file, it shows nothing. Can anyone say what am I doing wrong. Should I add the latest version of jquery or something..
当我把它放在我的 .tpl 文件中时,它什么也没显示。谁能说我做错了什么。我应该添加最新版本的jquery还是什么..
I have an additional thing to mention, when I try to use this in a separate jsfiddle, it doesn't work there as well.
我还有一件事要提,当我尝试在单独的 jsfiddle 中使用它时,它在那里也不起作用。
回答by user230391
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<script>
$(function () {
$('#container').highcharts({
chart: {
type: 'column'
},
title: {
text: 'Monthly Average Rainfall'
},
subtitle: {
text: 'Source: WorldClimate.com'
},
xAxis: {
categories: [
'Jan',
'Feb',
'Mar',
'Apr',
'May'
]
},
yAxis: {
min: 0,
title: {
text: 'Rainfall (mm)'
}
},
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [{
name: 'Tokyo',
data: [49.9, 71.5, 106.4, 129.2, 144.0]
}]
});
});
</script>
</head>
<body>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
</body>
回答by sebbzzz
You most likely did not include jquery. I pasted you exact code (without the extra script tag) in a jsfiddle and it worked.
您很可能没有包含 jquery。我在 jsfiddle 中粘贴了你的确切代码(没有额外的脚本标签)并且它起作用了。
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
回答by Syno
Make sure to always try the jQuery document ready functionfirst, when an error occurs.
发生错误时,请确保始终首先尝试jQuery 文档就绪功能。
<head>
<script src="/js/jquery-3.2.1.min.js"></script>
</head>
<script type="text/javascript">
$(document).ready(function(){
/ / code
});
</script>
回答by user230391
Please add this script at the head header in given order .
请按照给定的顺序在头部标题添加此脚本。
src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
src="http://code.highcharts.com/highcharts.js">
src="http://code.highcharts.com/highcharts.js">
src="http://code.highcharts.com/modules/exporting.js">
src="http://code.highcharts.com/modules/exporting.js">
回答by user230391
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<script>
$(function () {
var issueData = {"WAR":13,"VTO":14,"EXWH":33};
var pieData = [];
for (i in issueData) {
pieData.push([i,issueData[i]] );
}
$('#container').highcharts({
chart: {
type: 'pie',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Total tickets for each project'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
format: '<b>{point.name}</b>: {point.percentage:.1f} %'
}
}
},
series: [{
data: pieData
}]
});
});
$(function () {
var issueData = {"bug":8,"false":5};
var pieData = [];
for (i in issueData) {
pieData.push([i,issueData[i]] );
}
$('#container1').highcharts({
chart: {
type: 'pie',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'WAR DOne status '
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
format: '<b>{point.name}</b>: {point.percentage:.1f} %'
}
}
},
series: [{
data: pieData
}]
});
});
$(function () {
var issueData = {"true":3,"false":11};
var pieData = [];
for (i in issueData) {
pieData.push([i,issueData[i]] );
}
$('#container2').highcharts({
chart: {
type: 'pie',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'VTO DOne status '
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
format: '<b>{point.name}</b>: {point.percentage:.1f} %'
}
}
},
series: [{
data: pieData
}]
});
});
$(function () {
var issueData = {"true":8,"false":6};
var pieData = [];
for (i in issueData) {
pieData.push([i,issueData[i]] );
}
$('#container3').highcharts({
chart: {
type: 'pie',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'EXWH DOne status '
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
format: '<b>{point.name}</b>: {point.percentage:.1f} %'
}
}
},
series: [{
data: pieData
}]
});
});
</script>
<title>Charts</title>
</head>
<body>
<div id="container" style="height: 400px"></div>
<div id="container1" style="height: 400px"></div>
<div id="container2" style="height: 400px"></div>
<div id="container3" style="height: 400px"></div>
</body>
</html>