HighCharts: Labels visible over tooltip

前端 未结 7 1699
离开以前
离开以前 2020-12-01 09:45

Labels on my chart are showing over tooltip, which doesn\'t look very nice. I tried to play with zIndex, but to no result. How can I make tooltips not transpare

相关标签:
7条回答
  • 2020-12-01 10:04

    and if you dont want to daddle in the problems there are in useHTML, here is the way to do it in the 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) {
    
      } 
     });
    
    0 讨论(0)
  • 2020-12-01 10:05

    I had same issue. My solution. Tooltip - useHTML = true. Tooltip - Formatter = HTML code there with one div container. here margin in negative value is important in css.

    tooltip: {
        backgroundColor: "rgba(255,255,255,1)",
        useHTML: true,
        formatter: function() {
            var html = [];
            html.push('<b>Correlation to ' + this.point.p + '</b><br>');
            if (null != this.point.associatedPoints 
                    && typeof this.point.associatedPoints != 'undefined' 
                    && this.point.associatedPoints.length > 0) {
                $.each(this.point.associatedPoints, function(i, associatedPoint) {
                    html.push('Responses: ' + associatedPoint.nFormatted);
                });
            }
            return '<div class="tooltip-body">' + html.join('') + '</div>';
        }
    

    CSS:

    .highcharts-tooltip span {
        z-index: 9999 !important;
        top:2px !important;
        left:2px !important;
    }
    .highcharts-tooltip span .tooltip-body{
        background-color:white;
        padding:6px; 
        z-index:9999 !important;
        margin-bottom:-14px;
        margin-right:-14px;
    }
    
    0 讨论(0)
  • 2020-12-01 10:09

    I still had issues with some of the solutions around, setting z-index: 999 on .tooltip wasn't having any effect because of the various container divs. But, I've found setting this works nicely (when legend and tooltip are HTML). No need for setting other z-indexes either:

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

    0 讨论(0)
  • 2020-12-01 10:11

    You can set useHTML and define your own tooltip via 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;
    }
    

    Explanation: when you set useHTML to true, it displays the tooltip text as HTML on the HTML layer, but still draws an SVG shape in the highcharts display SVG for the box and arrow. You would end up with data labels looking like they were drawn on top of the tooltip, but the tooltip text itself on top of the data labels. The config options above effectively hide the SVG tooltip shape and build and style the tooltip purely with HTML/CSS. The only down-side is that you lose the little "arrow" pointer.

    0 讨论(0)
  • 2020-12-01 10:17

    If you set tooltip.backgroundColor to "rgba(255,255,255,1)" you'll get tooltip with "no transparency"

    You will have to remove useHTML: true in the pie settings.

    Fork of your jsfiddle: http://jsfiddle.net/kairs/Z3UZ8/1/

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

    Documentation on highchart

    0 讨论(0)
  • 2020-12-01 10:17

    I had the same problem. The Labels were visible over the tooltip. Removing useHTML=true for the labels worked for me.

    0 讨论(0)
提交回复
热议问题