高图-将字典作为时间轴系列的数据传递

时间:2019-08-30 22:14:07

标签: python django highcharts

因此,我已经使用Highcharts相当一段时间了,并且我试图制作一个时间表图表。我在互联网上看到了一些示例代码,并注意到data属性基本上是一个字典。因此,我使用python / pandas等从某些数据中制作了一个字典,它看起来像这样:

[{'name': '2017-12-07 - Chat',
  'label': 'some text',
  'description': 'some text'},
 {'name': '2017-12-15 - Whatsapp',
  'label': 'some text',
  'description': 'some text'}]

我在django中将其传递给上下文,然后在html模板中将其与图表的js代码一起调用:

  <script type="text/javascript">
  var _dict = {{dict|safe}};
  </script>
  <script src="/static/vendors/highcharts/cs_timeline.js"></script>

然后在javascript文件中,使用dict作为数据属性,并使用从官方Highcharts示例获得的一些代码:

Highcharts.chart('hist', {
    chart: {
        type: 'timeline'
    },
    xAxis: {
        visible: false
    },
    yAxis: {
        visible: false
    },
    title: {
        text: 'Timeline of Space Exploration'
    },
    subtitle: {
        text: 'Info source: <a href="https://en.wikipedia.org/wiki/Timeline_of_space_exploration">www.wikipedia.org</a>'
    },
    series: [{
        dataLabels: {
            connectorColor: 'silver',
            connectorWidth: 2
        },
        data: _dict
    }]
});

这对于我完成的每张图表都工作正常,但不适用于此图表。 我在确定问题出在哪里时遇到了麻烦;格式,字典,我弄乱了的一些文字(如果可能的话)等等。帮助将不胜感激! 〜第一篇文章,对不起~~

1 个答案:

答案 0 :(得分:0)

您似乎没有任何实际日期数据。我看到的最接近的是一个以日期开头的字符串。 Highcharts肯定需要日期才能显示时间序列。