2013-02-28 8 views
14

Le etichette sul mio grafico vengono visualizzate sopra il suggerimento, che non sembra molto bello. Ho provato a giocare con zIndex, ma senza risultato. Come posso rendere i tooltip non trasparenti? Ecco il mio jsFiddle: http://www.jsfiddle.net/4scfH/3/HighCharts: etichette visibili sul tooltip

$(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>

+1

Ecco una bella soluzione per tevfik6 https: // GitHub. it/highcharts/highcharts/issues/2528 # issuecomment-283177513 – Rachmaninoff

risposta

25

È possibile impostare useHTML e definire il proprio tooltip tramite CSS:

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

tooltip: { 
    borderWidth: 0, 
    backgroundColor: "rgba(255,255,255,0)", 
    borderRadius: 0, 
    shadow: false, 
    useHTML: true, 
    percentageDecimals: 2, 
    backgroundColor: "rgba(255,255,255,1)", 
    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; 
} 
+0

Molto bello, grazie;) –

+0

Questo è ciò che mi ha aiutato: '.highcharts-tooltip span { z-index: 9999! important; } '. Grazie mille! – silkfire

+0

@ sebastian-bochan Questa soluzione è utile quando non si utilizza un'opzione di zoom. In caso contrario, il suggerimento riguarderà il "pulsante Reset". C'è un modo semplice per risolverlo? – sherlock85

1

e se non volete daddle i problemi ci sono in useHTML, ecco il modo per farlo nel 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

si prega di fornire jsfiddle –

5

Se si imposta tooltip.backgroundColor a "RGBA (255,255,255,1) "riceverai il suggerimento con" nessuna trasparenza "

Dovrai rimuovere useHTML: true nelle impostazioni della torta.

Forcella della vostra jsfiddle: http://jsfiddle.net/kairs/Z3UZ8/1/

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

Documentation on highchart

+0

Il problema è quando si usa 'dataLabels: {useHTML: true,' –

2

ho avuto lo stesso problema. La mia soluzione Descrizione comando - useHTML = true. Descrizione comando - Formatter = codice HTML lì con un contenitore div. qui margine in valore negativo è importante 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; 
} 
+1

Welcome. Per favore spiega come questa risposta si aggiunge a quella attualmente selezionata, e l'altra già esistente. – mins

0

ho ancora avuto problemi con alcune delle soluzioni in tutto, l'impostazione z-index: 999 su .tooltip non stava avendo alcun effetto a causa dei vari div contenitore. Ma ho trovato che l'impostazione funziona correttamente (quando la legenda e la descrizione sono HTML). Non c'è bisogno di impostare altre z-indici sia:

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

2

ho avuto lo stesso problema. Le etichette erano visibili sopra il suggerimento. Rimuovere useHTML = true per le etichette ha funzionato per me.

+0

Ho avuto una situazione simile a quella del questionario, ma con un suggerimento condiviso. L'impostazione 'useHTML: false' nell'elemento' legend', come notato da @Sushil, ha fatto esattamente il trucco. Sembrava che avere "useHTML: true" impostato sia nella legenda * che nella descrizione del tool causasse stranezze indesiderate. –

0

Per Highchart i tooltip con il formato html

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

Problemi correlati