I have to pass two separate value, data and label, from a python list to chartjs.
Here my stuff:
data = [[title], [identifier], [subject], [type], [preview], [isReferencedBy], [licence], [licenseMetadata]]
label =["title", "identifier", "subject", "type", "preview", "isReferencedBy", "licence", "licenseMetadata"]
merge_dataLabel = dict(zip(label,data))
print(merge_dataLabel)
Values in data are the results from a sum, values in label are the corresponding label of each result. To associate each label to the corresponding result I'm using zip with this result:
{'title': [309], 'identifier': [309], 'subject': [1], 'type': [309], 'preview': [0], 'isReferencedBy': [0], 'licence': [0], 'licenseMetadata': [0]}
Before wasting time to integrate chartjs I tried then to render the result via a template:
return render ( request , 'completeness.html' , {'merge_dataLabel': merge_dataLabel})
Template:
<ul>
{% for item in merge_dataLabel %}
<li>{{ item }}</li>
{% endfor %}
</ul>
However only the label are rendered without the relative values. So I think that there's something wrong in what I did.
Suggestions?
Regards
The dictionary variable only shows the key until you explicitly ask for value as shown.
<ul> {% for item,value in merge_dataLabel.items %} <li>{{ item }}:{{ value }}</li> {% endfor %} </ul>
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.