2018-12-28 10:48:24 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2021-07-13 14:52:26 +08:00
|
|
|
"""
|
2018-12-28 10:48:24 +08:00
|
|
|
Created on 2017年12月19日
|
2021-07-13 14:52:26 +08:00
|
|
|
@author: Irony
|
|
|
|
@site: https://pyqt.site , https://github.com/PyQt5
|
2018-12-28 10:48:24 +08:00
|
|
|
@email: 892768447@qq.com
|
|
|
|
@file: LineChart
|
|
|
|
@description:
|
2021-07-13 14:52:26 +08:00
|
|
|
"""
|
2018-12-28 10:48:24 +08:00
|
|
|
import sys
|
|
|
|
|
2021-07-13 14:52:26 +08:00
|
|
|
try:
|
|
|
|
from PyQt5.QtChart import QChartView, QLineSeries, QChart
|
|
|
|
from PyQt5.QtGui import QPainter
|
|
|
|
from PyQt5.QtWidgets import QApplication
|
|
|
|
except ImportError:
|
|
|
|
from PySide2.QtGui import QPainter
|
|
|
|
from PySide2.QtWidgets import QApplication
|
|
|
|
from PySide2.QtCharts import QtCharts
|
2018-12-28 10:48:24 +08:00
|
|
|
|
2021-07-13 14:52:26 +08:00
|
|
|
QChartView = QtCharts.QChartView
|
|
|
|
QChart = QtCharts.QChart
|
|
|
|
QLineSeries = QtCharts.QLineSeries
|
2018-12-28 10:48:24 +08:00
|
|
|
|
2021-07-13 14:52:26 +08:00
|
|
|
if __name__ == '__main__':
|
2018-12-28 10:48:24 +08:00
|
|
|
app = QApplication(sys.argv)
|
|
|
|
chart = QChart()
|
2021-07-13 14:52:26 +08:00
|
|
|
chart.setTitle('Line Chart 1')
|
2018-12-28 10:48:24 +08:00
|
|
|
series = QLineSeries(chart)
|
|
|
|
series.append(0, 6)
|
|
|
|
series.append(2, 4)
|
|
|
|
chart.addSeries(series)
|
|
|
|
chart.createDefaultAxes() # 创建默认轴
|
|
|
|
|
|
|
|
view = QChartView(chart)
|
|
|
|
view.setRenderHint(QPainter.Antialiasing) # 抗锯齿
|
|
|
|
view.resize(800, 600)
|
|
|
|
view.show()
|
|
|
|
sys.exit(app.exec_())
|