我正在使用Morris.js库,我想从我的json源创建一个折线图。在我的html代码中,我包含了一个简单的div:
<div id="morris-area-chart"></div>
目前我正在用虚拟数据填充它:
Morris.Area({
element: 'morris-area-chart',
data: [{
period: '2010 Q1',
iphone: 2666,
ipad: null,
itouch: 2647
}, {
period: '2010 Q2',
iphone: 2778,
ipad: 2294,
itouch: 2441
}, {
period: '2010 Q3',
iphone: 4912,
ipad: 1969,
itouch: 2501
}, { ...
}],
xkey: 'period',
ykeys: ['iphone', 'ipad', 'itouch'],
labels: ['iPhone', 'iPad', 'iPod Touch'],
pointSize: 2,
hideHover: 'auto',
resize: true
});
现在,我想在一张图表上绘制六条不同的线条。我创建了一个来自我之前的问题https://stackoverflow.com/a/33422796/4662074的sql查询,现在进入的json看起来像这样:
[{"days_ago":null,"number_id":"1","num_texts":"9"},
{"days_ago":"18","number_id":"1","num_texts":"179"},
{"days_ago":"18","number_id":"5","num_texts":"1"},
{"days_ago":"17","number_id":"1","num_texts":"61"},
{"days_ago":"17","number_id":"2","num_texts":"1"},
{"days_ago":"17","number_id":"5","num_texts":"1"},
{"days_ago":"17","number_id":"6","num_texts":"3"},
{"days_ago":"16","number_id":"3","num_texts":"1"},
{"days_ago":"0","number_id":"1","num_texts":"1"},
{"days_ago":"0","number_id":"2","num_texts":"2"}, etc.]
我想实现一个效果,即每个number_id由一条线表示,在X轴上我们有days_ago值,在Y轴上我们有数字num_texts。你可以帮我解析我的json文件符合这个规范吗?