Instance Method
Question:
In version 2 echart has instance method But in version 3 i can't find instance method. So do you have any alternative method as like instance method in version 3.
https://ecomfe.github.io/echarts-doc/public/api-en.html#echartsInstance
@pissang thank you for quickly reply me.
I have one more question. In version 2 i can use legend getColor. But seems like version 3 has no getColor.
Do you have any idea?
Yes it has been removed.
Instead you can use
myChart.getModel().getSeriesByName(someSeriesName).getVisual('color')
@pissang ok thank you. Let me try.
@pissang hi again; would you check this pen what i am missing? http://codepen.io/coskuntekin/pen/LkBaRq
i am getting this error.
Uncaught TypeError: myChart.getModel(...).getSeriesByName(...).getVisual is not a function
Sorry my mistake. It should be
myChart.getModel().getSeriesByName('销量')[0].getData().getVisual('color')
@pissang it's fine. so i have one more question.
In version 2 legend has setSelected method, how about in version 3. How can i use?
i searched in documents but i didn't see, seems like removed do you know any other alternative method. Thank you.
You can use dispatchAction to have legend selected, dataZoom changed actions.
Like:
dispatchAction({
type: 'legendSelect',
name: 'someLegend'
});
See more at https://ecomfe.github.io/echarts-doc/public/api-en.html#action.legend
Thank you.
Here is my pen about getVisual and setSelected legend, maybe someone need it, later.
http://codepen.io/coskuntekin/pen/LkBaRq
Great! Thanks for sharing it!
@pissang i bother you again sorry.
dispatchAction is only working with selectedMode:single or i missed something?
Would you check this pen?
http://codepen.io/coskuntekin/pen/LkBaRq
legendSelect is for select the legend. If you wan't to toggle the selected status you should dispatch legendToggleSelect action
thank you again.
Hi @pissang again;
How can i set legend color?
initChart.getModel().getSeriesByName("seriesName")[0].getData().setVisual('#000');
Can i do like that?
You should not setting color like that. setVisual is usually used for saving color info in the visual encoding stage before the final rendering stage after setOption.
Insead you should always use setOption or dispatchAction if you wan't to change the view. In this case setOption is the only way
ok, thank you for your suggestion, i will try.