javascript - Morris.Line js 无法将年更改为月

标签 javascript html linechart morris.js

我正在尝试使用 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/

相关文章:

javascript - 如何使用 JavaScript 在没有提交按钮的情况下提交 "file"输入?

java - 将字符串转换为数据集

javascript - Json数据不显示在html服务器上

JavaScript自动排列图引擎

javascript 正在关闭我的 HTML 标签

html - 在 IE 浏览器中 anchor 标记的轮廓不可见

javascript - 如何隐藏 n3 图表中第一个子项和最后一个子项的刻度

javascript - 如何在 google chart api 中实现以下图表?

javascript - 多维数组序列化

html - 在列表下用 HTML/CSS 制作一条垂直线