Updating graph data already instantiated

0

I'm using Google Charts and I need to update a map that is already instantiated as a valid map , I actually want it when I click the refresh the data from within a map button.

Today I'm doing it this way:

var dataGraf = google.visualization.arrayToDataTable(parsVal);
var chart = document.getElementById('curve_chart');
chart.draw(dataGraf);

But nothing happens. For me to instantiate my map I used the following commands:

google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);

function drawChart() {
  var data = google.visualization.arrayToDataTable(parsVal);
  var options = {
    title: 'Membros x Visitantes',
    curveType: 'function',
    legend: { position: 'bottom' }
  };
 var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
 chart.draw(data, options);
}

How can I do to update, just when I click the button. Remembering that my dataGraf has my array with the new values.

I did a JsFiddle to exemplify my problem.

    
asked by anonymous 12.07.2016 / 21:35

1 answer

0

When you click the button you redraw the entire graph.

$("#botaoAtualizar").click(function(){
    redrawChart();
});

Use the function you have done by passing the new data.

function drawChart() {

  var dataGraf = google.visualization.arrayToDataTable(parsVal);

  var options = {
    title: 'Membros x Visitantes',
    curveType: 'function',
    legend: { position: 'bottom' }
  };

 var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
 chart.draw(dataGraf, options);

}
    
07.09.2016 / 06:17