我在html文件中有以下代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<div id=0 style='width:400px; height:400px'></div>
<script type='text/javascript' src='https://dl.dropboxusercontent.com/u/93241685/jquery.1.9.1.min.js'></script>
<script type='text/javascript' src='https://dl.dropboxusercontent.com/u/93241685/highcharts.js'></script>
<script>
$(function () {
$('#0').highcharts({
chart: {type: 'area',plotBackgroundColor:'white',plotBorderWidth: '',plotShadow: true,zoomType:'undefined'},
title: {text:'TTT'},
xAxis: {title: {text:'trX'}},
yAxis: {title: {text:'Ygrg'}},
tooltip: {pointFormat: '{series.name} {point.x}'},
});});
var chart = $('#0').highcharts();
chart.addSeries({
name: 'S1',
data: [1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6]
}, false);
chart.redraw();
</script>
</body>
</html>
当我运行此选项时,只显示div,图表标题位于顶部。没有其他的!甚至没有出现xAxis标题或yAxis标题。现在,有趣的是,当我试图在JSFiddle上运行它时,它完美地显示了图形。 JSFiddle链接也在下面给出。什么可能是在html文件中执行它的问题,我尝试从文件中删除额外的位,可能还有一些但仍然没用。请帮助。
答案 0 :(得分:0)
尝试将其包含在document.ready()
中,因为在jsfiddle中你指示运行代码jquery onload(如document.ready()
),如下所示:
$(document).ready(function(){
$('#0').highcharts({
chart: {type: 'area',plotBackgroundColor:'white',plotBorderWidth: '',plotShadow: true,zoomType:'undefined'},
title: {text:'TTT'},
xAxis: {title: {text:'trX'}},
yAxis: {title: {text:'Ygrg'}},
tooltip: {pointFormat: '{series.name} {point.x}'},
});
var chart = $('#0').highcharts();
chart.addSeries({
name: 'S1',
data: [1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6]
}, false);
chart.redraw();
});