void MainWindow::readcsvfile() //读取csv
{QFile csvFile("C:/Users/Administrator/Desktop/Demo/0702.CSV");QStringList csvList;csvList.clear();if (csvFile.open(QIODevice::ReadWrite)) //对csv文件进行读写操作{QTextStream stream(&csvFile);while (!stream.atEnd()){csvList.push_back(stream.readLine()); //保存到List当中}csvFile.close();}else{QMessageBox::about(NULL, "csv文件", "未打开该文件!");}int i = 0;Q_FOREACH(QString str, csvList)   //遍历List{i = i + 1;QStringList valsplit = str.split(","); //分隔字符串if(i > 2){//得到深度、声速、温度QString depth = valsplit[0];QString sonicvelocity = valsplit[1];QString temperature = valsplit[2];double depthvalue = depth.toDouble();double sonicvalue = sonicvelocity.toDouble();double tempvalue = temperature.toDouble();//Q//MessageBox::warning(NULL, "dd", QString::number(tempvalue));QPointF point;point.setX(depthvalue);point.setY(sonicvalue);QPointF point2;point2.setX(depthvalue);point2.setY(tempvalue + 1510);vectors.append(point);vector2.append(point2);}}
}void MainWindow::lineChart() //绘制图
{//设置X,Y标题ui->qwtPlot->setAxisTitle(QwtPlot::xBottom, QString::fromLocal8Bit("深度(m)"));ui->qwtPlot->setAxisTitle(QwtPlot::yLeft, QString::fromLocal8Bit("声速(m/s)"));ui->qwtPlot->setAxisTitle(QwtPlot::yRight, QString::fromLocal8Bit("温度(°C)"));ui->qwtPlot->enableAxis(QwtPlot::yRight,true);ui->qwtPlot->setAxisScale(QwtPlot::yLeft,1538,1540,0.2);ui->qwtPlot->setAxisScale(QwtPlot::xBottom,0,30,2);ui->qwtPlot->setAxisScale(QwtPlot::yRight,28,30,0.2);//ui->qwtPlot->set//构造曲线数据QwtPointSeriesData* series = new QwtPointSeriesData(vectors);//设置网格QwtPlotGrid* grid = new QwtPlotGrid();grid->setPen(QColor(222, 222, 222), 1);grid->attach(ui->qwtPlot);//create plot itemQwtPlotCurve* curve1 = new QwtPlotCurve(QString::fromLocal8Bit("声速"));//设置数据curve1->setData(series);//设置画笔颜色==就是图像颜色curve1->setPen(QColor(255, 0, 0), 2, Qt::SolidLine);//使曲线更光滑curve1->setCurveAttribute(QwtPlotCurve::Fitted, true);//把曲线附加到qwtPlot上curve1->attach(ui->qwtPlot);//添加温度-深度曲线//构造曲线数据QwtPointSeriesData* series2 = new QwtPointSeriesData(vector2);//create plot itemQwtPlotCurve* curve2 = new QwtPlotCurve(QString::fromLocal8Bit("温度"));//设置数据curve2->setData(series2);//设置画笔颜色=图像颜色curve2->setPen(QColor(127, 222, 335), 2, Qt::SolidLine);//使曲线更光滑curve2->setCurveAttribute(QwtPlotCurve::Fitted, true);//把曲线附加到qwtPlot上curve2->attach(ui->qwtPlot);//设置图例QwtLegend *legend = new QwtLegend;legend->setDefaultItemMode(QwtLegendData::ReadOnly);ui->qwtPlot->insertLegend(legend,QwtPlot::BottomLegend);//插入图例ui->qwtPlot->replot();ui->qwtPlot->show();
}

需要第三方库QWT

运行结果:

