Morris.js折线图来自JSON的多个ykey [英] Morris.js line chart multiple ykeys from json
本文介绍了Morris.js折线图来自JSON的多个ykey的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在看morris.js折线图.我的json是
I am wokring on morris.js line chart. My json is
[
{"uma":"34","time":"2017-05-11 12:30","mahes":"23","karan":"56"},
{"uma":"45","time":"2017-05-11 12:35","mahes":"45","karan":"56"},
{"uma":"34","time":"2017-05-11 12:38","mahes":"54","karan":"56"}
]
从上面的json中,我确定有关xkey和ykeys.所以我可以实现以下代码.
from the above json, I am sure about xkey and ykeys. so I can implement to the below code.
var stringify=JSON.stringify(abovejson);
var data =stringify,
config = {
data: JSON.parse(data),
xkey: 'time',
ykeys: ['uma','mahes','karan'],
labels: ['temperature'],
fillOpacity: 0.6,
hideHover: 'auto',
behaveLikeLine: true,
resize: true,
pointFillColors:['#ffffff'],
pointStrokeColors: ['black'],
lineColors:['green']
};
config.element = 'morris-area-chart-exm';
Morris.Line(config);`
如果我的json可能有2个以上的ykey,这些ykey将基于来自数据库的数据.我将如何将其绘制在ykeys上?请指教.
If my json may have more than 2 ykeys which will be based on the data comes from database. How will i plot it to ykeys?? Please advice.
示例JSON将
[
{"uma":"34","time":"2017-05-11 12:30","mahes":"23","karan":"56","janu":"23",....},
{"uma":"45","time":"2017-05-11 12:35","mahes":"45","karan":"56","janu":"56",....},
{"uma":"34","time":"2017-05-11 12:38","mahes":"54","karan":"56","janu":"67",....}
]
推荐答案
我为你提了个小提琴
http://jsfiddle.net/athulnair/edwsgj8g/
在此,我通过了ykey
In this, I passed the ykeys
为
var yvalues = Object.keys(jsonData[0]).filter(i=>i!='time');
因此它将获取所有y键跳过时间
So it will fetch all the y key skipping time
这篇关于Morris.js折线图来自JSON的多个ykey的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文