HighCharts:标签在工具提示上可见

时间:2013-02-28 07:57:44

标签: javascript jquery highcharts tooltip labels

我的图表上的标签显示在工具提示上,看起来不太好。我尝试使用zIndex,但没有结果。如何使工具提示不透明?这是我的jsFiddle:http://www.jsfiddle.net/4scfH/3/

$(function() {
  var chart;
  $(document).ready(function() {
    chart = new Highcharts.Chart({
      chart: {
        renderTo: 'graf1',
        plotBackgroundColor: null,
        plotBorderWidth: null,
        plotShadow: false
      },

      title: {
        margin: 40,
        text: 'Podíl všech potřeb'
      },
      tooltip: {
        //pointFormat: '<b>{point.y} Kč [{point.percentage}%]</b>',
        percentageDecimals: 2,
        backgroundColor: "rgba(255,255,255,1)",
        formatter: function() {
          return this.point.name + '<br />' + '<b>' + Highcharts.numberFormat(this.y).replace(",", " ") + ' Kč [' + Highcharts.numberFormat(this.percentage, 2) + '%]</b>';
        }
      },
      plotOptions: {
        pie: {
          allowPointSelect: true,
          cursor: 'pointer',
          dataLabels: {
            enabled: true,
            color: '#000000',
            connectorWidth: 2,
            useHTML: true,
            formatter: function() {
              return '<span style="color:' + this.point.color + '"><b>' + this.point.name + '</b></span>';
            }
          }
        }
      },
      series: [{
        type: 'pie',
        name: 'Potřeba',
        data: [
          ['Firefox', 45.0],
          ['IE', 26.8], {
            name: 'Chrome',
            y: 12.8,
            sliced: true,
            selected: true
          },
          ['Safari', 8.5],
          ['Opera', 6.2],
          ['Others', 0.7]
        ]
      }]
    });
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<div id="graf1" style="width: 400px; height: 250px; float:left"></div>

6 个答案:

答案 0 :(得分:28)

您可以设置useHTML并通过css定义自己的工具提示:

http://jsfiddle.net/4scfH/4/

tooltip: {
    borderWidth: 0,
    backgroundColor: "rgba(255,255,255,0)",
    borderRadius: 0,
    shadow: false,
    useHTML: true,
    percentageDecimals: 2,
    formatter: function () {
        return '<div class="tooltip">' + this.point.name + '<br />' + '<b>' + Highcharts.numberFormat(this.y).replace(",", " ") + ' Kč [' + Highcharts.numberFormat(this.percentage, 2) + '%]</b></div>';
    }
},

CSS

.label {
    z-index: 1 !important;
}

.highcharts-tooltip span {
    background-color: white;
    border:1 px solid green;
    opacity: 1;
    z-index: 9999 !important;
}

.tooltip {
    padding: 5px;
}

说明:当您将useHTML设置为true时,它会在HTML图层上将工具提示文本显示为HTML,但仍会在高位图显示SVG中为框和箭头绘制SVG形状。您最终会看到数据标签看起来像是在工具提示之上绘制的,但工具提示文本本身位于数据标签之上。上面的配置选项有效地隐藏了SVG工具提示形状,并纯粹使用HTML / CSS构建和设置工具提示。唯一的缺点是你失去了一个小“箭头”指针。

答案 1 :(得分:5)

如果将tooltip.backgroundColor设置为“rgba(255,255,255,1)”,您将获得“无透明度”的工具提示

您必须在饼图设置中删除useHTML:true。

你的jsfiddle的分叉:http://jsfiddle.net/kairs/Z3UZ8/1/

tooltip: {
  backgroundColor: "rgba(255,255,255,1)"
}

Documentation on highchart

答案 2 :(得分:2)

我遇到了同样的问题。标签在工具提示上可见。删除useHTML = true用于为我工作的标签。

答案 3 :(得分:1)

如果你不想讨论问题,那就是使用HTML,这是在svg中做到这一点的方法:

 Highcharts.wrap(Highcharts.Chart.prototype, 'redraw', function(proceed, animation) {
  proceed.call(this, animation);
  try {
   if (this.legend.options.floating) {
    var z = this.legend.group.element, zzz = z.parentNode;
    zzz.removeChild(z);
    zzz.appendChild(z); //zindex in svg is determined by element order
   }
  } catch(e) {

  } 
 });

答案 4 :(得分:0)

我仍然遇到一些解决方案的问题,在.tooltip上设置z-index:999因为各种容器div而没有任何效果。但是,我发现设置很好(当图例和工具提示是HTML时)。无需设置其他z索引:

.highcharts-legend { z-index: -1; }

答案 5 :(得分:0)

对于具有html格式的Highchart工具提示

Highchart config

tooltip: {
    borderWidth: 0,
    backgroundColor: "rgba(255,255,255,0)",
    shadow: false,
    useHTML: true
    ........
},

CSS:

.highcharts-tooltip>span {
    background-color: #fff;
    border: 1px solid #172F8F;
    border-radius: 5px;
    opacity: 1;
    z-index: 9999!important;
    padding: .8em;
    left: 0!important;
    top: 0!important;
}

Screenshot