apache / echarts

Apache ECharts is a powerful, interactive charting and data visualization library for browser
https://echarts.apache.org
Apache License 2.0
60.58k stars 19.62k forks source link

[Bug] 属性“getModel”为私有属性,只能在类“ECharts”中访问。ts(2341) #18302

Open gy1016 opened 1 year ago

gy1016 commented 1 year ago

Version

5.4.1

Link to Minimal Reproduction

No response

Steps to Reproduce

useEffect(() => { const dom = document.getElementById("container")!; const myChart = echarts.init(dom, undefined, { renderer: "canvas", useDirtyRect: false, });

const heatPoints: any[] = [];

fetch("http://127.0.0.1:9999/query") .then((res) => res.json()) .then(({ data }) => { for (let point of data) heatPoints.push([point.lng, point.lat, point.heat]); myChart.setOption({ animation: false, bmap: { center: [120.13066322374, 30.240018034923], zoom: 14, roam: true, }, visualMap: { show: false, top: "top", min: 0, max: 5, seriesIndex: 0, calculable: true, inRange: { color: ["blue", "blue", "green", "yellow", "red"], }, }, series: [ { type: "heatmap", coordinateSystem: "bmap", data: heatPoints, pointSize: 5, blurSize: 6, }, ], }); // [Bug] 属性“getModel”为私有属性,只能在类“ECharts”中访问。ts(2341) const bmap = myChart.getModel().getComponent("bmap").getBMap(); }); }, []);

Current Behavior

按照下面官网的这个例子,使用TS+React复现的时候,TS提示getModel是private方法 https://echarts.apache.org/examples/zh/editor.html?c=heatmap-bmap&version=5.4.1

Expected Behavior

getModel应该能够在myChart上使用

Environment

No response

Any additional comments?

No response

echarts-bot[bot] commented 1 year ago

@gy1016 It seems you are not using English, I've helped translate the content automatically. To make your issue understood by more people and get helped, we'd like to suggest using English next time. 🤗

TRANSLATED
**TITLE** [Bug] The property "getModel" is private and can only be accessed in the class "ECharts". ts(2341)
Ovilia commented 1 year ago

getModel 方法确实没准备暴露给开发者,应该是 BMap 的相关文档应该更新,as any 可以解决这个报错吗?可以的话能麻烦给 bmap/README.md 提个 PR 修复一下文档吗?

daolanfler commented 1 year ago

getModel 方法确实没准备暴露给开发者,应该是 BMap 的相关文档应该更新,as any 可以解决这个报错吗?可以的话能麻烦给 bmap/README.md 提个 PR 修复一下文档吗?

image 可以解决这个报错。没有暴露 getModel 的话,那有其他办法能获取 bmap 实例吗?感觉这个操作还是挺常见的