在HighCharts中更改音量列的颜色(高/低)

Jak*_*ake 7 highcharts highstock

我有一个简单的图表显示下面有体积列的烛台:http://jsfiddle.net/T83Xy/

基本上,我想使用黑色和红色作为列,具体取决于它是否高于打开或不高.我通过推Y:数据,颜色:'#000000'作为参数看到了一些样本.问题是我正在推送日期和卷号.我试图推X:日期,Y:数据,颜色:'#000000'但是它抛出错误而没有给我预期的结果.

Igo*_*tin 8

首先,如果你有大量的积分,你需要将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));
Run Code Online (Sandbox Code Playgroud)

请小心,因为此代码将影响当前页面上的所有图表.但您可以轻松添加一些条件,仅在特定图表上运行此选项.是一个带有上述代码的默认Highstock演示.