1
0

highchart_documentation.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. from nicegui import ui
  2. from . import doc
  3. @doc.demo(ui.highchart)
  4. def main_demo() -> 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. @doc.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. @doc.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')
  63. doc.reference(ui.highchart)