forked from zauberzeug/nicegui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request zauberzeug#1346 from natankeddem/echarts
Adding ECharts Element
- Loading branch information
Showing
10 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export default { | ||
template: "<div></div>", | ||
mounted() { | ||
setTimeout(() => { | ||
this.chart = echarts.init(this.$el); | ||
this.chart.setOption(this.options); | ||
this.chart.resize(); | ||
}, 0); // NOTE: wait for window.path_prefix to be set in app.mounted() | ||
}, | ||
beforeDestroy() { | ||
this.destroyChart(); | ||
}, | ||
beforeUnmount() { | ||
this.destroyChart(); | ||
}, | ||
methods: { | ||
update_chart() { | ||
if (this.chart) { | ||
this.chart.setOption(this.options); | ||
} | ||
}, | ||
destroyChart() { | ||
if (this.chart) { | ||
this.chart.dispose(); | ||
} | ||
}, | ||
}, | ||
props: { | ||
options: Object, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from typing import Dict | ||
|
||
from ..element import Element | ||
|
||
|
||
class EChart(Element, component='echart.js', libraries=['lib/echarts/echarts.min.js']): | ||
|
||
def __init__(self, options: Dict) -> None: | ||
"""Apache EChart | ||
An element to create a chart using `ECharts <https://echarts.apache.org/>`_. | ||
Updates can be pushed to the chart by changing the `options` property. | ||
After data has changed, call the `update` method to refresh the chart. | ||
:param options: dictionary of EChart options | ||
""" | ||
super().__init__() | ||
self._props['options'] = options | ||
self._classes = ['nicegui-echart'] | ||
|
||
@property | ||
def options(self) -> Dict: | ||
return self._props['options'] | ||
|
||
def update(self) -> None: | ||
super().update() | ||
self.run_method('update_chart') |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from nicegui import ui | ||
|
||
|
||
def main_demo() -> None: | ||
from random import random | ||
|
||
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]}, | ||
], | ||
}) | ||
|
||
def update(): | ||
echart.options['series'][0]['data'][0] = random() | ||
echart.update() | ||
|
||
ui.button('Update', on_click=update) |