I'm not good in javascript. I have google charts with data. And I need to add data via loop in javascript:
for (let i = 0; i < 3; i ) {
data.addRow(
['{{list[i][0]}}',
{ v: {{list[i][1][0]}}, f: '{{list[i][1][1]}}' }]
);
}
But it wrote me an error:
UndefinedError
jinja2.exceptions.UndefinedError: list object has no element Undefined
Can you advice me please, what I can do with it?
CodePudding user response:
I'm not too familiar with the Google Charts API, but from the looks of it, you have a syntax error since you're literally passing the string '{{list[i][0]}}'
to the data.addrow()
method.
Try this instead and let me know if it works:
for (let i = 0; i < 3; i ) {
data.addRow([
list[i][0],
{
v: list[i][1][0],
f: list[i][1][1]
}
]);
}
CodePudding user response:
I have found the answer. Try like this:
{% for i in range(list|length) %}
data.addRow(
['{{list[i][0]}}',
{ v: {{list[i][1][0]}}, f: '{{list[i][1][1]}}' }]
);
{% endfor %}
It's no javascript, I know. But helped me to solve the problem.