Highcharts modulo alternateGridColor

时间:2018-05-08 15:52:50

标签: javascript html highcharts

在HighCharts中,是否有一种内置的方法可以在功能上类似于' alternateGridColor'为每个第三,第四等行添加网格颜色?目前' alternateGridColor'只允许你为每隔一行着色。

这是我试图完成的设计: The design I'm trying to accomplish

1 个答案:

答案 0 :(得分:2)

没有自动化方式,但您可以使用plotBands来实现您的外观。

var categories = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];
var plotBands = [];
for (var i = 0; i < categories.length; i++) {
  if (i % 3 == 1) {
    plotBands.push({
      color: '#fecdfe',
      from: i - .5,
      to: i + .5
    });
  } else if (i % 3 == 2) {
    plotBands.push({
      color: '#cdfee5',
      from: i - .5,
      to: i + .5
    });
  }
}
Highcharts.chart('container', {
  yAxis: {

  },
  xAxis: {
    categories: categories,
    plotBands: plotBands,
  },

  series: [{
    type: 'bar',
    data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4],

  }]
});

http://jsfiddle.net/wskt4hzz/