Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

Bar charts don't support negative values

Open borgar opened this issue 13 years ago • 24 comments

Bar charts turn very strange when negative values exist in the data.

Test: http://jsfiddle.net/egMGx/

borgar avatar Mar 18 '13 11:03 borgar

I'll take a look at nice ways of showing negative scales for both bar and line charts.

nnnick avatar Mar 18 '13 20:03 nnnick

Could, we enhance the bar charts for the horizontal look and provide it also as an option?? I would also like to know how to contribute to the library with new chart types as an option.

kkush33 avatar Mar 30 '13 17:03 kkush33

anything new on this?

sebfischer83 avatar Apr 04 '13 10:04 sebfischer83

In my fork (https://github.com/WimAtIHomer/Chart.js) I have made changes to support negative values

Wimmen avatar May 02 '13 09:05 Wimmen

Did you do a pull-request? It would be awesome to have it for everybody in the main chartjs!

Xaviju avatar May 07 '13 14:05 Xaviju

The changes are part of my pull-request "BarAndLine Chart added". Don't know if will ever be part of the main chartjs, never had a reply on that pull-request. The project looks kind of dead.

Wimmen avatar May 08 '13 07:05 Wimmen

Any progress on this? PS. Thank you WimAtIHomer, your version works great.

Edit: I had to remove ".toFixed(getDecimalPlaces(stepValue))" from the populateLabels function in order to set correct labels on -1, 0, 1, etc values.

nicotroia avatar Sep 12 '13 21:09 nicotroia

still no progress with negative numbers?

kurtseebauer avatar Apr 01 '14 20:04 kurtseebauer

Bars with negative numbers works on the alternative version available at https://github.com/FVANCOP/ChartNew.js . This version is down compatible with nnnick version.

FVANCOP avatar Apr 02 '14 19:04 FVANCOP

thank you very much!

kurtseebauer avatar Apr 02 '14 22:04 kurtseebauer

Haven't had a chance to put that into the new version just yet. I'll leave this open as an enhancement, if anyone wants to take a look at incorporating their changes into the Chart.Scale class that'd be winning.

nnnick avatar Jun 29 '14 19:06 nnnick

I've proposed a fix, and wrapped it up as a pull request. This change works for my use case, but feel free to take it and generalize it.

ahrex avatar Oct 01 '14 00:10 ahrex

Hey guys, how is this going? is @ahrex 's pull request good to go? I'm looking to use a lot of these charts in production soon, and this is one of the biggies ;)

tannerlinsley avatar Nov 12 '14 19:11 tannerlinsley

Hey @tannerlinsley,

There's a bug with my proposed fix where the scale will look wonky upon resize (responsive == true). I'm testing out @3xmo's potential fix he provided at https://github.com/nnnick/Chart.js/pull/669#issuecomment-60125767. I'll let you know how it goes.

EDIT: fixed.

ahrex avatar Nov 12 '14 19:11 ahrex

@ahrex Awesome. If you need some help, let me know.

tannerlinsley avatar Nov 12 '14 19:11 tannerlinsley

I've not tested with responsive: true, but the previous PR is a win.

chrisfromredfin avatar Nov 13 '14 21:11 chrisfromredfin

@tannerlinsley, @chrisfromredfin,

I've cleaned up my pull request. The tip of ahrex/Chart.js now has the alternative origin wrapped up in a method, and I've replaced all areas that were calling the old origin with this method. It works for me, but I haven't tested all cases so feel free to comment on anything unusual you see.

ahrex avatar Nov 14 '14 00:11 ahrex

Everything so far seems to look amazing with @ahrex 's modifications. I'd love to see this merged in asap.

tannerlinsley avatar Dec 16 '14 18:12 tannerlinsley

@ahrex - I checked out the pending pull request here, and changed some of the bar values to negative values, but this resulted in the negative bar flowing outside of the scale and canvas. Can you confirm?

tannerlinsley avatar Dec 29 '14 21:12 tannerlinsley

:+1: please include #994

m1ga avatar Mar 19 '15 15:03 m1ga