我正在尝试使用 Morris.js 源创建折线图,但我希望将月份而不是示例年份放入图表中。现在的问题是,当我更改 years
字段时,图表不再起作用,我在下面添加了两个示例,第一个是工作年份版本,第二个是非工作月份版本。
如果有人能看到我哪里出了问题或者我是否遗漏了一些东西,那将会非常有帮助。
提前致谢。
上榜年份
new Morris.Line({
// ID of the element in which to draw the chart.
element: 'monthlyReport',
// Chart data records -- each entry in this array corresponds to a point on
// the chart.
data: [{
year: '2008',
value: 20
},
{
year: '2009',
value: 10
},
{
year: '2010',
value: 5
},
{
year: '2011',
value: 5
},
{
year: '2012',
value: 20
}
],
// The name of the data record attribute that contains x-values.
xkey: 'year',
// A list of names of data record attributes that contain y-values.
ykeys: ['value'],
// Labels for the ykeys -- will be displayed when you hover over the
// chart.
labels: ['Value']
});
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js"></script>
<div id="monthlyReport" style="height: 500px;width:50%;margin-left:25%;margin-bottom:100px;"></div>
月份图表
new Morris.Line({
// ID of the element in which to draw the chart.
element: 'monthlyReport',
// Chart data records -- each entry in this array corresponds to a point on
// the chart.
data: [{
month: 'Jan',
value: 20
},
{
month: 'Feb',
value: 10
},
{
month: 'Mar',
value: 5
},
{
month: 'Apr',
value: 5
},
{
month: 'May',
value: 20
}
],
// The name of the data record attribute that contains x-values.
xkey: 'month',
// A list of names of data record attributes that contain y-values.
ykeys: ['value'],
// Labels for the ykeys -- will be displayed when you hover over the
// chart.
labels: ['Value']
});
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js"></script>
<div id="monthlyReport" style="height: 500px;width:50%;margin-left:25%;margin-bottom:100px;"></div>
最佳答案
您可以尝试将选项parseTime设置为false。
关于javascript - Morris.Line js 无法将年更改为月,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51656025/