You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

32 lines
849 B

#include "mainwindow.h"
#include <QtCharts>
#include "./ui_mainwindow.h"
// 两种引入命名空间方法
// using namespace QtCharts; // 使用unsing引入命名空间
QT_CHARTS_USE_NAMESPACE // 使用内置宏引入命名空间
MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
QChartView* chartView = new QChartView(this);
QLineSeries* series = new QLineSeries();
for (quint32 i = 0; i < 100; i++) {
// 参数 x 为循环自增变量 i,参数 y 为正弦函数Y值
series->append(i, sin(static_cast<double>(0.6f * i)));
}
// 将系列添加到图表
chartView->chart()->addSeries(series);
// 基于已添加到图表的 series 来创建默认的坐标轴
chartView->chart()->createDefaultAxes();
}
MainWindow::~MainWindow() { delete ui; }