Using string for xkey in morrise charts
Asked Answered
I

4

21

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 String in the xKey the results appears like this: enter image description here

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>
Infrequent answered 3/3, 2014 at 13:53 Comment(0)
I
52

In morrise library, the X-Key always parsed to date/time value. So in order to prevent that and use string values in X-Key you have to add this attribute

parseTime: false

It worked after I added it.

source.

Infrequent answered 3/3, 2014 at 17:31 Comment(0)
B
6

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
    });
});
Baptist answered 1/8, 2015 at 8:41 Comment(0)
D
4

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

parseTime:false

Rewrite code like as below,

new Morris.Area({
             ------
             parseTime:false,
             ------
});
Dysfunction answered 21/7, 2016 at 10:56 Comment(0)
R
3

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
    });
Rectifier answered 26/8, 2016 at 7:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.