qt 动态生成柱状图

news2025/4/20 11:46:56

cpp文件

#include "mform.h"
#include "ui_mform.h"
#include <QBarSeries>
#include <QBarSet>
#include <QtCharts>
#include <QPushButton>
#include <QtCharts/QChartView>
#include <QtCharts/QPieSeries>
#include <QtCharts/QPieSlice>
#include <QtCharts/QAbstractBarSeries>
#include <QtCharts/QPercentBarSeries>
#include <QtCharts/QStackedBarSeries>
#include <QtCharts/QBarSeries>
#include <QtCharts/QBarSet>
#include <QtCharts/QLineSeries>
#include <QtCharts/QSplineSeries>
#include <QtCharts/QScatterSeries>
#include <QtCharts/QAreaSeries>
#include <QtCharts/QLegend>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QFormLayout>
#include <QtWidgets/QComboBox>
#include <QtWidgets/QSpinBox>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QGroupBox>
#include <QtWidgets/QLabel>
#include <QtCharts/QBarCategoryAxis>
#include <QtWidgets/QApplication>
#include <QtCharts/QValueAxis>
#include <QVector>
#include <QDebug>

QVector<int>data0;
QVector<int>data1;
QVector<int>data2;
QVector<int>data3;

using namespace QtCharts;

MForm::MForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MForm)
{
    ui->setupUi(this);
    for (int i = 0; i < 6; ++i) {
        data0.push_front(0);
        data1.push_front(0);
        data2.push_front(0);
        data3.push_front(0);
    }
    connect(ui->pushButton,&QPushButton::clicked,[=](){
        data0.push_front(ui->lineEdit_1->text().toInt());
        data1.push_front(ui->lineEdit_2->text().toInt());
        data2.push_front(ui->lineEdit_3->text().toInt());
        data3.push_front(ui->lineEdit_4->text().toInt());

        QBarSet *set0 = new QBarSet("日光(min)");
        QBarSet *set1 = new QBarSet("UV(min)");
        QBarSet *set2 = new QBarSet("日光(month)");
        QBarSet *set3 = new QBarSet("UV(month)");

        QVector<int>::iterator it1 = data0.begin();
        QVector<int>::iterator it2 = data1.begin();
        QVector<int>::iterator it3 = data2.begin();
        qDebug()<<it1<<"|"<<it2<<"|"<<it3;
        //if(i)
        for(QVector<int>::iterator it4 = data3.begin();it4<data3.begin()+5;it4++)
        {
            *set0 << *it1<< *(it1+1) << *(it1+2) << *(it1+3) << *(it1+4) << *(it1+5);
            *set1 << *it2<< *(it2+1) << *(it2+2) << *(it2+3) << *(it2+4) << *(it2+5);
            *set2 << *it3<< *(it3+1) << *(it3+2) << *(it3+3) << *(it3+4) << *(it3+5);
            *set3 << *it4<< *(it4+1) << *(it4+2) << *(it4+3) << *(it4+4) << *(it4+5);
            it1++;
            it2++;
            it3++;
        }
    //    *set0 << 5 << 2 << 3 << 4 << 5 << 6;
    //    *set1 << 7 << 0 << 0 << 4 << 0 << 7;
    //    *set2 << 9 << 5 << 8 << 19<< 8 << 5;
    //    *set3 << 5 << 6 << 7 << 3 << 4 << 5;
        QBarSeries *series = new QBarSeries();
        series->append(set0);
        series->append(set1);
        series->append(set2);
        series->append(set3);
        QChart *c = new QChart();
        c->setTitle("光照UV强度");
        c->addSeries(series);
        ui->graphicsView->setChart(c);
        c->legend()->setVisible(true);
        c->setAnimationOptions(QChart::SeriesAnimations);
        ui->graphicsView->setRenderHint(QPainter::Antialiasing);
        c->createDefaultAxes();//创建默认的左侧的坐标轴(根据 QBarSet 设置的值)
        QValueAxis *axisX = new QValueAxis();//轴变量、数据系列变量,都不能声明为局部临时变量
        QValueAxis *axisY = new QValueAxis();//创建X/Y轴
        axisX->setRange(0, 6);
        axisY->setRange(0, 10);//设置X/Y显示的区间
        c->setAxisX(axisX);
        c->setAxisY(axisY);//设置chart的坐标轴
        series->attachAxis(axisX);
        c->legend()->setVisible(true); //设置图例为显示状态
        c->legend()->setAlignment(Qt::AlignBottom);//设置图例的显示位置在底部

    });
}

