简体   繁体   English

Morris.js使用Django模板数组显示不正确的折线图

[英]Morris.js displaying incorrect line graph with Django template array

I recently heard of Morris.js and attempted to include a line graph in a website I was working on. 最近,我听说了Morris.js,并尝试在我正在开发的网站中包含折线图。 However, whenever I feed elements from my dates array to the data component of Morris.line(), the graph fails to display properly and instead displays a bunch of weird dates. 但是,每当我将日期数组中的元素输入到Morris.line()的数据组件中时,图形都无法正确显示,而是显示了一堆怪异的日期。

The relevant snippet of my JS code is shown here: 我的JS代码的相关代码片段显示在此处:

    Morris.Line({
        element: 'line',
        data: [
            { d: {{ dates.0 }}, v: {{ polar.0 }}},
            { d: {{ dates.1 }}, v: {{ polar.1 }}},
            { d: {{ dates.2 }}, v: {{ polar.2 }}},
            { d: {{ dates.3 }}, v: {{ polar.3 }}},
            { d: {{ dates.4 }}, v: {{ polar.4 }}},
        ],
        xkey: 'd',
        ykeys: ['v'],
        labels: ['Polarity']
    });

And the result can be seen here: 结果可以在这里看到:

http://i.imgur.com/BQtPxvr.png http://i.imgur.com/BQtPxvr.png

The dates that were supplied to the line graph were simply '2005', '2006', '2007', '2008', and '2009', in order to test the functionality of the graph. 为了测试图的功能,提供给折线图的日期只是“ 2005”,“ 2006”,“ 2007”,“ 2008”和“ 2009”。 How can I fix this? 我怎样才能解决这个问题?

通过将{{ dates.x }}元素括在引号中并在函数中包含parseTime: false参数,可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM