highchart_documentation.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. from nicegui import ui
  2. from ...model import UiElementDocumentation
  3. class HighchartDocumentation(UiElementDocumentation, element=ui.highchart):
  4. def main_demo(self) -> None:
  5. from random import random
  6. chart = ui.highchart({
  7. 'title': False,
  8. 'chart': {'type': 'bar'},
  9. 'xAxis': {'categories': ['A', 'B']},
  10. 'series': [
  11. {'name': 'Alpha', 'data': [0.1, 0.2]},
  12. {'name': 'Beta', 'data': [0.3, 0.4]},
  13. ],
  14. }).classes('w-full h-64')
  15. def update():
  16. chart.options['series'][0]['data'][0] = random()
  17. chart.update()
  18. ui.button('Update', on_click=update)
  19. def more(self) -> None:
  20. @self.demo('Chart with extra dependencies', '''
  21. To use a chart type that is not included in the default dependencies, you can specify extra dependencies.
  22. This demo shows a solid gauge chart.
  23. ''')
  24. def extra_dependencies() -> None:
  25. ui.highchart({
  26. 'title': False,
  27. 'chart': {'type': 'solidgauge'},
  28. 'yAxis': {
  29. 'min': 0,
  30. 'max': 1,
  31. },
  32. 'series': [
  33. {'data': [0.42]},
  34. ],
  35. }, extras=['solid-gauge']).classes('w-full h-64')
  36. @self.demo('Chart with draggable points', '''
  37. This chart allows dragging the series points.
  38. You can register callbacks for the following events:
  39. - `on_point_click`: called when a point is clicked
  40. - `on_point_drag_start`: called when a point drag starts
  41. - `on_point_drag`: called when a point is dragged
  42. - `on_point_drop`: called when a point is dropped
  43. ''')
  44. def drag() -> None:
  45. ui.highchart(
  46. {
  47. 'title': False,
  48. 'plotOptions': {
  49. 'series': {
  50. 'stickyTracking': False,
  51. 'dragDrop': {'draggableY': True, 'dragPrecisionY': 1},
  52. },
  53. },
  54. 'series': [
  55. {'name': 'A', 'data': [[20, 10], [30, 20], [40, 30]]},
  56. {'name': 'B', 'data': [[50, 40], [60, 50], [70, 60]]},
  57. ],
  58. },
  59. extras=['draggable-points'],
  60. on_point_click=lambda e: ui.notify(f'Click: {e}'),
  61. on_point_drag_start=lambda e: ui.notify(f'Drag start: {e}'),
  62. on_point_drop=lambda e: ui.notify(f'Drop: {e}')
  63. ).classes('w-full h-64')