morris.js – Simple elegant looking Charts Library based on Javascript


morris.js – Simple elegant looking Charts Library based on Javascript


It’s a very simple API for drawing line, bar, area and donut charts.


  • jQuery (>= 1.7 recommended, but it’ll probably work with older versions)
  • Raphael.js (>= 2.0)


Getting started

Add morris.js and its dependencies (jQuery &Raphaël) to your page.

1 <link rel="stylesheet" href="//">
2 <script src="//"></script>
3 <script src="//"></script>
4 <script src="//"></script>

If you don’t want to use the CDN-hosted assets, then you can extract them from the zip bundle and upload them to your own site.



Your first chart

Start by adding a <div> to your page that will contain your chart. Make sure it has an ID so you can refer to it in your Javascript later.

<div id="myfirstchart" style="height: 250px;"></div>

Note: in order to display something, you’ll need to have given the div some dimensions. Here I’ve used inline CSS just for illustration.

Next add a <script> block to the end of your page, containing the following javascript code:

new Morris.Line({
  // ID of the element in which to draw the chart.
  element: 'myfirstchart',
  // Chart data records -- each entry in this array corresponds to a point on
  // the chart.
  data: [
    { year: '2008', value: 20 },
    { year: '2009', value: 10 },
    { year: '2010', value: 5 },
    { year: '2011', value: 5 },
    { year: '2012', value: 20 }
  // The name of the data record attribute that contains x-values.
  xkey: 'year',
  // A list of names of data record attributes that contain y-values.
  ykeys: ['value'],
  // Labels for the ykeys -- will be displayed when you hover over the
  // chart.
  labels: ['Value']






Please enter your comment!
Please enter your name here

three × 1 =