Answer the question
In order to leave comments, you need to log in
How to properly build a python dictionary for google charts?
It is necessary to form a dictionary for google charts. But it has a strange design, and the library responds
Cannot read property '1' of undefined
coun = Country.objects.values('country')
link = Proxy.objects.filter(country__in=coun).order_by('country').values_list('country').annotate(Count('country'))
dicts = ({'c':[{'v': x[0]}, {'v': x[1]}]} for x in link)
return HttpResponse(dicts)
jQuery.get("/cantry/",
function(data) {
dd = data;
//console.log(dd);
var data = new google.visualization.DataTable({
'cols': [
{'label':'Страна', 'type':'string'},
{'label':'Число', 'type':'number'}
],
'rows': [
// {'c':[{'v':'24.05.2014'},{'v':3}]}, //<--Но в словаре который приходит нет запятых js.
// {'c':[{'v':'25.05.2014'},{'v':1}]},
// {'c':[{'v':'25.05.2014'},{'v':1}]}
dd
]
});
var options = {
title: '',
chartArea:{left:0,top:0,width:'100%',height:'75%'},
legend: {position: 'bottom', maxLines: '2'}
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
alert(dd);
}
);
Answer the question
In order to leave comments, you need to log in
The answer is
var google_data = {
"cols": [{
label: 'Страна', "type": "string"
}, {
"type": "string"
}],
rows: []
};
for(var i=0;i<data.length;i++){
google_data.rows.push({c:[{v:data[i]}, {v:parseInt(data[i])}]});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question