1
0

line_plot_documentation.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. from nicegui import events, ui
  2. from . import doc
  3. @doc.demo(ui.line_plot)
  4. def main_demo() -> None:
  5. import math
  6. from datetime import datetime
  7. line_plot = ui.line_plot(n=2, limit=20, figsize=(3, 2), update_every=5) \
  8. .with_legend(['sin', 'cos'], loc='upper center', ncol=2)
  9. def update_line_plot() -> None:
  10. now = datetime.now()
  11. x = now.timestamp()
  12. y1 = math.sin(x)
  13. y2 = math.cos(x)
  14. line_plot.push([now], [[y1], [y2]])
  15. line_updates = ui.timer(0.1, update_line_plot, active=False)
  16. line_checkbox = ui.checkbox('active').bind_value(line_updates, 'active')
  17. # END OF DEMO
  18. def handle_change(e: events.GenericEventArguments) -> None:
  19. def turn_off() -> None:
  20. line_checkbox.set_value(False)
  21. ui.notify('Turning off that line plot to save resources on our live demo server. 😎')
  22. line_checkbox.value = e.args
  23. if line_checkbox.value:
  24. ui.timer(10.0, turn_off, once=True)
  25. line_checkbox.on('update:model-value', handle_change, args=[None])
  26. doc.reference(ui.line_plot)