How can I obtain the ECharts instance using the ID set by props after the ECharts has been created on the current page? #3702
Closed
zhangguolin333
started this conversation in
General
Replies: 2 comments 15 replies
-
please put code in code block. |
Beta Was this translation helpful? Give feedback.
3 replies
-
from nicegui import ui
@ui.page('/')
def page_index():
echart = ui.echart({
'xAxis': {'type': 'value'},
'yAxis': {'type': 'category', 'data': ['A', 'B'], 'inverse': True},
'legend': {'textStyle': {'color': 'gray'}},
'series': [
{'type': 'bar', 'name': 'Alpha', 'data': [0.1, 0.2]},
{'type': 'bar', 'name': 'Beta', 'data': [0.3, 0.4]},
],
})
ui.add_body_html("""
<script>
window.addEventListener('load', () => {
const chartElement = document.getElementById('"""+f"c{echart.id}"+"""');
console.log(55555, chartElement);
if (chartElement) {
const myChart = echarts.getInstanceByDom(chartElement);
options = myChart.getOption();
console.log(6666, options);
}
});
</script>
""")
ui.run() |
Beta Was this translation helpful? Give feedback.
12 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Beta Was this translation helpful? Give feedback.
All reactions