morrisjs / morris.js

Pretty time-series line graphs
http://morrisjs.github.com/morris.js/
6.92k stars 1.23k forks source link

Y axis labels incorrect with negative values #794

Closed cgruber0 closed 4 years ago

cgruber0 commented 4 years ago

image

I have a bar chart with 2 negative bars. The y-axis should begin at zero and the bars should be vertically flipped. What am I doing wrong? With another dataset, also completely negative, it works without any problem.

new Morris.Bar({ // ID of the element in which to draw the chart. element: 'yearlyYieldPatternChart', // Chart data records -- each entry in this array corresponds to a point on // the chart. data: [{"year":"2011","yield":-18.16},{"year":"2018","yield":-16.25}], // 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: ['yield'], // Labels for the ykeys -- will be displayed when you hover over the // chart. labels: ['Yield per Year'] });

pierresh commented 4 years ago

If every value is negative, you need to set the option ymax to 0.

Example:

new Morris.Bar({
    element: 'yearlyYieldPatternChart',
    data: [{"year":"2011","yield":-18.16},{"year":"2018","yield":-16.25}],
    ymax: 0,
    xkey: 'year',
    ykeys: ['yield'],
    labels: ['Yield per Year']
});
cgruber0 commented 4 years ago

image

Then the labels left are quite ugly... is there a option to fix this?

pierresh commented 4 years ago

You can try to set the option gridIntegers to true,

or define ymin to a multiple of 4, like -20 for that example.

cgruber0 commented 4 years ago

Setting ymin and ymax helped, thank you very much!