echarts icon indicating copy to clipboard operation
echarts copied to clipboard

Instance Method

Open coskuntekin opened this issue 10 years ago • 17 comments

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.

coskuntekin avatar Jul 29 '16 09:07 coskuntekin

https://ecomfe.github.io/echarts-doc/public/api-en.html#echartsInstance

pissang avatar Jul 29 '16 09:07 pissang

@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?

coskuntekin avatar Jul 29 '16 09:07 coskuntekin

Yes it has been removed.

Instead you can use

myChart.getModel().getSeriesByName(someSeriesName).getVisual('color')

pissang avatar Jul 29 '16 09:07 pissang

@pissang ok thank you. Let me try.

coskuntekin avatar Jul 29 '16 09:07 coskuntekin

@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

coskuntekin avatar Aug 01 '16 04:08 coskuntekin

Sorry my mistake. It should be

myChart.getModel().getSeriesByName('销量')[0].getData().getVisual('color')

pissang avatar Aug 01 '16 04:08 pissang

@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?

coskuntekin avatar Aug 01 '16 04:08 coskuntekin

i searched in documents but i didn't see, seems like removed do you know any other alternative method. Thank you.

coskuntekin avatar Aug 01 '16 04:08 coskuntekin

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

pissang avatar Aug 01 '16 05:08 pissang

Thank you. Here is my pen about getVisual and setSelected legend, maybe someone need it, later. http://codepen.io/coskuntekin/pen/LkBaRq

coskuntekin avatar Aug 01 '16 05:08 coskuntekin

Great! Thanks for sharing it!

pissang avatar Aug 01 '16 05:08 pissang

@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

coskuntekin avatar Aug 01 '16 06:08 coskuntekin

legendSelect is for select the legend. If you wan't to toggle the selected status you should dispatch legendToggleSelect action

pissang avatar Aug 01 '16 06:08 pissang

thank you again.

coskuntekin avatar Aug 01 '16 07:08 coskuntekin

Hi @pissang again;

How can i set legend color?

initChart.getModel().getSeriesByName("seriesName")[0].getData().setVisual('#000');

Can i do like that?

coskuntekin avatar Aug 22 '16 09:08 coskuntekin

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

pissang avatar Aug 22 '16 09:08 pissang

ok, thank you for your suggestion, i will try.

coskuntekin avatar Aug 22 '16 10:08 coskuntekin