google_visualr icon indicating copy to clipboard operation
google_visualr copied to clipboard

Make graph variables accesible with the window scope

Open jdsampayo opened this issue 9 years ago • 2 comments

Scope the variables graph, options and data_table to the window object, to make posible the update of a graph dynamically from external sources

Use cases:

  • Update third column of first series with value 10000 of expenses chart, received by socket or ajax request
window.data_table_chart_expenses.setValue(2,1,10000);
window.chart_expenses.draw(window.data_table_chart_expenses, window.options_chart_expenses);

ezgif com-crop

  • Redraw the dynamically changed data on resize
$(window).on('debouncedresize', function(event) {
  window.chart_expenses.draw(window.data_table_chart_expenses, window.options_chart_expenses);
});

jdsampayo avatar Mar 23 '16 23:03 jdsampayo

Hi! Would listeners work for you in this case? https://developers.google.com/chart/interactive/docs/events#overview.

I have already added for listeners support on https://github.com/winston/google_visualr/blob/master/lib/google_visualr/base_chart.rb#L55

Thanks!

winston avatar Mar 24 '16 03:03 winston

Hello Winston,

Thank you very much for your feedback, I had read the links you provided me, unfortunately I'm unable to see how to implement the redraw of the graph with only listeners.

As I understand the draw() function needs the data_table and the options to redraw it with the same look and feel, that is the reason I exposed the data_table to update the data and options to preserve the styles to the window scope.

Without exposing those variables, how can I redraw the graph updating the data_table data (adding rows or columns) with the listeners implementation?

Best regards.

jdsampayo avatar Mar 28 '16 15:03 jdsampayo