如何自定义带有填充的热图单元?

时间:2018-07-26 04:47:52

标签: highcharts heatmap

我尝试达到某些单元格的单元格边框和单元格内容之间的填充。但是我无法设置<rect>元素的样式。

我使用highcharts v4.2.5。并尝试了自定义数据单元的几乎所有选项,例如笔触,strokeWidth,图案填充。

我还尝试对一个数据点使用2个重叠元素,如下所示:

<rect x="0"
      y="0"
      width="20"
      height="20"
      stroke="black"
      stroke-width="1"
      fill="white">

<rect x="3"
      y="3"
      width="14"
      height="14"
      stroke="black"
      stroke-width="0"
      fill="url('#custom-pattern'">
</rect>

,但是此选项需要覆盖highcharts渲染热图单元的方式。我仍在尝试这种方式。

cell是我想要达到的。

2 个答案:

答案 0 :(得分:1)

尝试使用pointPadding(请参阅https://api.highcharts.com/highcharts/series.heatmap.pointPadding)。

我使用此选项修改了Highcharts热图演示(请参见https://jsfiddle.net/brightmatrix/qtbof29x/):

 series: [{
    name: 'Sales per employee',
    pointPadding: 10,
    data: [[0, 0, 10], [0, 1, 19], [0, 2, 8], [0, 3, 24], [0, 4, 67], [1, 0, 92], [1, 1, 58], [1, 2, 78], [1, 3, 117], [1, 4, 48], [2, 0, 35], [2, 1, 15], [2, 2, 123], [2, 3, 64], [2, 4, 52], [3, 0, 72], [3, 1, 132], [3, 2, 114], [3, 3, 19], [3, 4, 16], [4, 0, 38], [4, 1, 5], [4, 2, 8], [4, 3, 117], [4, 4, 115], [5, 0, 88], [5, 1, 32], [5, 2, 12], [5, 3, 6], [5, 4, 120], [6, 0, 13], [6, 1, 44], [6, 2, 88], [6, 3, 98], [6, 4, 96], [7, 0, 31], [7, 1, 1], [7, 2, 82], [7, 3, 32], [7, 4, 30], [8, 0, 85], [8, 1, 97], [8, 2, 123], [8, 3, 64], [8, 4, 84], [9, 0, 47], [9, 1, 114], [9, 2, 31], [9, 3, 48], [9, 4, 91]],
    dataLabels: {
        enabled: true,
        color: '#000000'
    }
}]

enter image description here

根据最终版本的外观,您可以尝试的另一种解决方案是增加borderWidth并更改borderColor以模仿单元格填充。

我希望这些信息对您有所帮助。

答案 1 :(得分:1)

基于现有的rects元素,您可以渲染另一个模仿边框的元素。在这种情况下,您还必须使用pointPadding。

events: {
  render: function() {
    var chart = this,
      series = chart.series[0],
      points = series.points,
      pointPos,
      padding = series.options.pointPadding;

    if (series.rects) {
      Highcharts.each(series.rects, function(rect) {
        rect.destroy();
      });
    }

    series.rects = [];

    Highcharts.each(points, function(point) {
      pointPos = point.shapeArgs;

      series.rects.push(chart.renderer.rect(
          pointPos.x + chart.plotLeft - padding,
          pointPos.y + chart.plotTop - padding,
          pointPos.width + padding * 2,
          pointPos.height + padding * 2)
        .attr({
          fill: 'rgba(0,0,0,0)',
          stroke: 'black',
          'stroke-width': 1,
          zIndex: 3
        })
        .add());
    });
  }
}

实时演示:https://jsfiddle.net/1r8d95js/

API参考:https://api.highcharts.com/class-reference/Highcharts.SVGRenderer#rect

相关问题