当前位置:网站首页>绘制温度曲线图;QChart,
绘制温度曲线图;QChart,
2022-08-10 09:26:00 【Lee Neo】
.pro
QT += core gui charts
widget.h
#include "widget.h"
#include "ui_widget.h"
#include <QChart>
#include <QChartView>
#include <QValueAxis>
#include <QLineSeries>
#include <QSplineSeries>
#include <QPen>
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
this->setLayout(ui->verticalLayout);
//1创建图表视图;这里直接在ui中创建了
//QChartView *chartView = new QChartView();
//2、创建图表;
QChart *chart = new QChart();
//3、创建坐标轴;
QValueAxis *valueAxisX = new QValueAxis();
QValueAxis *valueAxisY = new QValueAxis();
//4、设置坐标轴范围;
valueAxisX->setRange(0,5000);
valueAxisY->setRange(0,110);
//5、设置坐标轴标题和显示格式;
valueAxisX->setTitleText("时间/ms");
valueAxisY->setTitleText("温度/℃");
valueAxisX->setLabelFormat("%d");
valueAxisY->setLabelFormat("%.2f");
//设置坐标轴的精度;
valueAxisX->setTickCount(11);
valueAxisY->setTickCount(11);
//6、图表添加坐标轴;
chart->addAxis(valueAxisX,Qt::AlignBottom);
chart->addAxis(valueAxisY,Qt::AlignLeft);
//7、设置图表的标题以及图例显示;
chart->setTitle("温度变化图");
chart->legend()->setVisible(false);
//8、创建曲线;
QSplineSeries *splineSeres = new QSplineSeries;
splineSeres->append(0,50);
splineSeres->append(1000,100);
splineSeres->append(2000,80);
splineSeres->append(3000,40);
splineSeres->append(4000,60);
splineSeres->append(5000,50);
//9、设置曲线的颜色;
QPen pen(QColor(0xff5566));
pen.setWidth(5);
splineSeres->setPen(pen);
//10、图表添加线;
chart->addSeries(splineSeres);
//11、将曲线和坐标轴联系起来;
splineSeres->attachAxis(valueAxisX);
splineSeres->attachAxis(valueAxisY);
//12、将图表放置在图表视图显示出来;
ui->chartView->setChart(chart);
}
Widget::~Widget()
{
delete ui;
}
效果:
边栏推荐
猜你喜欢
并查集学习
I don't want to do accounting anymore, Die changed to a new one, moved forward bravely, and finally successfully passed the career change test to double his monthly salary~
BUUCTF problem solving PWN 】 【 record (4-6 pages continuously updated)
FPGA中BEL Site Tile FSR SLR分别指什么?
09 【Attributes继承 provide与inject】
Spotify expresses its architectural design using the C4 model
【API 管理】什么是 API 管理,为什么它很重要?
【微服务架构】为故障设计微服务架构
【OAuth2】二十、OAuth2扩展协议 PKCE
J9 Number Theory: Macro Analysis of DAO Characteristics
随机推荐
【API Management】What is API Management and why is it important?
DeepFake换脸诈骗怎么破?让他侧个身
Mongo的简单操作-数据库用户的查询、创建与删除
js读取excel时间格式转换
CAD to WPF: Tips on converting CAD drawing files to WPF vector code files (xaml files)
爬虫-爬取某小说网站
The first offline workshop in 2022!Data application experience day for application developers is coming | TiDB Workshop Day
封装和使用通用的工具栏组件
DAY25:逻辑漏洞
将博客搬至CSDN
Shell functions and arrays
09 【Attributes继承 provide与inject】
【API 管理】什么是 API 管理,为什么它很重要?
PostgreSQL 2022 发展现状:13 个非 psql 工具
亚信AntDB数据库有啥业务应用场景和应用案例?
FPGA时钟篇(三) MRCC和SRCC的区别
如何理解BIO、NIO、AIO的区别
用高质量图像标注数据加速AI商业化落地
打工人的第27天-平凡但不平淡的日子
2 模块一:科研思维培养