echart_documentation.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from nicegui import ui
  2. from . import doc
  3. @doc.demo(ui.echart)
  4. def main_demo() -> None:
  5. from random import random
  6. echart = ui.echart({
  7. 'xAxis': {'type': 'value'},
  8. 'yAxis': {'type': 'category', 'data': ['A', 'B'], 'inverse': True},
  9. 'legend': {'textStyle': {'color': 'gray'}},
  10. 'series': [
  11. {'type': 'bar', 'name': 'Alpha', 'data': [0.1, 0.2]},
  12. {'type': 'bar', 'name': 'Beta', 'data': [0.3, 0.4]},
  13. ],
  14. })
  15. def update():
  16. echart.options['series'][0]['data'][0] = random()
  17. echart.update()
  18. ui.button('Update', on_click=update)
  19. @doc.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. @doc.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. })
  38. doc.reference(ui.echart)