Answer the question
In order to leave comments, you need to log in
How to transfer data from a database to Google Charts in Django?
Hello! I've been struggling all day, I can't figure out how to transfer values from the database to the google charts? data = table.objects.filter(title = key)
The table contains fields: ID (pk), name, number, date. I need to pass a date-number value to data.addRows
Google template looks like this:
google.charts.load('current', {packages: ['corechart', 'line']});
google.charts.setOnLoadCallback(drawBasic);
function drawBasic() {
var data = new google.visualization.DataTable();
data.addColumn('number', 'X');
data.addColumn('number', 'Dogs');
data.addRows([
[0, 0], [1, 10], [2, 23], [3, 17], [4, 18], [5, 9],
[6, 15], [7, 27], [8, 33], [9, 40], [10, 32], [11, 35],
[12, 30], [13, 40], [14, 42], [15, 47], [16, 44], [17, 48],
[18, 52], [19, 54], [20, 42], [21, 55], [22, 56], [23, 57],
[24, 60], [25, 50], [26, 52], [27, 51], [28, 49], [29, 53],
[30, 55]
]);
var options = {
axisTitlesPosition: 'none',
chartArea:{left:30,top:20, right:10, bottom: 20},
height: '260',
width:'450',
vAxis: {
format: 'short'
}
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
dump = serializers.serialize('python', data)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question