2016-09-20 10 views
0

私は新しいby javascriptです。私は私のウェブサイトでハイチャートを使用してスタック棒グラフをプロットしたいと思います。デモコードhereをコピーして、それをPHPのlocalhostに貼り付けますが、私のウェブサイトにハイチャートはありません。どうしたの?ハイチャートはウェブサイトでは機能しません

コード↓

<!DOCTYPE html> 
<html> 
<head> 
<script type="text/javascript" src="https://code.highcharts.com/highcharts.js"></script> 
<script type="text/javascript" src="https://code.highcharts.com/modules/exporting.js"></script> 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> 
<script type="text/javascript"> 
$(function() { 
    $("#container").highcharts({ 
     chart: { 
      type: 'column' 
     }, 
     title: { 
      text: 'Stacked column chart' 
     }, 
     xAxis: { 
      categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas'] 
     }, 
     yAxis: { 
      min: 0, 
      title: { 
       text: 'Total fruit consumption' 
      }, 
      stackLabels: { 
       enabled: true, 
       style: { 
        fontWeight: 'bold', 
        color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray' 
       } 
      } 
     }, 
     legend: { 
      align: 'right', 
      x: -30, 
      verticalAlign: 'top', 
      y: 25, 
      floating: true, 
      backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || 'white', 
      borderColor: '#CCC', 
      borderWidth: 1, 
      shadow: false 
     }, 
     tooltip: { 
      headerFormat: '<b>{point.x}</b><br/>', 
      pointFormat: '{series.name}: {point.y}<br/>Total: {point.stackTotal}' 
     }, 
     plotOptions: { 
      column: { 
       stacking: 'normal', 
       dataLabels: { 
        enabled: true, 
        color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white', 
        style: { 
         textShadow: '0 0 3px black' 
        } 
       } 
      } 
     }, 
     series: [{ 
      name: 'John', 
      data: [9, 10, 4, 7, 2] 
     }, { 
      name: 'Jane', 
      data: [8, 5, 3, 2, 1] 
     }, { 
      name: 'Joe', 
      data: [7, 7, 4, 2, 5] 
     }] 
    }); 
}); 
</script> 

</head> 

<body> 
    <h2 align="center">HighCharts.js demo</h2> 
    Where's the plot?<br> 
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div> 

</body> 
</html> 

答えて

1

だけのjQueryを呼び出すスクリプトを変更し、それがhighcharts前にロードします。 Highchartsはjqueryの上に構築されており、ハイチャートソースの前にロードされていないとエラーが発生するため、これは必要です。

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> 
<script type="text/javascript" src="https://code.highcharts.com/highcharts.js"></script> 
<script type="text/javascript" src="https://code.highcharts.com/modules/exporting.js"></script> 
+0

ありがとう!!!それはいかに簡単です。なぜjqueryを最初に呼び出す必要がありますか? – swchen

+0

ようこそ! Highchartsはjqueryの上に構築されていますので、jqueryがロードされていないとエラーが発生します。 – odai

+0

OK、ありがとうございます。 – swchen

関連する問題