Adarsh Ravi
Adarsh Ravi

Reputation: 953

Morris Donut Graph: How to get label of element on click event

I am using Morris Donut chart and the following is my code:

$(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);
            }
        });
    });
});

And as you see in the click event I am trying to send a parameter ItemName which currently is hard coded but I want to send the label of the element on which the user clicks as the parameter value.

Upvotes: 0

Views: 618

Answers (1)

Niebvelungen
Niebvelungen

Reputation: 1

row.label

gives you the label of the clicked Element

Upvotes: 0

Related Questions