EDIT: Here is a code pen.
There are two main goals:
- Set different colors for slices based on the specific conditions.
- Make the colors be gradient, based on the
amount
.
More info:
1. Set different colors for slices based on the specific conditions.
EDIT: As shown in the code pen, I managed to find a solution for this, but I don't know how good it is.
I want to set different colors for slices based on specific conditions, i.e. specific 'type' & 'ordering'.
For example:
if (ordering < 9999) => green
if (ordering >= 9999 && type === 'can-be-sold') => orange
if (type !== 'can-be-sold') => red
2) Make the colors be gradient, based on the amount.
Example:
There are 10 items that are green, each with a different amount. The slices with the biggest amount should have the color in its darker shade, whereas the slices with the smallest amount should have the color in its lightest shade.
I get the data through ajax:
$.ajax({
'url': '{$dataStockUrl}',
}).done(function(data) {
chart.data = data;
});
The data I get from $dataStockUrl
is in the format of:
[{
"shop": "Lorem",
"type": "can-be-sold",
"amount": "23",
"ordering":"0"
},
{
"shop": "Ipsum",
"type": "can-not-be-sold",
"amount": "1",
"ordering":"9999"
},
....etc....
]