MForm::~MForm()
{
    delete ui;
}

.h文件

#ifndef MFORM_H
#define MFORM_H

#include <QWidget>
#include <QtCharts>
namespace Ui {
class MForm;
}

class MForm : public QWidget
{
    Q_OBJECT

public:
    explicit MForm(QWidget *parent = 0);
    ~MForm();

private:
    Ui::MForm *ui;
};

#endif // MFORM_H

ui文件

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1280177.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

图解系列--功能追加协议,构建Web内容

功能追加协议 1.消除 HTTP 瓶颈的 SPDY 1.1.HTTP 的瓶颈 使用 HTTP 协议探知服务器上是否有内容更新&#xff0c;就必须频繁地从客户端到服务器端进行确认。如果服务器上没有内容更新&#xff0c;那么就会产生徒劳的通信。 若想在现有 Web 实现所需的功能&#xff0c;以下这些…

LLM | 一文搞懂Langchain的概念,相关组件,以及大模型微调~

本文主要介绍了 Langchain的概念&#xff0c;相关组件&#xff0c;以及大模型微调代码实现~ 1.什么是LangChain&#xff1f; LangChain是一个平台&#xff0c;提供工具和API&#xff0c;用于构建由语言模型&#xff08;LLM&#xff09;驱动的应用程序。它简化了 LLM 与项目的集…

自动驾驶学习笔记(十三)——感知基础

#Apollo开发者# 学习课程的传送门如下&#xff0c;当您也准备学习自动驾驶时&#xff0c;可以和我一同前往&#xff1a; 《自动驾驶新人之旅》免费课程—> 传送门 《Apollo Beta宣讲和线下沙龙》免费报名—>传送门 文章目录 前言 传感器 测距原理 坐标系 标定 同…

一个用c#瞎写的sftp工具

0.下载地址 https://wwus.lanzouj.com/iOZUv1gkgpze 密码:123456 1.能进行单个和批量下载, 没有弄上传 2.速度奇差,可能是某些地方没弄好.有一定的进度显示,但是不太准. 3.很多地方没弄好,有能力的自己弄一下 4.在app.config文件配置sftp

大小堆的实现(C语言)

目录 前言 一种完全二叉树&#xff1a;堆 堆的概念 堆的性质 建堆的时间复杂度 建堆的空间复杂度&#xff1a; 小堆的实现 必要补充 堆的初始化 堆的销毁 向上调整算法 堆的插入 向下调整算法 堆的删除 获取堆顶元素 获取堆中元素个数 堆的判空 最终代码 He…

SpringSecurity 三更草堂 学习笔记

SpringSecurity从入门到精通 0. 简介 Spring Security 是 Spring 家族中的一个安全管理框架。相比与另外一个安全框架Shiro&#xff0c;它提供了更丰富的功能&#xff0c;社区资源也比Shiro丰富。 一般来说中大型的项目都是使用SpringSecurity 来做安全框架。小项目有Shiro的…

数据结构奇妙旅程之顺序表和链表

꒰˃͈꒵˂͈꒱ write in front ꒰˃͈꒵˂͈꒱ ʕ̯•͡˔•̯᷅ʔ大家好&#xff0c;我是xiaoxie.希望你看完之后,有不足之处请多多谅解&#xff0c;让我们一起共同进步૮₍❀ᴗ͈ . ᴗ͈ აxiaoxieʕ̯•͡˔•̯᷅ʔ—CSDN博客 本文由xiaoxieʕ̯•͡˔•̯᷅ʔ 原创 CSDN …

第一百八十六回 DropdownMenu组件

文章目录 1. 概念介绍2. 使用方法2.1 DropdownMenu2.1 DropdownMenuEntry 3. 示例代码4. 内容总结 我们在上一章回中介绍了"如何禁止页面跟随手机自动旋转"相关的内容&#xff0c;本章回中将介 绍DropdownMenu组件.闲话休提&#xff0c;让我们一起Talk Flutter吧。 …

TeXworks 初次使用 debug方法

下载Texlive&#xff0c;打开TeXworks editor 编译排版&#xff0c;可能会报很多错&#xff1a; 1. ! Fatal Package fontspec Error: The fontspec package requires either XeTeX or (fontspec) LuaTeX. (fontspec) (fontspec) …

【前沿技术】扩散模型是什么

