ECharts: dataset with bars colored based on category name?

1.8k Views Asked by At

I'd like to be able to control bar colors based on xAxis/category label name, throughout multiple charts, while using the dataset.source option of feeding data.

I'm guessing the solution might involve using visualMap?

customColors = {
 x1: '#123',
 x2: '#456',
 x3: '#789',
 ...
}

enter image description here

1

There are 1 best solutions below

2
On

I don't think visualMap is the way to do this, you probably want to set the colors in series:
https://echarts.apache.org/en/option.html#series-bar.data.itemStyle.color
or define a color palette:
https://echarts.apache.org/en/option.html#color

Echarts should color the chart by series by default:
https://echarts.apache.org/en/option.html#series-bar.colorBy