javascript 在莫里斯图表中使用字符串作为 xkey
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22148577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using string for xkey in morrise charts
提问by hasan.alkhatib
I am trying to use morrise charts to build a line chart that will display vehicles' numbers according to days among the week.
我正在尝试使用莫里斯图来构建一个折线图,该图将根据一周中的天数显示车辆数量。
The problem is when I use Stringin the xKeythe results appears like this:
问题是当我在xKey 中使用String 时,结果如下所示:
but if I replaced them with numbers, it works fine.
但是如果我用数字替换它们,它就可以正常工作。
Here is my code.
这是我的代码。
<div class="col-xs-6">
<label>Transports Traffic</label>
<div id="traffic_chart">
<script>
new Morris.Area({
element: 'traffic_chart',
data: [
{y: 'Sat', a: 100, b: 90, c:22},
{y: 'Sun', a: 75, b: 65, c:22},
{y: 'Mon', a: 50, b: 40, c:22},
{y: 'Tue', a: 75, b: 65, c:22},
{y: 'Wed', a: 50, b: 40, c:22},
{y: 'Thi', a: 75, b: 65, c:22},
{y: 'Fri', a: 100, b: 90, c:22}
],
xkey: 'y',
ykeys: ['a', 'b', 'c'],
labels: ['Cars', 'Bikes', 'Trucks']
});
</script>
</div>
</div>
回答by hasan.alkhatib
回答by vr_driver
Here's my example that works too.
这也是我的例子。
$(function() {
Morris.Area({
element: 'morris-area-chart-days',
data: [{
day: 'Mon',
a: 95
}, {
day: 'Tue',
a: 66
}, {
day: 'Wed',
a: 86
}, {
day: 'Thu',
a: 151
}, {
day: 'Fri',
a: 115
}, {
day: 'Sat',
a: 93
}, {
day: 'Sun',
a: 38
}],
xkey: 'day',
ykeys: ['a'],
parseTime: false,
labels: ['Messages'],
pointSize: 2,
hideHover: 'auto',
resize: true
});
});
回答by CelinVeronicca
In Morrischart, if 'parseTime' set to false then it skip time/date parsing for X values, Otherwise it treating them as an equally-spaced series;the default value is parseTime:true..thats why you get the issue in above chart..So could you please insert the below line of code
在 Morrischart 中,如果 'parseTime' 设置为 false,则它会跳过 X 值的时间/日期解析,否则将它们视为等距系列;默认值为 parseTime:true ..这就是您在上图中遇到问题的原因..所以你能插入下面的代码行吗
parseTime:false
解析时间:假
Rewrite code like as below,
像下面这样重写代码,
new Morris.Area({
------
parseTime:false,
------
});
回答by Brammy Welang
use this...
用这个...
parseTime: false,
解析时间:假,
Morris.Line({
element: 'morris-line-chart',
data: <?php echo json_encode($emparray);?>,
xkey: 'xco',
ykeys: ['x1', 'x2'],
labels: ['x1', 'x2'],
hideHover: 'auto',
pointSize: 3,
parseTime: false,
resize: true
});