莫里斯.js 折线图来自 json 的多个 ykey



我在莫里斯.js折线图上徘徊。我的 json 是

[
{"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。 所以我可以实现下面的代码。

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,这将基于来自数据库的数据。我将如何将其绘制成ykeys??请指教。

示例 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/

在这一点上,我通过了ykeys

var yvalues = Object.keys(jsonData[0]).filter(i=>i!='time');

所以它将获取所有的y键跳过时间

相关内容

  • 没有找到相关文章

最新更新