Morris图表中的X轴格式是否可以从T&
更改为YYYY-MM-DD
?
答案 0 :(得分:3)
使用xLabelFormat
功能实现:
xLabelFormat: function (d) {
return ("0" + d.getDate()).slice(-2) + '-' + ("0" + (d.getMonth() + 1)).slice(-2) + '-' + d.getFullYear();
}
Morris.Area({
element: 'chart',
data: [
{ y: '2015-01-01', a: 1, b: 2 },
{ y: '2015-01-02', a: 2, b: 3 },
{ y: '2015-01-02', a: 2, b: 2 },
{ y: '2015-01-03', a: 1, b: 4 },
{ y: '2015-01-04', a: 2, b: 5 },
{ y: '2015-01-05', a: 3, b: 3 },
{ y: '2015-01-06', a: 1, b: 2 }
],
xkey: 'y',
ykeys: ['a', 'b'],
labels: ['Individual Score', 'Team Score'],
fillOpacity: 0.4,
hideHover: 'auto',
behaveLikeLine: true,
resize: true,
xLabelFormat: function (d) {
return ("0" + d.getDate()).slice(-2) + '-' + ("0" + (d.getMonth() + 1)).slice(-2) + '-' + d.getFullYear();
},
pointFillColors: ['#ffffff'],
pointStrokeColors: ['black'],
lineColors: ['red', 'blue'],
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/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>
<link href="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css" rel="stylesheet"/>
<div id="chart"></div>