QT读取csv文件并且绘制折线图相关推荐

  1. QT 读取csv文件-QT根据显示器大小设置窗口大小-QT绑定信号与槽

    QT 读取csv文件 废话不多说先上代码, 需要引入的头文件: 函数是自己写的一个小项目截取的一段,基本上思路就是这个.读取csv格式的和读取txt文件类似. #include <QFile&g ...

  2. 用python读取csv文件并绘制波形及频谱

    最近想用python处理一下故障录波数据,于是学习了一下python.我一直对数据绘图比较感兴趣,学了一点皮毛之后感觉还挺好用的,这一点python和matlab/octave是非常相近的. 先说一下 ...

  3. 【Python】读取CSV文件画箱线图

    目录 1.简介 2.使用 模板 数据集 单个箱型图 多个箱型图 (直接x=[x1,x2])

  4. Python读取CSV文件画折线图

    首先,我们先导入需要的模块,然后读取CSV文件的数据,在折线图上画出"Third"这一列的数据的折线图 画出的图表结果: import pandas as pd import ma ...

  5. Python读取excel文件中的数据,绘制折线图、散点图

    https://www.cnblogs.com/liulinghua90/p/9935642.html https://blog.csdn.net/qq_32458499/article/detail ...

  6. 使用python读取excel中的数据,并绘制折线图

    使用python读取excel中的数据,并绘制折线图 做实验的时候采集到一些数据,从文本拷贝到excel,然后从十六进制转换成十进制.图表是分析数据的有利工具,使用python绘制出的图表简明美观.所 ...

  7. Python读取excel/csv表格并通过折线图可视化显示

    Python读取excel/csv表格并通过折线图可视化显示 写作背景 参数 使用figure()函数重新申请一个figure对象 注意,每次调用figure的时候都会重新申请一个figure对象 第 ...

  8. 数据可视化:读取csv文件绘制图表

    怎样去读取csv文件: 怎样去读每一行的某一列: #提取并读取数据 读取每天的最高气温 import csvfilename = 'sitka_weather_07-2014.csv' with op ...

  9. python csv读取-Python读取csv文件(详解版,看了无师自通)

    前面程序展示的数据都是直接通过程序给出的,但实际应用可能需要展示不同来源(比如文件.网络).不同格式(比如 csv.JSON)的数据,这些数据可能有部分是损坏的,因此程序需要对这些数据进行处理. cs ...

最新文章

  1. intimidated
  2. C# 对Outlook联系人的增、删、查
  3. leetcode 28. 实现 strStr()(kmp)
  4. 香港2013迷你制汇节即将启幕
  5. Centos 6安装完美搭建mysql、php、apache之旅
  6. 当启动vue项目安装依赖时报错
  7. python模块整理12-pdb调试模块
  8. C语言:字符串中各类字符数的统计
  9. 部署nodejs报No package nodejs available
  10. 歌评-《Rex Incognito 尘世闲游》-陈致逸
  11. 群赛14----2017.9.24
  12. 数论——Baby Step Giant Step大步小步算法
  13. 高等数学——多元函数最值问题
  14. 水星路由器wan口ip显示0_路由器wan口ip地址显示0.0.0.0怎么办(2)
  15. 用C语言编程西瓜问题,C语言编写的小病毒
  16. 海思hi3516EV300_4G图传模组防雷防静电推荐图
  17. 英文文本关键词抽取——使用NLTK进行关键词抽取
  18. 201933 plsql设置及使用技巧—Jess
  19. 互联网不再适合创业 移动互联网不再制造马化腾
  20. 二、MT8168 KeyPad驱动指南

热门文章

  1. 面试官:分布式环境下,如何实现session共享
  2. 几行代码,轻松带你实现Java生成二维码功能!
  3. oracle11g的tnstimeout,redhat下oracle11g 配置listener.ora
  4. Java 内存模型(零)
  5. PHP_递归实现无限级分类
  6. delphi 第三方组件 log4cpp.dll
  7. UVA 1349 Optimal Bus Route Design (二分图最小权完美匹配)
  8. 深入浅出ObjC之消息 (转)
  9. cocos2d-x初探学习笔记(1)--HelloWorld .
  10. SQL 中操作XML类型数据