#ifndef CURVEPLOTWIDGET_H #define CURVEPLOTWIDGET_H #include #include #include #include #include #include #include #include QT_BEGIN_NAMESPACE namespace QtCharts { class QChart; class QChartView; class QLineSeries; class QValueAxis; } QT_END_NAMESPACE class CurvePlotWidget : public QWidget { Q_OBJECT public: explicit CurvePlotWidget(QWidget *parent = nullptr); int addSeries(const QString &name, const QColor &color); void appendPoint(int seriesIndex, double yValue); protected: void changeEvent(QEvent *e) override; private: void initChart(); void updateAxisRange(); QtCharts::QChart *m_chart = nullptr; QtCharts::QChartView *m_view = nullptr; QList m_series; QtCharts::QDateTimeAxis *m_axisX = nullptr; // 替换 QtCharts::QValueAxis *m_axisY = nullptr; static constexpr int MAX_POINTS = 300; static constexpr int TIME_WINDOW_S = 300; // 600 秒 = 10 分钟 int m_tick = 0; }; #endif // CURVEPLOTWIDGET_H