I'm trying to create a line chart using the Morris.js source but I'm looking to get months put into the chart rather than the example years. Now the problem is when I change the years
field the chart no longer works I've added the two examples below the first is the working years version while the second is the non-working months version.
If someone can see where I'm going wrong or if i'm missing something that'd be very helpful.
Thanks in advance.
Chart Years
new Morris.Line({
// ID of the element in which to draw the chart.
element: 'monthlyReport',
// 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']
});
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js"></script>
<div id="monthlyReport" style="height: 500px;width:50%;margin-left:25%;margin-bottom:100px;"></div>
Chart Months
new Morris.Line({
// ID of the element in which to draw the chart.
element: 'monthlyReport',
// Chart data records -- each entry in this array corresponds to a point on
// the chart.
data: [{
month: 'Jan',
value: 20
},
{
month: 'Feb',
value: 10
},
{
month: 'Mar',
value: 5
},
{
month: 'Apr',
value: 5
},
{
month: 'May',
value: 20
}
],
// The name of the data record attribute that contains x-values.
xkey: 'month',
// 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']
});
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js"></script>
<div id="monthlyReport" style="height: 500px;width:50%;margin-left:25%;margin-bottom:100px;"></div>