underscore underscore -4 years ago 56
Javascript Question

can't use strings instead of integers in area charts in morris charts library

Bar Chart Example

Morris.Bar({
element: 'bar-example',
data: [
{ y: 'dddd', 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']
});


Area Chart Example

Morris.Area({
element: 'area-example',
data: [
{ y: 'dddd', 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']
});


In Morris Chart library Bar charts accepts strings for Y-AXIS but Area one doesn't.I can't understand why ?

THIS IS THE MORRIS LIBRARY

Answer Source

Morris.js is trying to parse x-values as timestamp. But 'dddd' has invalid format. You can skip date parsing by using parseTime: false option (jsbin). In this case X values will be treated as an equally-spaced series. See docs

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download