处理莫里斯图

时间:2018-11-20 18:59:54

标签: javascript morris.js

所以我正在尝试使用莫里斯图表构建折线图,该图表将根据一年中的门票状态显示门票数量。

问题是我对xKey以及那里的内容有些困惑。

图片说明了我要做什么 enter image description here

相反,我得到两行,一个代表状态,另一个代表计数

数据

 {period: "2010-09", status: 1, count: 20}
,{period: "2010-10", status: 1, count: 50}
,{period: "2010-10", status: 2, count: 34}
,{period: "2010-11", status: 2, count: 70}

代码

Morris.Area({
            element: 'morris-area-chart'
            , data: data
            , xkey: 'period'
            , ykeys:  ['count','status']
            , labels: ['processing', 'done']
});

我知道我在弄乱东西,但我不知道是什么。

1 个答案:

答案 0 :(得分:1)

您应该这样更改数据:

 {period: "2010-09", status1Count: 20, status2Count: 12}
,{period: "2010-10", status1Count: 50, status2Count: 34}
,{period: "2010-11", status1Count: 70, status2Count: 25}

和图表代码:

Morris.Area({
            element: 'morris-area-chart'
            , data: data
            , xkey: 'period'
            , ykeys:  ['status1Count','status2Count']
            , labels: ['processing', 'done']
});