Show modal click on Morris pie segment

We create some pie charts and donut charts using MorrisJS, for example, This. Everything is fine, but I would like a modal tooltip when I click a segment in the charts.

I'm 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 these morris pie charts, I have no elements ID, so I cannot achieve modality. Is there a way I can do this?

+4
source share
3 answers

Add this click event handler to the end of the column or pie chart.

Charts.Donut({
            element: _element,
            data: _data,
            colors: _colors,
        }).on('click', function (i, row) {  
           $('#id_modal').modal({ show: true });
        });
+4
source
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);
});
+5

onclick visualizza_modal();

            function visualizza_modal() 
                  {
                    jQuery('#id_modal').modal({
                         show: true
                      });
                  } 
0

Source: https://habr.com/ru/post/1545520/


All Articles