echarts [Bug] "DEPRECATED: "api.style" has been deprecated"

nwo49xxi  于 2022-10-23  发布在  Echarts
关注(0)|答案(4)|浏览(1401)

Version

5.2.2

https://echarts.apache.org/examples/en/editor.html?c=custom-polar-heatmap

Steps to Reproduce

  1. Open https://echarts.apache.org/examples/en/editor.html?c=custom-polar-heatmap

Current Behavior

An option from the doc is deprecated

Expected Behavior

The options from the docs shouldn't be deprecated

Environment

- OS: Windows
- Browser: Chrome
- Framework: /

Any additional comments?

I am using this echarts from example in my app : https://echarts.apache.org/examples/en/editor.html?c=custom-polar-heatmap
However, I have this warn in the console : styleCompat.js:238 [ECharts] DEPRECATED: "api.style" has been deprecated. Please write literal style directly instead.
I tried to find more about it and I could only find a bit of info in the Echarts changelog In renderItem, the api.style(...) and api.styleEmphasis(...) are deprecated. Because it is not really necessary and hard to ensure backward compatibility. Users can fetch system designated visual by api.visual(...).
Though, I couldn't find more and the doc still make the use of api.style() : https://echarts.apache.org/en/option.html#series-custom.renderItem.return

What should I change in the example above to make it works without deprecacted options ?

jc3wubiy

jc3wubiy1#

Yes the example can be changed to simpler:

return {
  ...
  style: {
    fill: api.visual('color')
  }
}
vd8tlhqk

vd8tlhqk2#

Thanks @pissang
I let you close this, as I don't know if the documentation / examples should be updated

pgx2nnw8

pgx2nnw83#

@pissang I got a similar use case with custom render using api.style() . It seems that api.style() does more than just setting the styles.

const customRender = (params, api) => {
    const start = api.coord([api.value(0), 1]);
    const style = api.style();

    return {
        type: 'rect',
        shape: {
            x: start[0],
            y: start[1],
            width: params.coordSys.width / values.length,
            height: params.coordSys.height
        },
        style: style
    };
};

When I print out the result of api.style() , it's more than just styling. There are setting of the Y value, right?

{
    "fill": "white",
    "stroke": "black",
    "textPosition": "inside",
    "textDistance": 5,
    "textFill": "black",
    "fontStyle": "normal",
    "fontWeight": "normal",
    "fontSize": 12,
    "fontFamily": "sans-serif",
    "text": "YEF",
    "legacy": true
}
7z5jn7bk

7z5jn7bk4#

Yes the example can be changed to simpler:

return {
  ...
  style: {
    fill: api.visual('color')
  }
}

What should be used instead of api.styleEmphasis()?

相关问题