我正在努力解决这个问题。
我有什么:
我想要的是什么:
这是我的第一个结构:
var counter = <?php echo json_encode($v); ?>;
new Morris.Line({
element: 'visit-chart',
data: [
{ "period": '2014-07-01', value: 70 },
{ "period": '2014-07-02', value: 59 },
{ "period": '2014-07-03', value: 130 },
],
xkey: 'period',
ykeys: ['value'],
labels: ['Views']
});
这是计数器变量检索的内容:
[{"id":"6","day":"2014-09-06","views":"7"},{"id":"5","day":"2014-09-05","views":"3"},{"id":"4","day":"2014-09-04","views":"6"},{"id":"3","day":"2014-09-03","views":"2"},{"id":"2","day":"2014-09-02","views":"15"}];
我现在想要的是改变&#34; period&#34;的值。和&#34;价值&#34;通过&#34; day&#34;的值和&#34;观点&#34; &#34;计数器&#34;数组变量。
我试过了:
var counter = <?php echo json_encode($v); ?>;
new Morris.Line({
element: 'visit-chart',
data: [
counter.forEach(function(entry) {
{ "period": entry[days], value: entry[views] },
});
],
xkey: 'period',
ykeys: ['value'],
labels: ['Visualizações']
});
任何人都可以帮助我吗?顺便说一下,我是jQuery的先行者。
答案 0 :(得分:0)
var counter = <?php echo json_encode($v); ?>;
var data =[];
for(i=0;i<counter.length;i++){
data.push({"period":counter[i].day, "value":counter[i].views})
}
new Morris.Line({
element: 'visit-chart',
data: data,
xkey: 'period',
ykeys: ['value'],
labels: ['Visualizações']
});