2014-05-04 57 views
1

我有一个HTML文件下面的代码:Highchart绘图问题

<!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文件中,我试图从文件中删除额外的位和可能的一切,但仍然没有用。请帮助。

http://jsfiddle.net/5fway/

回答

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(); 
});