[英]How to pass value from a python list to a chart?
I have to pass two separate value, data and label, from a python list to chartjs.我必须将两个单独的值,data 和 label,从 python 列表传递给 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. data 中的值是求和的结果,label 中的值是每个结果对应的 label。 To associate each label to the corresponding result I'm using zip with this result:要将每个 label 关联到相应的结果,我使用 zip 与此结果:
{'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:在浪费时间集成 chartjs 之前,我尝试通过模板渲染结果:
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.然而,只有 label 被渲染,没有相对值。 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.