Updating DB with Chart JS

Updating DB with Chart JS
0

#1

Greetings,

I am trying to add a function to the onClick listener on Chart JS labels. The function exists as soon as it hits the call to the DB. I get nothing back and the rest of the code does not execute. So the click executes on the front end calls to a function in a js file that should then talk to the DB. This is my code to incorporate the function to the chart js onClick.

        legend:{
            position:'bottom',
            onClick: function(e, legendItem) {
                Poll.findById('58e20fbea059d106a74ff2e6',function(err,docs){
                    if(err)     console.error(err);
                                var index = legendItem.index;
                                var ci = this.chart;
                                ci.data.datasets[0].data[index] +=1;
                                ci.update();
                });
            }
        }```

Is it not possible to access the DB from the db without post calls?

#2

What’s the error that you are getting? Have you checked the logs in the console? This click function that you execute should be making a request to your server, which can then interact with your DB. You connect to the DB through the server so it should be accessed from there.