javascript - Show datalabels for spiderweb only when hovered over the line or the legend? -


i creating spiderweb chart following highcharts guide. data label enabled. want hide data on load , show data when user hovers on line or hovers overs legend. how can accomplish this?

here link jsfiddle: http://jsfiddle.net/mmaharjan/fqrvq3m8/

$(function () {      $('#container').highcharts({          chart: {             polar: true,             type: 'line'         },          title: {             text: 'hello world',         },          pane: {             size: '80%'         },          xaxis: {             categories: ['sales', 'marketing', 'development', 'customer support',                 'information technology', 'administration'],             tickmarkplacement: 'on',             linewidth: 0         },          yaxis: {             gridlineinterpolation: 'polygon',             linewidth: 0,             min: 0,             max: 5,             labels: {                 enabled: false,             }         },         plotoptions: {             line: {                 datalabels: {                     enabled: true                 }             }         },         legend: {             align: 'center',             verticalalign: 'bottom',             layout: 'vertical'         },          series: [{              name: 'allocated budget',             data: [1, 2, 1, 3, 4],             pointplacement: 'on'         }, {              name: 'actual spending',             data: [3, 4, 5, 3, 2],             pointplacement: 'on'         }]      }); }); 

html:

<script src="http://code.highcharts.com/highcharts.js"></script> <script src="http://code.highcharts.com/highcharts-more.js"></script> <script src="http://code.highcharts.com/modules/exporting.js"></script> <div id="container" style="min-width: 400px; max-width: 600px; height: 400px; margin: 0 auto"></div> 

my suggestion use events mouseover , mouseout of series. these hide , show data labels. using callback method when constructing chart can hide data labels default , add additional events hovering legend items, utilizing functionality of mouseover , mouseout.

to illustrate, in chart options have:

plotoptions: {     series: {         datalabels: {             enabled: true         },         events: {             mouseover: function(event) {                 // show data labels current series                 $.each(this.data, function(i, point){                     point.datalabel.show();                 });             },             mouseout: function(event) {                 // hide data labels current series                 $.each(this.data, function(i, point){                     point.datalabel.hide();                 });             }         }     } } 

and callback function be:

$('#container').highcharts({     // options... }, function(chart) {     // hide data labels default     $.each(chart.series, function(i, series) {         $.each(series.data, function(i, point){             point.datalabel.hide();         });     });      // add events hovering legend items     $('.highcharts-legend-item').hover(function(e) {         chart.series[$(this).index()].onmouseover();     },function() {         chart.series[$(this).index()].onmouseout();     }); }); 

see this jsfiddle complete example.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -