Reputation: 2542
so basically ive been trying to use Flask to display charts in a 2x3 grid. (6 charts in total) but i cant even get one up.
Im looking at this one: http://www.highcharts.com/demo/line-time-series
The default example seems to work. However, but when i host my own data at localhost:5000/data and use highcharts to load it, nothing appears at all. I think the data is the wrong format.
my data is of the form
{'2016-04-22': 3,
'2016-04-25': 1,
'2016-04-26': 1,
'2016-04-29': 12,
'2016-05-03': 2}
but the data in that link is
?([
[Date.UTC(2013,5,2),0.7695],
[Date.UTC(2013,5,3),0.7648],
[Date.UTC(2013,5,4),0.7645],
[Date.UTC(2013,5,5),0.7638]]
Here's a fiddle link (ignore data.csv, its supposed to be data) https://jsfiddle.net/d8xgno5d/
Anyone got any pointers? really desperate now. I've tried csv, but i dont know how to load csv data from a link into highchars.
all help will really be appreciated :)
thank you! :)
Upvotes: 0
Views: 614
Reputation: 2542
For those interested, I managed to solve it for the load csv method.
By replacing the first line of .getJSON with
$.get('http://localhost:5000/data.csv',function(csv){
you can load CSV's instead, which is much easier when you can use pandas in python.
Here's the full code for the javascript file if needed.
$(document).ready(function () {
$.get('http://localhost:5000/data.csv',function(csv){
$('#workload').highcharts({
chart: {
zoomType: 'x'
},
data: {
csv: csv
},
title: {
text: 'Evie Workload'
},
subtitle: {
text: document.ontouchstart === undefined ?
'Click and drag in the plot area to zoom in' : 'Pinch the chart to zoom in'
},
xAxis: {
type: 'datetime'
},
yAxis: {
title: {
text: 'Emails'
}
},
legend: {
enabled: false
},
credits:{
enabled:false
},
plotOptions: {
area: {
fillColor: {
linearGradient: {
x1: 0,
y1: 0,
x2: 0,
y2: 1
},
stops: [
[0, Highcharts.getOptions().colors[0]],
[1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
]
},
marker: {
radius: 2
},
lineWidth: 1,
states: {
hover: {
lineWidth: 1
}
},
threshold: null
}
},
series: [{
type: 'area',
name: 'Workload',
}]
});
});
});
Upvotes: 2