HighCharts中的拆分显示传奇



我的组合图与高胸罩,有样条,馅饼和堆叠。是否可以将图例分开或一起使用垂直和水平布局?

当前布局传奇是水平的

*系列1 *系列2 *系列3 *系列4 *系列5 *系列6 *系列7 *系列8

我希望传奇显示为

*系列1 *系列2
*系列3 *系列4 *系列5
*系列6 *系列7 *系列8

有可能吗?

thanx

不能仅通过使用HighCharts构造函数来完成。您可以通过包装一些核心功能来实现这种外观和行为:

(function(H) {
  var merge = H.merge;
  H.wrap(H.Legend.prototype, 'getAllItems', function() {
    var allItems = [],
      chart = this.chart,
      options = this.options,
      legendID = options.legendID;
    H.each(chart.series, function(series) {
      if (series) {
        var seriesOptions = series.options;
        // use points or series for the legend item depending on legendType
        if (!isNaN(legendID) && (seriesOptions.legendID === legendID)) {
          allItems = allItems.concat(
            series.legendItems ||
            (seriesOptions.legendType === 'point' ?
              series.data :
              series)
          );
        }
      }
    });
    return allItems;
  });
  H.wrap(H.Chart.prototype, 'render', function(p) {
    var chart = this,
      chartOptions = chart.options;
    chart.firstLegend = new H.Legend(chart, merge(chartOptions.legend, chartOptions.firstLegend, {
      legendID: 0
    }));
    chart.secondLegend = new H.Legend(chart, merge(chartOptions.legend, chartOptions.secondLegend, {
      legendID: 1
    }));
    p.call(this);
  });
  H.wrap(H.Chart.prototype, 'redraw', function(p, r, a) {
    var chart = this;
    p.call(chart, r, a);
    chart.firstLegend.render();
    chart.secondLegend.render();
  });
  H.wrap(H.Legend.prototype, 'positionItem', function(p, item) {
    p.call(this, item);
  });
})(Highcharts);

HighCharts选项:

Highcharts.chart('container', {
  chart: {
    marginRight: 350 // create some space for the legend
  },
  legend: {
    verticalAlign: 'middle',
    width: 300,
    align: 'right'
  },
  firstLegend: {
    y: -25
  },
  secondLegend: {
    y: 25
  },
  series: [{
    data: [5, 6, 7],
    legendID: 0,
  }, {
    data: [2, 3, 1],
    legendID: 0,
  },
  (...)
  {
    data: [1, 8, 2],
    legendID: 1
  }, {
    data: [3, 2],
    legendID: 1
  },
  (...)
  ]
});

实时演示: http://jsfiddle.net/kkulig/r70fwasr/

可以优化此代码,使其适用于2个以上的传奇。

您可以使用Legend的ItemWidth属性。这是链接

Highcharts.chart('container', {
chart: {
    width: 500
},
title: {
    text: 'Legend <em>itemWidth</em> option'
},
legend: {
    itemWidth: 100
},
series: [{
    data: [6, 4, 2],
    name: 'First'
}, {
    data: [7, 3, 2],
    name: 'Second'
}, {
    data: [9, 4, 8],
    name: 'Third'
}, {
    data: [1, 2, 6],
    name: 'Fourth'
}, {
    data: [4, 6, 4],
    name: 'Fifth'
}, {
    data: [1, 2, 7],
    name: 'Sixth'
}, {
    data: [4, 2, 5],
    name: 'Seventh'
}, {
    data: [8, 3, 2],
    name: 'Eighth'
}, {
    data: [4, 5, 6],
    name: 'Ninth'
}]

});

http://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/highcharts/tree/master/master/samples/highcharts/legharts/legend/legend/itemwidth-80/

最新更新