Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble with adpation of your fork for using draw down bar from 0 for negatives value #7

Closed
Mokette opened this issue Mar 4, 2015 · 9 comments
Assignees
Labels

Comments

@Mokette
Copy link

Mokette commented Mar 4, 2015

Hi,
i've contact you by mail, and for make the discussion easier, you've aksed me to post a issue here so there it is ! ;)
i've got some trouble to adapt your fork for make it draw down bar from 0 for negatives values.

At first place, I was looking for a fork of Chartjs api wich support negative values correctly. I found a post of nnnick in the issue part where he explains how we can succeed to draw negative value down from 0 so I try to do some modification in the chart.js file to do that (following the indication of nnnick) and I succeed I get this :
http://fiddle.jshell.net/Mokette/x2vy0nvh/2/
(you probably have to run it for make it draw properly -> positifves values draw up from 0 to value and negatives draw down from 0 to value)
(in this fiddle it’s the chartjs file with some modification for drawing negatives values down from 0, it’s work pretty well :) )

Then I’ve been ask to draw multiple graph (a bar and two line) in the same canvas so I look for a fork wich permit these functionality and I found yours !
It work really good for drawing multiple graph with the new overlay extension but it doesn’t work for drawing negatives values.
So I try to do the same modification to the Chart.js file of your fork to add the functionality of drawing bars down from 0 for bar graph but I didn’t succeed to make it work well :s
http://fiddle.jshell.net/Mokette/xL0bdcmb/1/
This is the fiddle where I load your chart.js file from your fork with my modification for drawing bar down :) but didn’t work as the first fiddle for drawing bar down but still work well for multiple graph :)

You can find here http://gnomebusters.fr/jsfiddle/files/ two file, the chart.js file I use in my second fiddle (the Chart.js file is the one from your fork where i add some modification to test drawing negatives bars) and a .txt file where I explain where I’ve added/modify your fork to try to draw negative bars.

@leighquince leighquince self-assigned this Mar 4, 2015
@leighquince
Copy link
Owner

have you got the link to issue in nnick/chart.js where the modifications are

@leighquince leighquince added the bug label Mar 4, 2015
@Mokette
Copy link
Author

Mokette commented Mar 4, 2015

I don't get it right now :s i've forgot to add it to my bookmarks :s
i'll try to find it again as soon as i can :)
but all the modification that nnnick submit are those i've added in the chart.js file attach to my comment (if you read the .txt file you can see where i've add it (i also comment the line beofre and after my modification to highlight them more easilly ;) )

@Mokette
Copy link
Author

Mokette commented Mar 4, 2015

Oh if i remmeber well, i'll probably get some help of that fix too ;)
https://github.com/ahrex/Chart.js/commit/75e9a64cd74656c37ae2e9044ebdeb9f5a566712
(and it's probably those modification that i've add in your fork chart.js file to try to make it works with negatives values)
and this came from the Issue chartjs#669 of nnnick fork
chartjs#669

@leighquince
Copy link
Owner

ah ok if there are comments i can see what has been added cheers

@leighquince
Copy link
Owner

so it was just missing some code from one place in your example, where i have the option of drawing stacked bars and normal bars you had only added it to the stacked bars part, also added in checking for showing tooltips when hovering over labels here is an example - http://fiddle.jshell.net/leighking2/6p4fo0tb/

i have added a commit to a dev branch where you can grab the built Chart.js file (07e6e78) as im not entirely happy with this solution, i would like it to automatically detect the need to display in negative values without having to setup the overrides in the options. also when using the overlay and having a fill on the line it doesn't take into account the fact that 0 is no longer at the bottom so fills all the way from the bottom which looks weird.

so ill keep having a look at this but for the moment it does now work like the fix from nnick/chart.js's repo. when i have everything ready ill commit this to the master but for now just going to leave it on the dev branch.

@Mokette
Copy link
Author

Mokette commented Mar 5, 2015

Oh ok that's why it didn't work correctly when i try to use it.
I've retrieve your new built from your commit in the dev branch and try it on my project, it wokrs really good ! :)
Yes i've seen that when you set up a fillCOlor for the line type it look really weird ^^ but i'm glad that in my case, the fillColor got an alpha 0 so it's appears transparent on the canvas and make it works not so bad and not so weird ;)

Thank you so much for your help ! :)

(juste a little question for ask if it's possible to do something ^^ on my graph the two line are both constant define by the user, so it always display a straight line, is it possible for that usecase that the line will be draw from the left side to the right side of canvas without space between the side of canvas ? :) space is due to X label/value and because dot of line graph spawn in the middle of each Bars in the bar graph but will it be possibel to draw the line directly from the y axis to the complete right side of the canvas ? Just for asking ;) )
Thanks for your answer :)

@leighquince
Copy link
Owner

ok ive just pushed a commit to the dev branch again for this issue which makes it so that you do;t have to override the scale and line charts display better with the negative values. you just have to make sure the beginFromZero option is false. I'm going to do some mroe testing on it but then ill merge into the master branch. if you take a look let me know if you spot anything weird with it.

@Mokette
Copy link
Author

Mokette commented Mar 17, 2015

Ok really thank you ! :)
Sure, i'll take a look at it and gonna tell you if i spot something ;)

@leighquince
Copy link
Owner

ok ive tested it against all the charts and it seems to be working well, im going to merge the dev branch into master so if you do spot anything just add another issue, cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants