我建议您将一组已知数据随机化(以排除无意义值),如下所示:
{% for organization in organizations %}
{
value: {{ organization.value }},
color: "{{ random(['#H54924', '#F36252', '#F56954']) }}"
label: "{{ organization.name }}"
},
{% endfor %}
编辑:
对于纯随机值,可以尝试以下方法:
{% set values = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']%}
{% for organization in organizations %}
{
value: {{ organization.value }},
color: "#{{random(values)~ random(values)~ random(values)~ random(values)~ random(values)~ random(values) }}",
label: "{{ organization.name }}"
},
{% endfor %}
{{ '#' ~ random(values) ~ random(values) ~ random(values) ~ random(values) ~ random(values) ~ random(values) }}
Here 一个工作示例
希望有帮助