2013-03-20 9 views
8

Jak uzyskać wykres kołowy Highcharts, aby uzyskać wybrany identyfikator pliku?Wykresy kołowe Highcharts pobierają wybrany kod ciasta

Mam tablicę danych

var data= { name: series[i], y: Data[i],id:categorydata[i] }; 

Render wykresie

new Highcharts.Chart({ .... 

    .... 
series: [{ 
       type: 'pie', 
       name: 'Category', 
       data: data 
      }] 
    }); 

Jak uzyskać identyfikator wybranego tortu.

Robię to w

plotOptions: { 
       series: { 
        animation: false, 
        events:{ 
         click: function (event) { 
          var point = this; 
          //How do I Access the id??????? 
          alert('value: ' + this.series); 


         } 
        } 
       }, 

Odpowiedz

19

Chcesz, obsługi zdarzeń na config punktu, a nie seryjnej. Każdy klin jest punkt w jednej serii:

var data = [{ name: 'One', y: 10, id: 0 },{ name: 'Two', y: 10, id: 1 }]; 

    // some other code here... 

    series:[ 
     { 
     "data": data, 
      type: 'pie', 
      animation: false, 
      point:{ 
       events:{ 
        click: function (event) { 
         alert(this.x + " " + this.y); 
        } 
       } 
      }   
     } 
    ], 

Fiddle here.

Pełny kod działa:

var chart; 
 
point = null; 
 
$(document).ready(function() { 
 

 
    var data = [{ name: 'One', y: 10, id: 0 },{ name: 'Two', y: 10, id: 1 }]; 
 
    
 
    chart = new Highcharts.Chart(
 
    { 
 
     series:[ 
 
      { 
 
      "data": data, 
 
       type: 'pie', 
 
       animation: false, 
 
       point:{ 
 
        events:{ 
 
         click: function (event) { 
 
          alert(this.id); 
 
         } 
 
        } 
 
       }   
 
      } 
 
     ], 
 
     "chart":{ 
 
      "renderTo":"container" 
 
     }, 
 
    }); 
 
});
<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="container" style="width: 320px; height: 200px"></div>

+0

Dziękuję za wyjaśnienie tego! –

+0

Dzięki za wskazówkę! :) – ECC

+0

fiddle nie działa –

Powiązane problemy