61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
简单图表测试
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
def test_chart_widget():
|
|
"""测试图表组件是否能正常工作"""
|
|
print("=== 图表组件测试 ===")
|
|
|
|
try:
|
|
from PyQt6.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget
|
|
from charts import BarChartWidget
|
|
|
|
app = QApplication(sys.argv)
|
|
|
|
# 创建测试窗口
|
|
window = QMainWindow()
|
|
central_widget = QWidget()
|
|
layout = QVBoxLayout()
|
|
|
|
# 创建测试数据
|
|
test_data = [15, 1, 49, 0, 0, 0, 5] # 实际的7天数据
|
|
test_labels = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
|
|
|
|
# 创建柱状图
|
|
chart = BarChartWidget(
|
|
test_data,
|
|
title='7天阅读统计测试',
|
|
unit='分钟',
|
|
labels=test_labels,
|
|
value_format=lambda v: f'{int(v)}'
|
|
)
|
|
|
|
layout.addWidget(chart)
|
|
central_widget.setLayout(layout)
|
|
window.setCentralWidget(central_widget)
|
|
window.setWindowTitle('图表测试')
|
|
window.resize(600, 400)
|
|
|
|
print("✅ 图表组件创建成功")
|
|
print("💡 如果看到图表窗口,说明图表组件工作正常")
|
|
print("💡 如果没有看到图表,说明图表组件有问题")
|
|
|
|
window.show()
|
|
# 不运行事件循环,只是测试创建
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"❌ 图表组件测试失败: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
success = test_chart_widget()
|
|
print(f"\n图表组件状态: {'正常' if success else '异常'}") |