Skip to content

Conversation

jdsampayo
Copy link

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);
});

@winston
Copy link
Owner

winston commented Mar 24, 2016

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!

@jdsampayo
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants