test_candle_chart.py
import dearpygui.dearpygui as dpg
import random
def create_test_chart():
# 生成测试数据
x = list(range(10))
opens = [random.randint(90, 110) for _ in range(10)]
closes = [o + random.randint(-10, 10) for o in opens]
highs = [max(o, c) + random.randint(0, 5) for o, c in zip(opens, closes)]
lows = [min(o, c) - random.randint(0, 5) for o, c in zip(opens, closes)]
# 创建上下文
dpg.create_context()
with dpg.window(label="测试蜡烛图", tag="test_window", width=800, height=600):
with dpg.plot(width=-1, height=-1, tag="test_plot"):
with dpg.plot_axis(dpg.mvXAxis, label="X轴"):
pass
with dpg.plot_axis(dpg.mvYAxis, label="Y轴"):
dpg.add_candle_series(x=x, opens=opens, closes=closes, highs=highs, lows=lows, tag="test_candle")
dpg.create_viewport(title="测试蜡烛图", width=800, height=600)
dpg.setup_dearpygui()
dpg.show_viewport()
print("蜡烛图创建成功!")
try:
dpg.start_dearpygui()
except Exception as e:
print(f"错误: {e}")
finally:
dpg.destroy_context()
if __name__ == "__main__":
create_test_chart()