2014-05-06 19 views
6

Sto riproducendo un grafico utilizzando highstock sull'applicazione rails su un file index.html.erb, tuttavia quando provo a caricare il grafico, viene visualizzato il seguente errore sulla console firebug,ReferenceError: HighCharts non definito

ReferenceError: HighCharts is not defined 
new HighCharts.Chart({ 

il mio file index.html.erb è la seguente

<div id="quotes_chart", style="width=560px; height:300px;"> 
<script> 
$(function(){ 
new HighCharts.Chart({ 
    chart : { 
    renderTo: "quotes_chart" 
    }, 
    title : { 
    text: "Daily trades" 
    }, 
    xAxis : { 
    type: "datetime" 
    }, 
    yAxis : { 
    title: { 
    text: "Shillings" 
    } 
    }, 
    tooltip : { 
    formatter: function(){ 
     return HighCharts.dateFormat("%B %e, %Y", this.x) + ': ' + "Kshs" + Highcharts.numberFormat(this.y, 2); 
    } 
    }, 
    series: [ 
    <% { "Telecommunication" => StockQuote.telecomm, "Agriculture" => StockQuote.agric }.each do |name, prices| 
%> 
{ 
    name: <%= name %>, 
    pointInterval: <%= 1.day * 1000 %>, 
    pointStart: <%= 2.weeks.ago.to_i * 1000 %>, 
    data: <%= (2.weeks.ago.to_date..Date.today).map { |date| StockQuote.price_on(date).to_f}.inspect%> 
}, 
<% end %> 
] 
}); 
}); 
</script> 
</div> 

Nel mio application.html.erb è la seguente:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> 
<script src="components/highstock/highstock.js"></script> 
<%= javascript_include_tag "jquery-1.11.0.min", "highcharts" %> 

Nella cartella app assests/javascripts ho entrambi i file jquery-1.11.0.min.js e highcharts.js scaricati da highcharts.com

Cosa potrei fare di sbagliato?

risposta

2

È necessario caricare Highcharts solo una volta, non due volte. Quindi, consiglio di usare solo:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> 
<script src="components/highstock/highstock.js"></script> 

Perché Highstock include tutte le opzioni di Highcharts. Per favore, tieni sempre cura dei percorsi corretti per i tuoi file, perché sembra un problema solo con esso.

3
var chart=null; 
$(document).ready(function() { 
    chart = new Highcharts.Chart({ 
        chart: { 
         renderTo: 'container', 
         type: 'bar' 
        }, 
        title: { 
         text: '${model.title}' 
        } 
...       

Impostare il grafico per nulla, perché questo errore può verificarsi a causa di dichiarazione più che si può non essere a conoscenza. Presupposto: tutte le importazioni sono corrette

Problemi correlati