Skip to content

Instantly share code, notes, and snippets.

@jparker
Created March 6, 2014 00:41
Show Gist options
  • Save jparker/9379914 to your computer and use it in GitHub Desktop.
Save jparker/9379914 to your computer and use it in GitHub Desktop.
Load remote data as DataTable for Google Chart
jQuery.ajax
async: false
dataType: 'json'
url: '/path/to/data.json'
success: (data) ->
google.load 'visualization', '1', {packages: ['corechart']}
google.setOnLoadCallback ->
table = new google.visualization.DataTable()
table.addColumn 'datetime', 'Timestamp'
table.addColumn 'number', 'Memory Total'
jQuery.each data, (i, row) ->
table.addRow [new Date(row.timestamp), row.memory_total]
options = {title: 'Memory Usage', vAxis: {format: '# MB', minValue: 0}}
chart = new google.visualization.LineChart document.getElementById 'chart_div'
chart.draw table, options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment