score:1

can't be sure that this is the cause of your issue without seeing the html, but the way you are passing data to your chart js is unsafe - don't do this:

const chartdata = {{ chart_data | safe }};

it's very likely you are ending up with invalid js as a result of this, because the output is not properly escaped. instead, use the json_script filter to safely render your object, and then read this in js. something like this:

{{ chart_data|json_script:"chart-data" }}
<script>
    const chartdata = json.parse(document.getelementbyid("chart-data").textcontent);
    // initialise the chart as you currently do
</script>   

note - you need to stop encoding the data as json in your view - just pass it the original list which this filter will encode safely for you.

if this doesn't fix it then it's likely that the data structure itself is not what the chart library is expecting - perhaps if you post a sample of what chartdata looks like we can see whether that looks right.


Related Query

More Query from same tag