2017-06-30 1 views
0

Je dois masquer un point spécifique dans un diagramme de dispersion HighCharts. J'ai essayé d'établir la série.point.visible que ce n'est pas la bonne manière ... Voir http://jsfiddle.net/1wfotmoa/28/. Quel est le bon code à insérer pour la fonction de clic sur le bouton?Masquer un point spécifique dans un diagramme de dispersion HighCharts

$(function() { 
    $('#container').highcharts({ 
     chart: { 
      type: 'scatter', 
     }, 
     plotOptions: { 
      scatter: { 
       marker: { 
        radius: 5, 
        symbol:'circle', 
        fillColor: '#800000' 
       }, 
      } 
     }, 
    series: [{ 
     name: 'A', 
     color: "#b0b0b0", 
     data: [[38,42],[39,39],[35,45],[35,54],{x:36,y:35}] 
     }] 
}); 
var chart=$('#container').highcharts(); 
}); 
$('#button').click(function() { 
    chart.series[0].data[3].visible=(!chart.series[0].data[3].visible); 
}); 
+1

http://jsfiddle.net/55tkvfbn/ est-ce acceptable –

Répondre

1

Je peux penser à deux options

Masquer le marqueur:

$('#button').click(function() { 
    // This is an option, but you'd also need to hide the label and tooltip for it to be usable 
    // the data is still in the series 
    var data = chart.series[0].data; 
    var point = data[3]; 
    if (point.marker && point.marker.enabled == false) { 
     data[3].marker = { 
     enabled: true, 
     states: { 
      hover: { 
      enabled: true 
      } 
     } 
     }; 
    } else { 
     data[3].marker = { 
     enabled: false, 
     states: { 
      hover: { 
      enabled: false 
      } 
     } 
     }; 
    } 
    chart.series[0].setData(data); 
    }); 

Retirez le point de la série

$('#button2').click(function() { 
    // This requires that you keep your original data somewhere, so you can add it back in. 
    // I'm also using a flag to track if the data is hidden or not. 
    // You could check that the series matches the saved data if you'd rather or 
    // keep track of a point and add and remove that. 
    var series = chart.series[0]; 
    if (hidden) { 
     myData = origData.slice(); 
     series.setData(myData); 
     hidden = false; 
    } else { 
     series.removePoint(3); 
     hidden = true; 
    } 
    }); 

http://jsfiddle.net/1wfotmoa/31/

Bien que j'aime la suggestion de Deep 3015 des commentaires aussi