如何找到自动打开,高,低和关闭值并显示烛台和图表

时间:2014-07-02 13:16:08

标签: jquery html highcharts highstock

我有以下代码。 jsfiddle类型按钮的想法借用了这个jsfiddle

我的javascript代码:

 $(function () {   $.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-ohlc.json&callback=?', function (data) {
            Highcharts.setOptions({
                global: {
                    timezoneOffset: 7 * 60
                }
            });

        // Create the chart
        var end = 1363935600000;
        var chart = new Highcharts.StockChart({
            chart: {
                renderTo: 'container'
            },
            title: {
                text: 'AAPL Stock Price'
            },
            rangeSelector: {
                inputEnabled: false,
                selected: 0,
                buttonTheme: {
                    width: null
                },
                buttons: [{
                    type: 'day',
                    count: 6,
                    text: 'past 7 days'
                }, {
                    type: 'day',
                    count: 14,
                    text: 'past 15 days'
                }, {
                    type: 'day',
                    count: 29,
                    text: 'past 30 days'
                }, {
                    type: 'day',
                    count: 59,
                    text: 'past 60 days'
                }, {
                    type: 'day',
                    count: 179,
                    text: 'past 180 days'
                }]
            },

            xAxis: {
                max: end,
                type: 'datetime',
                minTickInterval: 24 * 3600 * 1000
            },
            navigator: {
                enabled: false
            },
            scrollbar: {
                enabled: false
            },
            series: [{
                name: 'AAPL',
                data: data,
                tooltip: {
                    valueDecimals: 3
                }
            }]
        });
        // Toggle point markers
        var enableMarkers = true;
        $('#markers').click(function () {
            chart.series[0].update({
                marker: {
                    enabled: enableMarkers,
                    radius: 5,
                    fillColor: '#0000FF'
                }
            });
            enableMarkers = !enableMarkers;
        });

        // Toggle point markers
        var color = false;
        $('#color').click(function () {
            chart.series[0].update({
                color: color ? null : Highcharts.getOptions().colors[1]
            });
            color = !color;
        });

        // Set type
        $.each(['line', 'spline', 'area', 'areaspline', 'candlestick', 'ohlc'], function (i, type) {
            $('#' + type).click(function () {
                chart.series[0].update({
                    type: type
                });
            });
        });
    });
});

我的HTML代码:

<script src="http://code.highcharts.com/stock/highstock.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/stock/modules/exporting.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="height: 400px; min-width: 600px"></div>
<button id="markers">Toggle point markers</button>
<button id="color">Toggle color</button>
<button id="line" style="margin-left: 2em">Line</button>
<button id="spline">Spline</button>
<button id="area">Area</button>
<button id="areaspline">Area spline</button>
<button id="ohlc">OHLC</button>
<button id="candlestick">Candlestick</button>

更新问题: 它与样本数据集一起工作正常。 但是,如果我更改下面的数据集: 1279609200000 74

1279695600000   685
1279782000000   1123
1279868400000   666
1279954800000   166
1280041200000   84
1280127600000   302
1280214000000   492
1280300400000   571
1280386800000   602
1280473200000   583
1280559600000   570
1280646000000   493
1280732400000   685
1280818800000   702
1280905200000   549

如何显示烛台和ohlc图表?谢谢。

0 个答案:

没有答案