2016-04-26 19 views
8

Sto cercando di creare un grafico highstock, ma sto ottenendo il seguente errore:Highstock, errore: TypeError Uncaught: w [(valore intermedio) (valore intermedio) (valore intermedio)] non è un costruttore

error: Uncaught TypeError: w[(intermediate value)(intermediate value)(intermediate value)] is not a constructor

Il mio JSON sembra valido, e anche il mio javascript, qualche idea su come risolvere questo problema?

Javascript:

$.getJSON('<?php echo SITE_URL; ?>analytic/weekly_views_json', function(data) 
    { 
     // Create the chart 
     $('#container2').highcharts('StockChart', { 

      rangeSelector: { 
       selected: 1 
      }, 

      title: { 
       text: 'AAPL Stock Price' 
      }, 

      series: [{ 
       name: 'AAPL Stock Price', 
       data: data, 
       type: 'spline', 

      }] 
     }); 
    }); 

JSON:

[[1420547368,1],[1423225768,1],[1425644968,1],[1428319768,1],[1430911768,1],[1433590168,1],[1452083368,1],[1454761768,1],[1457267368,1],[1458131368,1],[1459942168,1],[1494070168,1]] 
+2

I timestamp sembrano un formato UNIX, ma dovrebbe essere moltiplicato per 1000 per ottenere il formato JS. Hai una demo dal vivo del tuo grafico, perché il tuo codice è corretto. –

+0

Il codice che hai fornito sembra funzionare http://jsfiddle.net/o079d5s6/2/ Potresti creare un violino che mostri il problema? –

+0

@YuryTarabanko Io uso esattamente l'esempio di highchart ma ho ottenuto l'errore sopra! [esempio di highchart jsfiddle] (http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/stock/demo/basic-line/) – MHS

risposta

5

Prima soluzione:

avevo lo stesso errore, ho usato highchart come di seguito nel mio codice HTML:

<head> 
<script src="https://code.highcharts.com/highcharts.js"></script> 
... 
</head> 

e il mio codice js era:

$('#container').highcharts('StockChart', { 
... 
}); 

rispetto al highchart documention, dobbiamo usare Highcharts.Chart per creare nuova highstock. così ho cambiato il mio codice a:

<head> 
<script src="https://code.highcharts.com/highcharts.js"></script> 
... 
</head> 

e il mio codice js era:

var chart = new Highcharts.Chart({ 
     chart: { 
       renderTo: 'container' 
      }, 
... 
}); 

e questo errore è stato risolto!

Seconda soluzione:

anche per quanto riguarda this documentation, se si esegue Chart e StockChart in combinazione, è solo bisogno di caricare il file highstock.js.

modo cambiato il mio codice a:

<head> 
<script src="https://code.highcharts.com/stock/highstock.js"></script> 
... 
</head> 

e il mio codice js era:

var chart = new Highcharts.Chart({ 
     chart: { 
       renderTo: 'container' 
      }, 
... 
}); 
0

Questo ha funzionato per me

<script src="../lib/highcharts.js"/> 
<script src="../lib/highcharts-more.js"/> 

var chart = new Highcharts.Chart({ 
        chart: { 
         renderTo: 'Temperature' 
        }, 
        title: { 
         text: 'HighStock' 
        }, 
        legend: { 
         enabled: true 
        }, 
        xAxis: { 
         categories: ['1','2','3','4'], 
         title: { 
          text: 'day' 
         } 
        }, 
        yAxis: { 
         title: { 
          text: 'values' 
         } 
        }, 
        series: [{ 
         name: 'temperature', 
         data: [ 
          [5,30],[10,35],[15,40],[20,45] 
         ], 
        }] 
       }); 
Problemi correlati