Morris Donut图:如何在点击事件中获取元素标签

时间:2017-04-25 11:11:20

标签: javascript jquery morris.js

我正在使用Morris Donut图表,以下是我的代码:

$(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 ,该参数当前是硬编码但我想发送用户点击的元素的标签作为参数值

1 个答案:

答案 0 :(得分:0)

row.label

为您提供所点击元素的标签