在Highcharts列和饼图中悬停时,边框部分隐藏

时间:2017-12-09 00:06:11

标签: css svg highcharts

当我将鼠标悬停在堆积条形图或饼图的片段上时,我希望片段的所有方向都有黑色边框。但是,对于堆叠的柱形图和饼图,特别是悬停区段的一侧保留了白色边框,将其与下一个区段分开:

incomplete bar segment border

是否有Highcharts设置或CSS样式,以便在将鼠标悬停在该细分上时,可以在细分受众群周围显示边框?

图表设置和JSFiddle链接:

柱形图:http://jsfiddle.net/nyh22g2e/1/

柱形图设置:

Highcharts.chart('container', {
  chart: {
    type: 'pie'
  },
  xAxis: {
    categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
  },

  plotOptions: {
    series: {
      states: {
        hover: {
          brightness: 0,
          borderColor: 'black',
          halo: false,
        }
      }
    }
  },

  series: [{
    data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
  }]
});

饼图:http://jsfiddle.net/djpjtmzg/

饼图设置:

Highcharts.chart('container', {
  chart: {
    type: 'pie'
  },
  xAxis: {
    categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
  },

  plotOptions: {
    series: {
      states: {
        hover: {
          brightness: 0,
          borderColor: 'black',
          halo: false,
        }
      }
    }
  },

  series: [{
    data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
  }]
});

1 个答案:

答案 0 :(得分:0)

边框的某些部分不可见,因为它们与"常规"重叠。其他列的边界。在非悬停状态下将borderWidth设置为0似乎可以解决此问题:

plotOptions: {
    series: {
        stacking: 'normal',
        borderWidth: 0, // regular border disabled
        states: {
            hover: {
                brightness: 0,
                borderColor: 'black',
                borderWidth: 1 // enable border on hover
            }
        }
    }
}

现场演示: http://jsfiddle.net/kkulig/1kh7kvqq/

API参考: https://api.highcharts.com/highcharts/plotOptions.column.borderWidth

修改

我注意到在Highcharts论坛上出现了更好的解决方案:https://forum.highcharts.com/highcharts-usage/stacked-bar-and-pie-border-on-hover-t39961/

它使用mouseOver事件来增加悬停元素的zIndex

底部边框问题:

删除悬停系列的"clip-path" SVG属性可解决问题:

  events: {
    mouseOver: function() {
      this.update({
        zIndex: 1
      });
      this.group.attr({
        "clip-path": ""
      });
    }
  },

现场演示: http://jsfiddle.net/kkulig/p9cqzs3f/