【发布时间】:2022-01-18 06:35:39
【问题描述】:
我正在使用 Chart.js 创建一组极区图表,我想更改用于显示数据的颜色的不透明度,使其略微透明。
您将在下面找到代码:
var totals = {{ class_submission_totals|safe }}
{% for t in type_qs %}
var labels_{{ t.pk }} = []
var backgroundColors_{{ t.pk }} = []
{% for b in behaviour_qs %}
{% if b.type.pk == t.pk and not b.previous %}
labels_{{ t.pk }}.push("{{ b.title }}")
backgroundColors_{{ t.pk }}.push("{{ b.primarycolour }}")
{% endif %}
{% endfor %}
{% endfor %}
new Chart("chart_{{ i.pk }}_{{ t.pk }}", {
type: "polarArea",
data: {
labels: labels_{{ t.pk }},
datasets: [{
fillOpacity: 0.3,
pointRadius: 1,
backgroundColor: backgroundColors_{{ t.pk }},
data: totals_{{ i.pk }}_{{ t.pk }}_arr,
}]
},
options: {
responsive: false,
maintainAspectRatio: true,
plugins: {
legend: {
display: true,
},
title: {
display: false,
text: 'Chart.js Polar Area Chart'
}
}
}
});
{% endfor %}
{% endfor %}
【问题讨论】:
-
您是否尝试过将 rgba() 值作为 backgroundColor 传递? w3schools.com/cssref/func_rgba.asp
-
感谢您的帮助
标签: python jquery django charts chart.js