Highcharts.stockChart不是一个功能

时间:2016-12-17 13:38:52

标签: javascript charts highcharts

我正在尝试使用Hightcharts.js制作图表,但收到错误

  

TypeError:Highcharts.stockChart不是函数。

我使用npm(package.json)

安装它
"highcharts": "^5.0.6"

Сall

var Highcharts = require('highcharts');

并使用

var options = {
    chart: {
        alignTicks: false,
        renderTo: 'container'
    },

    rangeSelector: {
        selected: 1
    },

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

    series: [{
        type: 'column',
        name: 'AAPL Stock Volume',
        data: [],
        dataGrouping: {
            units: [[
                'week', // unit name
                [1] // allowed multiples
            ], [
                'month',
                [1, 2, 3, 4, 6]
            ]]
        }
    }];
};
var chart = Highcharts.stockChart(options);

Highstock不是一个单独的模块,属于Highcharts,我不明白可能是什么问题?

2 个答案:

答案 0 :(得分:3)

Highstock不是一个单独的模块,属于Highcharts。事实并非如此。

但相反的是。如果你包括Highstock,那么你不需要再包括Highcharts。

根据Highcharts文件

http://www.highcharts.com/docs/getting-started/installation

Highcharts已包含在Highstock中,因此无需加载两者。 highstock.js文件包含在包中。

$(document).ready(function(){
    $.getJSON('https://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=?', function (data)    {
        // Create the chart
        
        var dataObject = {
            rangeSelector: {
                selected: 1,
                inputEnabled: $('#container').width() > 480
            },
            
            title: {
                text: 'AAPL Stock Price'
            },
            
            series: [{
                name: 'AAPL',
                data: data,
                tooltip: {
                    valueDecimals: 2
                }
            }]
            
            ,
            
            chart: {
                renderTo: 'container'
            }
            
        };
        
         var chart = new Highcharts.stockChart(dataObject);   
    });
    });
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highcharts/5.0.6/css/highcharts.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highcharts/5.0.6/js/highstock.js"></script>

<div id="container" style="height: 400px; min-width: 310px"></div>

答案 1 :(得分:1)

npm安装highcharts-angular,然后

import * as Highcharts from 'highcharts/highstock';