chart_documentation.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from nicegui import ui
  2. from ..documentation_tools import text_demo
  3. def main_demo() -> None:
  4. from random import random
  5. chart = ui.chart({
  6. 'title': False,
  7. 'chart': {'type': 'bar'},
  8. 'xAxis': {'categories': ['A', 'B']},
  9. 'series': [
  10. {'name': 'Alpha', 'data': [0.1, 0.2]},
  11. {'name': 'Beta', 'data': [0.3, 0.4]},
  12. ],
  13. }).classes('w-full h-64')
  14. def update():
  15. chart.options['series'][0]['data'][0] = random()
  16. chart.update()
  17. ui.button('Update', on_click=update)
  18. def more() -> None:
  19. @text_demo('Chart with extra dependencies', '''
  20. To use a chart type that is not included in the default dependencies, you can specify extra dependencies.
  21. This demo shows a solid gauge chart.
  22. ''')
  23. def extra_dependencies() -> None:
  24. ui.chart({
  25. 'title': False,
  26. 'chart': {'type': 'solidgauge'},
  27. 'yAxis': {
  28. 'min': 0,
  29. 'max': 1,
  30. },
  31. 'series': [
  32. {'data': [0.42]},
  33. ],
  34. }, extras=['solid-gauge']).classes('w-full h-64')