echart_documentation.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from nicegui import ui
  2. from ..documentation_tools import text_demo
  3. def main_demo() -> None:
  4. from random import random
  5. echart = ui.echart({
  6. 'xAxis': {'type': 'value'},
  7. 'yAxis': {'type': 'category', 'data': ['A', 'B'], 'inverse': True},
  8. 'legend': {'textStyle': {'color': 'gray'}},
  9. 'series': [
  10. {'type': 'bar', 'name': 'Alpha', 'data': [0.1, 0.2]},
  11. {'type': 'bar', 'name': 'Beta', 'data': [0.3, 0.4]},
  12. ],
  13. })
  14. def update():
  15. echart.options['series'][0]['data'][0] = random()
  16. echart.update()
  17. ui.button('Update', on_click=update)
  18. def more() -> None:
  19. @text_demo('EChart with clickable points', '''
  20. You can register a callback for an event when a series point is clicked.
  21. ''')
  22. def clickable_points() -> None:
  23. ui.echart({
  24. 'xAxis': {'type': 'category'},
  25. 'yAxis': {'type': 'value'},
  26. 'series': [{'type': 'line', 'data': [20, 10, 30, 50, 40, 30]}],
  27. }, on_point_click=ui.notify)
  28. @text_demo('EChart with dynamic properties', '''
  29. Dynamic properties can be passed to chart elements to customize them such as apply an axis label format.
  30. To make a property dynamic, prefix a colon ":" to the property name.
  31. ''')
  32. def dynamic_properties() -> None:
  33. ui.echart({
  34. 'xAxis': {'type': 'category'},
  35. 'yAxis': {'axisLabel': {':formatter': 'value => "$" + value'}},
  36. 'series': [{'type': 'line', 'data': [5, 8, 13, 21, 34, 55]}],
  37. })