I'm drawing a pie using d3, and using the following to fill the slices with certain colors:
d3.scale.ordinal().domain([]).range(['#2ECC71', '#208E4E', '#12512C', '#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'])
My problem arises when swapping out one pie chart for another, which is in essence just a data swap. When doing so, instead of the new pie starting from '#2ECC71', it starts from a later color value, depending on how many slices there were; e.g. if two slices were used, the "new" pie after dataswap would start at "#12512c".
js framework: Vue.js d3 version: v3
Cheers.
const greenScale = ['#2ECC71', '#208E4E', '#12512C', '#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'];First I triedd3.scale.ordinal().domain([0, greenScale.length]).range(greenScale)But that didn't work. My pie charts were skipping from the first value to the fourth. That said, I went back to the docs and noticed that the domain values can be mapped 1-1 to the range values. Solution:d3.scale.ordinal().domain(_.range(greenScale.length)).range(greenScale)- Santboi