7

下に出来高の列があるローソク足を示す簡単なチャートがあります: http://jsfiddle.net/T83Xy/

基本的には、始値よりも高く閉まるかどうかに応じて、黒と赤を柱に使用したいと考えています。パラメータとして Y: data, color: '#000000' をプッシュして、いくつかのサンプルを見てきました。問題は、日付とボリューム番号をプッシュしていることです。X: 日付、Y: データ、色: '#000000' をプッシュしようとしましたが、エラーが発生し、期待した結果が得られません。

4

3 に答える 3

9

大量のポイントがある場合は、最初にseries.turboThresholdを 0に設定する必要があります。これにより、入力データ形式のチェックが無効になります。

次に、ろうそくに応じて列の色を適用するには、次のコードをお勧めします。

Highcharts.seriesTypes.column.prototype.pointAttribs = (function(func) {
    return function(point, state) {
      var attribs = func.apply(this, arguments);
      
      var candleSeries = this.chart.series[0]; // Probably you'll need to change the index
      var candlePoint = candleSeries.points.filter(function(p) { return p.index == point.index; })[0];

      var color = (candlePoint.open < candlePoint.close) ? '#FF0000' : '#000000'; // Replace with your colors
      attribs.fill = state == 'hover' ? Highcharts.Color(color).brighten(0.3).get() : color;
      
      return attribs;
    };
}(Highcharts.seriesTypes.column.prototype.pointAttribs));

このコードは、現在ページにあるすべてのグラフに影響するので注意してください。ただし、特定のチャートでのみこれを実行する条件を簡単に追加できます。上記のコードを使用したデフォルトのHighstockデモを次に示します。

于 2012-09-30T05:08:38.120 に答える
1

これは私にとって完璧に機能しました:

$(function () {
jQuery.getJSON('https://www.highcharts.com/samples/data/jsonp.php?filename=aapl-ohlcv.json&callback=?', function (data) {

    // split the data set into ohlc and volume
    var volumeColor = '';
    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
        ]);
         if (i==0) {
        volumeColor = '#CCCCCC';
         } else {         
            if (data[i][1] >= data[i-1][1]) {
               volumeColor = '#006633';
            } else {
               volumeColor = '#CC0033';
            }
         }

        volume.push({
            x: data[i][0], // the date
            y: data[i][5],
            color: volumeColor
        });
    }


    // 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,
            turboThreshold: Number.MAX_VALUE,
            dataGrouping: {
                enabled: false,
                units: groupingUnits
            }
        }]
    });
});
});
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script>
<div id="container" style="height:400px;min-width:310px"></div>

于 2016-10-13T06:38:52.970 に答える