shutterstock / rickshaw

JavaScript toolkit for creating interactive real-time graphs
https://shutterstock.github.io/rickshaw
MIT License
6.53k stars 941 forks source link

Graph negatives values seems impossible #10

Closed akileos closed 12 years ago

akileos commented 12 years ago

IT seems that we are unable to display negative values on the chart. I didn't find any param to set Y-Axis min to anything that is not "zero". Is there a clean way to do this ?

akileos commented 12 years ago

Sample graph :

var data = [ { x: 0, y: -40 }, { x: 1, y: 3 }, { x: 2, y: -17 }, { x: 3, y: -42 } ];

var graph = new Rickshaw.Graph( { element: document.querySelector("#chart"), width: 580, height: 250, series: [ { color: 'steelblue', data: data } ] } );

graph.render();

andrew commented 12 years ago

The minimum graph value is hardcoded to 0 in all of the renders, for instance: https://github.com/shutterstock/rickshaw/blob/master/src/js/Rickshaw.Graph.Renderer.Line.js#L35

I've fixed it in my fork here: https://github.com/andrew/rickshaw/commit/7dc125e79326d94bdbf44d5337c78050757dd9c5

PlasticLizard commented 12 years ago

Any chance this change can be merged in the main project? We have a few data sets with negative values, would be very nice to have ...

andrew commented 12 years ago

I'll send a pull request

PlasticLizard commented 12 years ago

Thank you, much appreciated.

kvisle commented 12 years ago

I've implemented a fix, where you can set a min-property on your graph. Being any number you wish, 'auto' (picks the lowest value in your current dataset), or just not define it (will fall back to the current default; 0).

https://github.com/kvisle/rickshaw/commit/a834029022a2177deb3c471b7b8a8b8b575d536d

Pull request sent, should apply to current HEAD.

dchester commented 12 years ago

This is merged in with 6a75eae7fb

If you specify min: 'auto', in the Rickshaw.Graph constructor, you should be able to graph negative values.