score:1

Accepted answer

if you don't set your domain (i'm assuming you don't), d3 will create the ordinal scale's domain based on the usage:

setting the domain on an ordinal scale is optional if the unknown value is implicit (the default). in this case, the domain will be inferred implicitly from usage by assigning each unique value passed to the scale a new value from the range. (source)

therefore, it's a good idea to explicitly set the domain. since you want that...

the first colours in the array are assigned to the largest x-axis values

...we can sort the data and create a brand array:

.domain(data.sort((a, b) => b.x1 - a.x1).map(d => d.brand))

pay attention to the fact that sort() will change your data array in place.


Related Query