Topic: How to get point data on chart click?

frank81818@hotmail.com priority asked 7 months ago


*Expected behavior*Click the bar of chart, get the label/data value of selected.

Actual behavior

jquery can get click event , how to get the clicked data value?

Resources (screenshots, code snippets etc.)enter image description hereHere's my code: const dataBar = { type: 'horizontalBar', data: { labels: names, datasets: [ { data: series, }, ], }

                };
                const eventOption = {
                    options: {
                        // This chart will not respond to mousemove, etc
                        onClick: function (e,d) {                                
                            console.log(d);
                            //how to get the label name in the _modal?
                        },
                        title: {
                            display: true,
                            text:"by status",
                        },
                        legend: {
                            display: false,
                        }
                    }                       
                };

                new mdb.Chart(document.getElementById('pills-3a'), dataBar, eventOption);  

Thanks!


Dawid Wajszczuk staff answered 7 months ago


Hi,

You can try something like this console.log(d[0]._model.label). Here is the snippet: https://mdbootstrap.com/snippets/standard/d-wajszczuk/3857972.

Keep coding,
Dawid


frank81818@hotmail.com priority answered 7 months ago


Hi Dawid, Thanks so much! It works!



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Resolved

Specification of the issue

  • User: Priority
  • Premium support: Yes
  • Technology: MDB Standard
  • MDB Version: MDB5 3.11.0
  • Device: pc
  • Browser: chrome
  • OS: windows
  • Provided sample code: No
  • Provided link: No