Time series graphs in Highcharts

时间:2017-06-19 13:53:03

标签: python highcharts

I have a JSON in the following format [{"usage_idle": 99.49824385418651, "time": "2017-06-12T10:15:20Z"}, {"usage_idle": 99.59798994937717, "time": "2017-06-12T10:15:20Z"}]

How can I plot a time series graph with this using highchart? I am using python in the backend.

1 个答案:

答案 0 :(得分:1)

将数据格式映射到下面的highcharts点选项的示例:

const json = [
    {"usage_idle": 99.49824385418651, "time": "2017-06-12T10:15:20Z"},
  {"usage_idle": 99.59798994937717, "time": "2017-06-12T10:15:21Z"}
]

const options = {
    xAxis: { type: 'datetime' },
  yAxis: { type: 'logarithmic' },
  series: [{
    data: json.map((o) => ({ x: Date.parse(o.time), y: o.usage_idle })),
    type: 'column'
  }]
}

const chart = Highcharts.chart('container', options)

实例: https://jsfiddle.net/cqnmc4az/