How to get histogram color by echarts

problem description

how to get the color of a column in the echarts histogram (or how to get the color of the corresponding legend in legend)

the environmental background of the problems and what methods you have tried

use myChart.component.legend.getColor (value), but error Cannot read property "legend" of undefined

related codes

/ / Please paste the code text below (do not replace the code with pictures)
var color=myChart.component.legend.getColor ("device registration rate");
console.log ("color" + color);

)

what result do you expect? What is the error message actually seen?

cannot get the legend object

Aug.09,2021

this is the description of the official document. It should be that the version of the js file introduced is too high.
I tried it with version 2.0. There is a lengend object, but there is no getColor.
you can try a lower version of js

.

has encountered a similar requirement before, requiring the following text description to be the same as the legend color.
I used an opportunistic approach to define a color array directly, the legend takes colors from the color array, and the color of the text description is also taken from this color array.


echarts cannot directly obtain the color of a legend in legend or a column in a bar chart. The myChart.component.legend.getColor (value) method does not exist in the higher version of echarts. At that time, I found that this method was also the solution of someone else four years ago. As the first answer to this question said, it uses version 2.0. There are lengend objects, but there is no getColor method. I use the latest version of echarts,. Even the legend object does not have


depending on the situation in which you need to get the color, maybe there are parameters in the corresponding method, from which you can get the color.
for example, in tooltip:formatter, you can get colors

.
Menu