0. 前言 扩散模型的灵感来自非平衡热力学。他们定义了一个马尔可夫扩散步骤链&#xff0c;以缓慢地将随机噪声添加到数据中&#xff0c;然后学习逆转扩散过程以从噪声中构建所需的数据样本。与VAE或流动模型不同&#xff0c;扩散模型是通过固定程序学习的&#xff0c;并且潜在变…

【学术精选】地球系统科学顶级国际会议 IGARSS 2024

顶级会议推荐 英文名称&#xff1a;International Symposium of Geoscience and RemoteSensing, IGARSS 2024 英文简称&#xff1a;IGARSS 2024 中文名称&#xff1a;国际地球科学与遥感研讨会 ​会议信息 重要日期&#xff1a; Community Contributed Session Proposal Dea…

基于ZLMediaKit的webrtc实时视频传输demo搭建

环境 ubuntu 20.04 ​ gcc version 9.4.0 ​ cmake version 3.16.3 部署ZLMediaKit流媒体服务器 安装openssl 首先可以检查一下自己的openssl的版本如果是1.1.1以上就可以忽略这一步 wget https://www.openssl.org/source/openssl-1.1.1k.tar.gz tar -xvzf openssl-1.1.1k…

基于springboot 学生学情预警系统-计算机毕设 附源码57567

springboot 学生学情预警系统 摘 要 科技进步的飞速发展引起人们日常生活的巨大变化&#xff0c;电子信息技术的飞速发展使得电子信息技术的各个领域的应用水平得到普及和应用。信息时代的到来已成为不可阻挡的时尚潮流&#xff0c;人类发展的历史正进入一个新时代。在现实运…

Python如何使用pip安装模块和包与绘图时如何显示中文

Python如何使用pip安装模块和包 使用pip安装python模块和包 方式一&#xff1a;1.进入命令行2.敲入pip命令&#xff1a;pip install 包名 。由于python官网下载速度太慢&#xff0c;可以通过添加参数从清华镜像下载包&#xff08;-i https://pypi.tuna.tsinghua.edu.cn/simpl…

Web漏洞分析-SQL注入XXE注入(上)

随着互联网的不断普及和Web应用的广泛应用&#xff0c;网络安全问题愈发引起广泛关注。在网络安全领域中&#xff0c;SQL注入和XXE注入是两个备受关注的话题&#xff0c;也是导致许多安全漏洞的主要原因之一。本博客将深入研究这两种常见的Web漏洞&#xff0c;带您探寻背后的原…

curl --compressed报错,此版本不支持此命令

出现这个问题是因为微软windows自带的curl不支持这个选项,验证如下 执行where curl 时,可以看到输出为 C:\Windows\System32\curl.ee 解决方法是使用其它curl,下载地址如下 curl for Windows https://curl.se/windows/ 然后把安装目录的bin目录放到path环境变量里最开始, 让…

十大经典系统架构设计面试题

十大经典系统架构设计面试题_架构_程序员石磊_InfoQ写作社区翻译自&#xff1a;https://medium.com/geekculture/top-10-system-design-interview-questions-10f7b5ea123d在我作为微软和Facebhttps://xie.infoq.cn/article/4c0c9328a725a76922f6547ad 任何 SDI 问题的提示 通过…

能源企业管理ERP系统都有哪些?可以帮助企业解决哪些难点

能源企业在不同的发展阶段面对的经营压力以及遇到的管理问题各异&#xff0c;随着部分产品结构的复杂化&#xff0c;日常经营管理工作也愈加繁琐。 有些能源企业内部存在信息传递不畅、经营数据统计不及时、部门协作效率低、多仓库和多平台数据不统一等情况&#xff0c;而这些…

web:very_easy_sql(sql、ssrf、gopher协议sql注入)

题目 页面显示如下 显示不是内部用户&#xff0c;无法识别信息 查看源码&#xff0c;找到一个use.php 访问之后显示如下 随便输入了一个&#xff0c;发现url有参数显示 试一下靶机的网址&#xff0c;返回nonono 联系之前原始页面写的“不是内网用户&#xff0c;无法别识身份”…

简单句子成分、阅读技巧

四、段落的主旨题&#xff1a;问这一段讲了什么&#xff08;一般都在段落的第一句话或最后一句话&#xff09; 词汇题的答案一般都在生词的上一句或者下一句 做题步骤&#xff1a; 1、先标段落 2、看题&#xff0c;划出关键词 3、去原文定位&#xff0c;标注中文意思 4、第一遍…