userdata = db.execute("SELECT * FROM history WHERE id = :id", id=session["user_id"])
[{'id': 1, 'weight': 180, 'calories': 2100, 'rewards': 1, 'date': '2018-04-14'}, {'id': 1, 'weight': 185, 'calories': 1800, 'rewards': -1, 'date': '2018-04-15'}, {'id': 1, 'weight': 180, 'calories': 1600, 'rewards': 1, 'date': '2018-04-13'}, {'id': 1, 'weight': 180, 'calories': 1900, 'rewards': -2, 'date': '2018-04-12'}, {'id': 1, 'weight': 186, 'calories': 1111, 'rewards': 5, 'date': '2018-04-16'}, {'id': 1, 'weight': 184, 'calories': 1200, 'rewards': 5, 'date': '2018-04-17'}, {'id': 1, 'weight': 184, 'calories': 1400, 'rewards': 3, 'date': '2018-04-18'}, {'id': 1, 'weight': 180, 'calories': 2100, 'rewards': -4, 'date': '2018-04-11'}]
@app.route("/charting", methods=["GET", "POST"])
@login_required
def charting():
rows = db.execute("SELECT * FROM history WHERE id = :id", id=session["user_id"])
jsonData = (json.dumps(rows))
return render_template("charting.html"), jsonData
google.charts.load('current', {
packages: ['corechart']
}).then(function () {
// create chart
var container = $('#chart_div').get(0);
var chart = new google.visualization.LineChart(container);
var options = {
legend: {
position: 'top'
}
};
// create data table
var data = new google.visualization.DataTable();
data.addColumn('string', 'Date');
data.addColumn('number', 'Weight');
data.addColumn('number', 'Calories');
// get data
$.ajax({
url: '/charting',
dataType: 'json'
}).done(function (jsonData) {
});
// load json data
function loadData(jsonData) {
$.each(jsonData, function(index, row) {
data.addRow([
row.date,
row.weight,
row.calories
]);
});
drawChart();
}
// draw chart
$(window).resize(drawChart);
function drawChart() {
chart.draw(data, options);
}
});
--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/81b7eb7c-3e46-40eb-9c65-b122ce0268e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To post to this group, send email to google-visua...@googlegroups.com.