0

I'm working on a project in Django, for part of it I'm trying to use Googles chart api, which uses a Javascript function to plot the graph. So what I'm trying to do is generate the graph data in my views.py and then pass the data through the context variables to the script. To test this I tried to do:

graphplot = [['Age', 'Weight'],[ 8,      12],[ 4,      5.5],[ 11,     14],[ 4,      5],[ 3,      3.5],[ 6.5,    7]]

context = {
    "graphplot": graphplot,
}

in my views.py then I have:

var data = google.visualization.arrayToDataTable({{graphplot}});

in my template, however this doesn't seem to work.

When I do:

var data = google.visualization.arrayToDataTable([
  ['Age', 'Weight'],
  [ 8,      12],
  [ 4,      5.5],
  [ 11,     14],
  [ 4,      5],
  [ 3,      3.5],
  [ 6.5,    7]
]);

It does show the graph so I know it's not a problem with the JavaScript.

Any help would be appreciated

user2320239
  • 1,021
  • 2
  • 18
  • 43

1 Answers1

0

Try this, It should work.

var plot_data = {{graphplot}};

var data = google.visualization.arrayToDataTable(plot_data);
jatinkumar patel
  • 2,920
  • 21
  • 28