-
Notifications
You must be signed in to change notification settings - Fork 760
Gradient color for (line)charts #510
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
Comments
issue on angular github page |
Great investigation @Doomic. Hopefully they can fix that in |
If you don't mind. I leave the "fight" where to fix up to you. (personally i agree with you and this should be fixed in angular.) if they doen't want to fix there code, here is the code they use, but with the improvement. you could use it for the merge situations
|
Hey. I want to use gradient color and come to this thread. |
We've decided that this will not be fixed in AngularJS. Please use https://lodash.com/docs/4.17.4#merge or a similar function instead. |
This issue will be an extention to #240 but i also find some results that may help.
ChartJs
ChartJs supports that that linecolors and backgroundcolors (and perhaps more color object) are a gradient. This can be done by getting the ctx and call createLinearGradient function, push the result in the color object you want and there is a gradient line/background.
AngularChart
Angular-chart can't give you the ctx (correct me if i am wrong). However just find the canvas with javascript and get the context(2d) will give the ctx. (just like you are used to in ChartJs)
Then a made the gradient and put it in the color scope and/or the datasetoverride.
However, this will not result in a gradient line or background. an other color will there (i believe it is the color for the latest draw object to the canvas).
Example
http://jsbin.com/duforuyumu/1/edit?html,js,output
Solution
After searching i found the problem. It is inside the angular.merge function. (this function is used inside the getDataSets function and the getDataSet function)
this merge function (deep copy) loops trough all attributes and if the attribute is an object; this object will be merged again. This looks like a good way of dealing with merging objects.
jQuery does also include a extend function with deep copy possibility. After implimenting this function insteed of the angular.merge the issues is fixed.
Search deeper
This means jquery merge the object a little bit different. I got the source code of both functions and find out that jquery first determent if the object is a "normal" object.
as you can see... both are objects. however not both are a "normal" object.
Angular will try to loop trough the gradient attributes (but there are none). And jquery will copy (link) the gradient to the result (like a string or number just will be linked).
Final
I understand that this merge function is from angular. So the team there should fix this problem... I will make an issue there as well. But for now, angular-chart can be fixed with a jquery extend.
The text was updated successfully, but these errors were encountered: