Search code examples
morris.js

reverse order of Y axis in Morris line chart


Is it possible to set y axis values in reverse order(0-100)? Max value on top must start from zero to 100 at bottom.

Morris.Line({
     element: 'line-example',
     data: [
         { y: '2006', a: 100, b: 90 },
         { y: '2007', a: 75,  b: 65 },
         { y: '2008', a: 50,  b: 40 },
         { y: '2009', a: 75,  b: 65 },
         { y: '2010', a: 50,  b: 40 },
         { y: '2011', a: 75,  b: 65 },
         { y: '2012', a: 100, b: 90 }
     ],
     xkey: 'y',
     ykeys: ['a', 'b'],
     labels: ['Series A', 'Series B']
 });

Solution

  • I got it working by setting ymin to 100 and ymax to 0. It then plotted my line graph with values closest to 0 at the top, and closest too 100 at the bottom. Here's my code snippet.

    config = 
    {
        data: data,
        xkey: 'y',
        ymin: 100,
        ymax: 0,
        fillOpacity: 0.6,
        ....
    }
    

    You can see instructions here: https://morrisjs.github.io/morris.js/lines.html