Using string for xkey in morrise charts

hasan.alkhatib picture hasan.alkhatib · Mar 3, 2014 · Viewed 16.9k times · Source

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>

Answer

hasan.alkhatib picture hasan.alkhatib · Mar 3, 2014

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.