Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display modal on clicking a Morris pie segment

Am creating some pie charts and donut charts using MorrisJS like This All is well but I would like to have a modal pop up when I click a segment in the charts.

Am used to doing modals this way

<!-- Link to shw Modal -->
<a href="#modal-id"  class="btn btn-success" data-toggle="modal" > Click to show modal</a>

<!-- Modal -->
<div class="modal fade" id="modal-id" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
...
</div>

Now in this morris pie charts, I dont have the ID elements hence I am unable to achieve the modal. Is there a way I can do it?

like image 889
Alexxio Avatar asked Jan 11 '23 08:01

Alexxio


1 Answers

var donut = new Morris.Donut({
    element: 'sales-chart',
    resize: true,
    colors: ["#3c8dbc", "#f56954", "#00a65a", "#0CDE47", "#076ABE", "#998373", "#378238"],
    data: [
        {label: "Android", value: 12},
        {label: "iPhone", value: 30},
        {label: "Other", value: 20}
        ],
        labelColor: '#303641',
        hideHover: 'auto',
        formatter: function (x) { 
            return x + ' % ';
        }
}).on('click', function(i, row){
    alert(row.label);
    console.log(i, row);
});
like image 175
Vivek Avatar answered Jan 22 '23 07:01

Vivek