2017-04-25 49 views
0

我使用莫里斯圓環圖和下面是我的代碼:莫里斯甜甜圈圖表:如何獲得元素的標籤上點擊事件

$(document).ready(function() { 

    var data_dg = @Html.Raw(Json.Encode(Model)) 
    donut_chart_data = []; 

    for (var i = 0; i < data_dg.length; i++) { 
     var iName = data_dg[i].ItemName; 
     var Cnt = data_dg[i].Count; 

     donut_chart_data[i] = { 
      label: iName, 
      value: Cnt 
     }; 

    } 

    Morris.Donut({ 
     element: 'donut-graph', 
     colors: ['#D3696C', '#db9b9d', '#f74c52', '#632527', '#a3304f', '#820202', '#6d4141'], 
     data: donut_chart_data 
    }); 


    $("#donut-graph").click(function (i, row) { 

     var ItemName = 'Paper'; 
     $.ajax({ 
      type: "POST", 
      url: '/Home/GetDataByID', 
      contentType: "application/json; charset=utf-8", 
      data: '{ ItemName: "'+ItemName+'" }', 
      dataType: "json", 
      success: function (response) { 
       alert('success'); 
      }, 
      failure: function (response) { 
       alert(response.responseText); 
      }, 
      error: function (response) { 
       alert(response.responseText); 
      } 
     }); 
    }); 
}); 

而當你在點擊事件看我試圖發送一個參數ItemName目前硬編碼,但我想發送用戶點擊的元素的標籤作爲參數值。

回答