javascript - Redrawing google chart -
hello guys developing web application google chart . want redraw chart on each times user makes selection , here code
//loading google api google.load("visualization", "1", { packages: ["corechart"] }); google.setonloadcallback(drawallcharts); function drawallcharts() { //sending server request $.post("index.php", { type: "result" }, function (data, status) { handleresponse(data, true) }); } //this function handles response of server json string function handleresponse(jsonstring, init) { //parsing json string object var obj = json.parse(jsonstring); var arraydata = objtostrin(obj); //converting obj array console.log(arraydata); drawdistchart(arraydata, init); } //this function draws first chart function drawdistchart(arraydata, init) { //preparing data var datadistribution = new google.visualization.datatable(); datadistribution.addcolumn('string', "fitness"); datadistribution.addcolumn('number', "physical"); datadistribution.addcolumn('number', "emotional"); datadistribution.addrows(arraydata); //setting few properties var options = { title: 'no of people', backgroundcolor: { fill: 'transparent' }, haxis: { title: 'wellness score', slantedtext: true, titletextstyle: { color: 'red' } } }; //drawing chart var chart = new google.visualization.columnchart(document.getelementbyid('chart_div')); chart.draw(datadistribution, options); }
but nothing happens , please help
you need add "select" event listener handle user selecting chart elements:
google.visualization.events.addlistener(chart, 'select', function () { var selection = chart.getselection(); if (selection.length) { // user clicked on chart element // row/column information selection[n].row/column // selection // redraw chart chart.draw(datadistribution, options); } });
Comments
Post a Comment