As detailed in the documentation, `series-treemap.data.color` is a list that impacts the color of nodes at the same level (and their children).
If you wish to assign a specific color to a node, you must utilize
series-treemap.data.itemStyle.color
(doc).
Here's an illustration:
var myChart = echarts.init(document.getElementById('main'));
option = {
series: [
{
type: 'treemap',
data: [
{
name: 'nodeA',
value: 10,
color: ['blue','green', 'grey'],
children: [
{
name: 'nodeAa',
value: 4,
itemStyle : {
color: 'red'
},
},
{
name: 'nodeAb',
value: 6,
children: [
{
name: 'nodeAb1',
value: 20
}
]
},
{
name: 'nodeAc',
value: 6
},
{
name: 'nodeAd',
value: 6
}
]
},
{
name: 'nodeB',
value: 20,
color: ['orange'],
children: [
{
name: 'nodeBa',
value: 20,
children: [
{
name: 'nodeBa1',
value: 20
},
{
name: 'nodeBa2',
value: 20
}
]
}
]
}
]
}
]
};
myChart .setOption(option)
<html>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.3.2/echarts.min.js"></script>
<div id="main" style="width: 600px; height:400px;"></div>
</body>
</html>
All the children under nodeA
(such as nodeAb
, nodeAc
, nodeAd
) adhere to the colors specified in color: ['blue','green', 'grey']
. However, nodeAa
deviates from this rule because it has its own color defined in itemStyle.color: red
.
Nodes nodeBa1
and nodeBa2
are both orange due to being within the parent's color list. If you desire a different color for one of them, include additional colors in the color
array or specify itemStyle.color
.