文章目录
- 界面设置
- 代码
界面设置
代码
#include "dialog.h"
#include "ui_dialog.h"
Dialog::Dialog(QWidget *parent)
: QDialog(parent)
, ui(new Ui::Dialog)
{
ui->setupUi(this);
//构建图标系列
lineSerise=new QLineSeries(this);
//为折线添加数据
for (size_t i=0;i<100;i++)
{
lineSerise->append(i,sin(0.6f*i));
}
//构建图标对象
m_chart=new QChart();
//注意:先添加到图表再创建坐标轴,否则无效
//1.将折线系列添加到图表
m_chart->addSeries(lineSerise);
//2.为图表添加默认坐标轴
m_chart->createDefaultAxes();
//隐藏图例
m_chart->legend()->hide();
//设置图标主题
m_chart->setTheme(QtCharts::QChart::ChartThemeBlueCerulean);
//设置标题
m_chart->setTitle(QString("图表1"));
//设置尺寸
m_chart->setGeometry(0,0,500,300);
//构建场景
m_pScene =new QGraphicsScene(this);
//为视图构建场景
ui->graphicsView->setScene(m_pScene);
//将图表添加到场景
m_pScene->addItem(m_chart);
//设置抗锯齿
ui->graphicsView->setRenderHint(QPainter::Antialiasing,true);
}
Dialog::~Dialog()
{
delete ui;
}