highchart_documentation.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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.highchart({
  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.highchart({
  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')
  35. @text_demo('Chart with draggable points', '''
  36. This chart allows dragging the series points.
  37. You can register callbacks for the following events:
  38. - `on_point_click`: called when a point is clicked
  39. - `on_point_drag_start`: called when a point drag starts
  40. - `on_point_drag`: called when a point is dragged
  41. - `on_point_drop`: called when a point is dropped
  42. ''')
  43. def drag() -> None:
  44. ui.highchart(
  45. {
  46. 'title': False,
  47. 'plotOptions': {
  48. 'series': {
  49. 'stickyTracking': False,
  50. 'dragDrop': {'draggableY': True, 'dragPrecisionY': 1},
  51. },
  52. },
  53. 'series': [
  54. {'name': 'A', 'data': [[20, 10], [30, 20], [40, 30]]},
  55. {'name': 'B', 'data': [[50, 40], [60, 50], [70, 60]]},
  56. ],
  57. },
  58. extras=['draggable-points'],
  59. on_point_click=lambda e: ui.notify(f'Click: {e}'),
  60. on_point_drag_start=lambda e: ui.notify(f'Drag start: {e}'),
  61. on_point_drop=lambda e: ui.notify(f'Drop: {e}')
  62. ).classes('w-full h-64')