当前位置:网站首页>绘制温度曲线图;QChart,
绘制温度曲线图;QChart,
2022-08-10 09:26:00 【Lee Neo】
.pro
QT += core gui chartswidget.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;
}
效果:

边栏推荐
- 12 【其它组合式API】
- Defending risks with technology and escorting cloud native | Tongchuang Yongyi X Boyun held a joint product launch conference
- DAY25:逻辑漏洞
- 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~
- 数据中台解决方案及未来发展方向
- 硬件工程师90天学习资料及笔记汇总
- 封装和使用通用的工具栏组件
- 支付 x 聚合 x 分账 - 回流平台“二清”风险规避之路
- 重学冒泡排序
- 1499. 满足不等式的最大值 堆/双端队列
猜你喜欢

Docker搭建Mysql一主一从

ARM Architecture 3: Addressing and Exception Handling of ARM Instructions

J9数字论:关于DAO 特点的宏观分析

「微服务架构」编曲与编舞——让系统协同工作的不同模式

PostgreSQL 2022 发展现状:13 个非 psql 工具

FPGA时钟篇(三) MRCC和SRCC的区别

J9 Number Theory: Macro Analysis of DAO Characteristics

shell------ commonly used gadgets, sort, uniq, tr, cut

Flink部署 完整使用 (第三章)

DAY25:逻辑漏洞
随机推荐
shell------ commonly used gadgets, sort, uniq, tr, cut
地平线:面向规模化量产的智能驾驶系统和软件开发
DAY25:逻辑漏洞复现
JWT: To own me is to have power
JWT:拥有我,即拥有权力
[Metaverse Omi Says] Listen to how Rabbit Fan Rabbit creates a new era of trendy play from virtual to reality
数据库注入提权总结(一)
Flink快速上手 完整使用 (第二章)
Controller层代码这么写,简洁又优雅!
傅立叶级数与傅里叶变换
[OAuth2] Nineteen, OpenID Connect dynamic client registration
【API 管理】什么是 API 管理,为什么它很重要?
DAY25: Logic Vulnerability
CAD转WPF: 关于CAD图纸文件转换为WPF矢量代码文件(xaml文件)的技巧
How to understand the difference between BIO, NIO, and AIO
navicat导入SQL文件报:[ERR] 2006 - MySQL server has gone away [ERR] -- MySQL dump 10.13 Distrib 5.7.34
06 【生命周期 模板引用】
高等数学(第七版)同济大学 习题4-3 个人解答
OLTP and OLAP database architecture 】 【 : actual comparison
FPGA时钟篇(一) 7系列的时钟结构