【问题标题】:Django Chart.jsDjango Chart.js
【发布时间】:2018-05-09 10:24:35
【问题描述】:

我正在尝试设置 Chart.js 以在我的项目中使用。 这是example,我正在尝试复制,我得到this 我使用的是 PyCharm,所以很容易下载所有库,我在 Installed aps 中添加了 chart.js

我的 test.html:

{% load staticfiles %}
<html>
    <head>
        <title>django-chartjs line chart demo</title>
        <!--[if lte IE 8]>
            <script src="{% static 'js/excanvas.js' %}"></script>
        <![endif]-->
    </head>
    <body>
        <h1>Some Line Charts loaded in Ajax!</h1>

        <canvas id="myChart" width="500" height="400"></canvas>

        <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
        <script type="text/javascript" src="{% static 'js/Chart.min.js' %}"></script>
        <script type="text/javascript">
            $.get('{% url "line_chart_json" %}', function(data) {
                var ctx = $("#myChart").get(0).getContext("2d");
                new Chart(ctx, {
                    type: 'line', data: data
                });
            });
        </script>
    </body>
</html>

我的看法:

   class LineChartJSONView(BaseLineChartView):
        def get_labels(self):
            """Return 7 labels for the x-axis."""
            return ["January", "February", "March", "April", "May", "June", "July"]

        def get_providers(self):
            """Return names of datasets."""
            return ["Central", "Eastside", "Westside"]

        def get_data(self):
            """Return 3 datasets to plot."""

            return [[75, 44, 92, 11, 44, 95, 35],
                    [41, 92, 18, 3, 73, 87, 92],
                    [87, 21, 94, 3, 90, 13, 65]]
    line_chart = TemplateView.as_view(template_name='main/mark/test.html')
    line_chart_json = LineChartJSONView.as_view()

【问题讨论】:

    标签: django chart.js


    【解决方案1】:

    因为您正在查看 json 结果;你正在做这样的事情:

    http://localhost:8000/yourapp/line_chart/json
    

    你应该在哪里做:

    http://localhost:8000/yourapp/line_chart
    

    【讨论】:

      猜你喜欢
      • 2018-09-27
      • 2023-03-30
      • 1970-01-01
      • 2020-11-25
      • 1970-01-01
      • 2020-06-25
      • 2018-01-26
      • 2018-12-04
      • 2022-01-17
      相关资源
      最近更新 更多