浏览代码

use similar demo for both chart and echart

Falko Schindler 1 年之前
父节点
当前提交
e3e15d20e8
共有 1 个文件被更改,包括 11 次插入6 次删除
  1. 11 6
      website/more_documentation/echart_documentation.py

+ 11 - 6
website/more_documentation/echart_documentation.py

@@ -2,15 +2,20 @@ from nicegui import ui
 
 
 def main_demo() -> None:
-    chart = ui.echart({
+    from random import random
+
+    echart = ui.echart({
         'xAxis': {'type': 'value'},
-        'yAxis': {'type': 'value'},
-        'series': [{'data': [[0, 0], [1, 1]], 'type': 'line'}],
+        'yAxis': {'type': 'category', 'data': ['A', 'B'], 'inverse': True},
+        'legend': {'textStyle': {'color': 'gray'}},
+        'series': [
+            {'type': 'bar', 'name': 'Alpha', 'data': [0.1, 0.2]},
+            {'type': 'bar', 'name': 'Beta', 'data': [0.3, 0.4]},
+        ],
     })
 
     def update():
-        x = len(chart.options['series'][0]['data'])
-        chart.options['series'][0]['data'].append([x, x**2])
-        chart.update()
+        echart.options['series'][0]['data'][0] = random()
+        echart.update()
 
     ui.button('Update', on_click=update)