echart.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. from typing import Dict
  2. from ..element import Element
  3. class EChart(Element, component='echart.js', libraries=['lib/echarts/echarts.min.js']):
  4. def __init__(self, options: Dict) -> None:
  5. """Apache EChart
  6. An element to create a chart using `ECharts <https://echarts.apache.org/>`_.
  7. Updates can be pushed to the chart by changing the `options` property.
  8. After data has changed, call the `update` method to refresh the chart.
  9. :param options: dictionary of EChart options
  10. """
  11. super().__init__()
  12. self._props['options'] = options
  13. self._classes = ['nicegui-echart']
  14. @property
  15. def options(self) -> Dict:
  16. return self._props['options']
  17. def update(self) -> None:
  18. super().update()
  19. self.run_method('update_chart')
  20. def resize(self) -> None:
  21. """Resize the chart to fit the container.
  22. Usually, this does not need to be called manually, as the chart is resized automatically when the window is resized.
  23. """
  24. self.run_method('resize_chart')