更改颜色并使用设置 API

Change Colors and Using Setting Up an API

我正在尝试在我的 rails 网络应用程序上使用 highcharts。我对此完全陌生。如何将向下蜡烛条的颜色更改为红色,将向上蜡烛条更改为绿色?

这是我的:

$(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 = [],
            dataLength = data.length,
            // set the allowed units for data grouping
            groupingUnits = [[
                'week',                         // unit name
                [1]                             // allowed multiples
            ], [
                'month',
                [1, 2, 3, 4, 6]
            ]],

            i = 0;

        for (i; i < dataLength; i += 1) {
            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
            ]);
        }


        // create the chart
        $('#container').highcharts('StockChart', {

            rangeSelector: {
                selected: 1
            },

            title: {
                text: 'AAPL Historical'
            },

            yAxis: [{
                labels: {
                    align: 'right',
                    x: -3
                },
                title: {
                    text: 'OHLC'
                },
                height: '60%',
                lineWidth: 2
            }, {
                labels: {
                    align: 'right',
                    x: -3
                },
                title: {
                    text: 'Volume'
                },
                top: '65%',
                height: '35%',
                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
                }
            }]
        });
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://code.highcharts.com/stock/highstock.js"></script>
<script src="http://code.highcharts.com/stock/modules/exporting.js"></script>

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

如果我加载:http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-ohlcv.json&callback=?我可以弄清楚第一个数字的所有数字是多少,这代表什么?日期不知何故?

我如何使用 rails 制作一个 JSON 供 highcharts 使用,以便我可以看到每分钟的更新。


我的问题:

非常感谢。

如果我不够清楚,请告诉我。

要更改颜色,请使用 color and upColor

我不是Rails开发人员,但要回答其他问题:

  • 在JS中使用setInterval()从后端AJAX获取数据
  • 对于基于分钟的烛台,只需提供每分钟都有时间戳的数据。在示例中,数据是基于每日的。

关于数据格式:[1222646400000,17.09,17.10,14.37,15.04,655513663]

第一个是以毫秒为单位的时间戳,接下来的四个值是开盘-高-低-收盘,最后一个是用于第二个窗格的音量。

强烈推荐阅读教程:

我很确定在 Rails 中生成 JSON 不会很难。