Highstocks图表没有正确显示

时间:2016-06-02 05:59:35

标签: javascript html highcharts highstock

我试图复制一个我在小提琴上找到的高档图表示例( link)。我将代码复制并粘贴到html文件中,但图表并没有显示出来。任何人都可以帮我解决这个问题吗?感谢。

html文件内容如下:

<!DOCTYPE html>
<html>
<head>

<!--highStocks start--> 

    <!--script src="./static/lib/js/highstock.js"></script>
    <script src="./static/lib/js/exporting.js"></script-->

    <script src="http://github.highcharts.com/highstock.js"></script>
    <script src="http://code.highcharts.com/stock/modules/exporting.js"></script>
    <script type="text/javascript">
$(function() {
    $.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-ohlcv.json&callback=?', function(data) {

        // split the data set into ohlc and volume
        var ohlc = [],
            volume = [],
            volume2 = [],
            dataLength = data.length;

        for (i = 0; i < dataLength; i++) {
            ohlc.push([
                data[i][0], // the date
                data[i][1], // open
                data[i][2], // high
                data[i][3], // low
                data[i][4] // close
            ]);

            volume.push([
                data[i][0], // the date
                data[i][5] // the volume
            ]);

            volume2.push([
                data[i][0], // the date
                data[i][5] // the volume
            ]);


        }

        // set the allowed units for data grouping
        var groupingUnits = [[
            'week',                         // unit name
            [1]                             // allowed multiples
        ], [
            'month',
            [1, 2, 3, 4, 6]
        ]];

        // create the chart
        chart = new Highcharts.StockChart({
            chart: {
                renderTo: 'container',
                alignTicks: false
            },

            rangeSelector: {
                selected: 1
            },

            title: {
                text: 'AAPL Historical'
            },

            yAxis: [{
                title: {
                    text: 'OHLC'
                },
                height: 200,
                lineWidth: 2
            }, {
                title: {
                    text: 'Volume'
                },
                top: 300,
                height: 100,
                offset: 0,
                lineWidth: 2
            }, {
                title: {
                    text: 'Volume2'
                },
                top: 400,
                height: 100,
                offset: 0,
                lineWidth: 2
            }],

            series: [{
                type: 'candlestick',
                name: 'AAPL',
                data: ohlc,
                dataGrouping: {
                    units: groupingUnits
                }
            }, {
                type: 'column',
                name: 'Volume',
                data: volume,
                yAxis: 1,
                dataGrouping: {
                    units: groupingUnits
                }
            }, {
                type: 'column',
                name: 'Volume2',
                data: volume,
                yAxis: 2,
                dataGrouping: {
                    units: groupingUnits
                }
            }]
        });
    });
});
    </script>


<!--highStocks end--> 



</head>
<body class="application">

<hr>
<div id="container" style="height: 600px; min-width: 500px"></div>
<hr>



</body>
</html>

1 个答案:

答案 0 :(得分:3)

添加它将起作用的Jquery库

&#13;
&#13;
<!DOCTYPE html>
<html>
<head>

<!--highStocks start--> 

    <!--script src="./static/lib/js/highstock.js"></script>
    <script src="./static/lib/js/exporting.js"></script-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
    <script src="http://github.highcharts.com/highstock.js"></script>
    <script src="http://code.highcharts.com/stock/modules/exporting.js"></script>
    <script type="text/javascript">
$(function() {
    $.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-ohlcv.json&callback=?', function(data) {

        // split the data set into ohlc and volume
        var ohlc = [],
            volume = [],
            volume2 = [],
            dataLength = data.length;

        for (i = 0; i < dataLength; i++) {
            ohlc.push([
                data[i][0], // the date
                data[i][1], // open
                data[i][2], // high
                data[i][3], // low
                data[i][4] // close
            ]);

            volume.push([
                data[i][0], // the date
                data[i][5] // the volume
            ]);

            volume2.push([
                data[i][0], // the date
                data[i][5] // the volume
            ]);


        }

        // set the allowed units for data grouping
        var groupingUnits = [[
            'week',                         // unit name
            [1]                             // allowed multiples
        ], [
            'month',
            [1, 2, 3, 4, 6]
        ]];

        // create the chart
        chart = new Highcharts.StockChart({
            chart: {
                renderTo: 'container',
                alignTicks: false
            },

            rangeSelector: {
                selected: 1
            },

            title: {
                text: 'AAPL Historical'
            },

            yAxis: [{
                title: {
                    text: 'OHLC'
                },
                height: 200,
                lineWidth: 2
            }, {
                title: {
                    text: 'Volume'
                },
                top: 300,
                height: 100,
                offset: 0,
                lineWidth: 2
            }, {
                title: {
                    text: 'Volume2'
                },
                top: 400,
                height: 100,
                offset: 0,
                lineWidth: 2
            }],

            series: [{
                type: 'candlestick',
                name: 'AAPL',
                data: ohlc,
                dataGrouping: {
                    units: groupingUnits
                }
            }, {
                type: 'column',
                name: 'Volume',
                data: volume,
                yAxis: 1,
                dataGrouping: {
                    units: groupingUnits
                }
            }, {
                type: 'column',
                name: 'Volume2',
                data: volume,
                yAxis: 2,
                dataGrouping: {
                    units: groupingUnits
                }
            }]
        });
    });
});
    </script>


<!--highStocks end--> 



</head>
<body class="application">

<hr>
<div id="container" style="height: 600px; min-width: 500px"></div>
<hr>



</body>
</html>
&#13;
&#13;
&#13;