I'm trying to return two different lists that are representing a chart values and labels to jsonify then to be passed to Javascript function to draw the chart, but it never worked with me. It only worked when i returned a single list for values without the labels list.
The following is my Flask script:
The following is my Javascript code containing jQuery and AJAX function:
<script>
var getValues = $.get('/data');
getValues.done(function(values,labels){
var data = {
labels: [
labels.labels
],
series: [
values.values
] };
var options = {
width : 800,
height : 400
}
var myChart = new Chartist.Bar('.ct-chart', data, options);
});
</script>
Your /data
endpoint returns JSON object which you can specify in your $.get
parameter.
$.get('/data', function(response){
var data = {
labels: response.labels,
series: [response.values]
};
var options = {
width : 800,
height : 400
}
var myChart = new Chartist.Bar('.ct-chart', data, options);
}, "json");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.