qt使用QCustomPlot 將數據曲線圖化


標 題: qt使用QCustomPlot  將數據曲線圖化
作 者: itdef
鏈 接: http://www.cnblogs.com/itdef/p/4028551.html 

歡迎轉帖 請保持文本完整並注明出處

 

使用QCustomPlot 開源代碼將數據以曲線圖顯示

QCustomPlot  官方網站http://www.qcustomplot.com/

下載有三種包 有示例 有文檔 有代碼,但是核心文件就是兩個 qcustomplot.cpp qcustomplot.h

先看QCustomPlot.tar.gz 這個壓縮包 解壓后 examples文件夾是使用例子(使用qt編譯,qt安裝請另行搜索)

documentation文件夾是文檔

 

另一個QCustomPlot-sharedlib.tar壓縮包 提供將核心文件編譯為lib文件使用的代碼示例(windows 平台下)

 

我將示例代碼稍作修改 為以后顯示監控系統數據做准備

使用代碼如下

#include <QApplication>
#include <QMainWindow>
#include <QVBoxLayout>
#include <QPushButton>
#include "qcustomplot.h"

int main(int argc, char *argv[])
{
  QApplication a(argc, argv);
  QWidget window;
  QVBoxLayout *layout = new QVBoxLayout;
  
  // setup customPlot as central widget of window:
  QCustomPlot customPlot;
  QCustomPlot customPlot0;
  
  
  // create plot (from quadratic plot example):
  QVector<double> x(101), y(101);
  for (int i=0; i<101; ++i)
  {
    x[i] = i/50.0 - 1;
    y[i] = x[i]*x[i];
  }
  customPlot.addGraph();
  customPlot.graph(0)->setData(x, y);
  customPlot.xAxis->setLabel("x");
  customPlot.yAxis->setLabel("y");
  customPlot.rescaleAxes();
  
  
   QVector<double> x0(101), y0(101);
  for (int i=0; i<101; ++i)
  {
    x0[i] = i/10.0 - 1;
    y0[i] = x0[i]*x0[i];
  }
  customPlot0.addGraph();
  customPlot0.graph(0)->setData(x0, y0);
  customPlot0.xAxis->setLabel("x");
  customPlot0.yAxis->setLabel("y");
  customPlot0.rescaleAxes();
  
  
  
  layout->addWidget(&customPlot);
  layout->addWidget(&customPlot0);
  window.setLayout(layout);
  
  window.setGeometry(900, 100, 300, 400);
  window.show();
  return a.exec();
}

 

效果圖:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM