-1

I need to add to the array Java Script informations from Python list

list.py

workflows = [{"date": '2012', "rate": 5}, {"date": '2011', "rate": 4}]
return render_template('modules/general/backoffice/rating.html',  workflows=workflows)

rating.html

{% block module_scripts %}
    <script>
            $(function () {
                "use strict";
                // LINE CHART
                var line = new Morris.Line({
                    element: 'line-chart',
                    resize: true,
                    data: [
                        {% for workflow in workflows %}
                            {time: {{ workflow.date }}, rate: {{workflow.rate}} }
                        {% endfor %}
                    ],
                    xkey: 'time',
                    ykeys: ['rate'],
                    labels: ['Rate'],
                    lineColors: ['#3c8dbc'],
                    hideHover: 'auto'
                });
            });
        </script>
{% endblock %}

But it does not work.

I've seen a lot of posts about my problem, but they are not suitable.

One of them Django FOR LOOP in JavaScript

Community
  • 1
  • 1
  • 2
    What was the error (in the browser's console) ? One mistake that I found is you are missing `,` after each array item. You have to put `,` at the end: `{time: {{ workflow.date }}, rate: {{workflow.rate}} },` – Yohanes Gultom Feb 08 '17 at 07:44
  • 1
    @YohanesGultom this script is designed for LINE CHART. In the loop must be added to the coordinates to create a chart. When I manually add the coordinates of all the works. The console does not have any errors. –  Feb 08 '17 at 07:52
  • 1
    @YohanesGultom thanks for "browser's console" –  Feb 08 '17 at 08:02

1 Answers1

-1
<script>
        $(function () {
            "use strict";
            // LINE CHART
            var line = new Morris.Line({
                element: 'line-chart',
                resize: true,
                data: [
                    {% for workflow in workflows %}
                        {time: '{{ workflow.date }}', rate: {{workflow.rate}} },
                    {% endfor %}
                ],
                xkey: 'time',
                ykeys: ['rate'],
                labels: ['Rate'],
                lineColors: ['#3c8dbc'],
                hideHover: 'auto'
            });
        });
    </script>