每个 - 列范围栏上的HighCharts颜色

时间:2016-02-21 18:54:32

标签: javascript jquery html charts highcharts

有关Highcharts的问题,如何在每个列范围栏上设置不同的颜色。 我尝试了一些选择,但无法使其发挥作用。

我尝试的例子:

这是我在JSFiddle上的代码:

https://jsfiddle.net/1abugmka/#&togetherjs=N72vHyNcPL

$(function () {

    $('#container').highcharts({

        chart: {
            type: 'columnrange',
            inverted: true,
            renderTo: 'container',
        },
        tooltip: {
          pointFormat: ""
        },
        title: {
            text: ''
        },
         credits: {
        enabled: false
      },
        xAxis: {
             type: 'datetime',
             categories:['1','2']
        },
        yAxis:{
          labels: {
            enabled: false
         },
         title: {
          text: 'Months'
        }
        },
         colors: ['#562F1E', '#AF7F24'],
        series: [{
           data: [
                [Date.UTC(2015, 10, 01),Date.UTC(2015, 02, 04)],
                [Date.UTC(2014, 10, 01),Date.UTC(2014, 02, 04)],

            ]

        }],

        legend: {
        enabled: false
      },
      exporting: {
        enabled: false
      }

    });

});

1 个答案:

答案 0 :(得分:4)

一种选择是使用colorByPoint,它为每个点指定一种颜色,而不是每个系列的颜色。示例实现(JSFiddle):

plotOptions: {
    columnrange: {
        colorByPoint: true
        colors: ['red', 'blue', 'yellow'] // if you want custom order of colors
    }
}

另一种选择是将每个点定义为对象,而不是数组。然后,您可以设置每个单独点对象的color选项。示例实现(JSFiddle):

series: [{
    data: [
        { low: Date.UTC(2015, 10, 01), high: Date.UTC(2015, 02, 04), color: 'red' },
        { low: Date.UTC(2014, 10, 01), high: Date.UTC(2014, 02, 04), color: 'blue' },
    ]
}]
相关问题