QwtPlot画曲线
2015-08-11 14:33
447 查看
直接用代码写
#include <QtGui/QApplication>
#include <Qt/qmath.h>
#include <QVector>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_magnifier.h>
#include <qwt_plot_panner.h>
#include <qwt_legend.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QwtPlot plot(QwtText("CppQwtExample1"));
plot.resize(640,400);
//设置坐标轴的名称
plot.setAxisTitle(QwtPlot::xBottom, "x->");
plot.setAxisTitle(QwtPlot::yLeft, "y->");
//设置坐标轴的范围
plot.setAxisScale(QwtPlot::xBottom, 0.0, 2.0 * M_PI);
plot.setAxisScale(QwtPlot::yLeft, -1.0, 1.0);
//设置右边标注
plot.insertLegend(new QwtLegend(), QwtPlot::RightLegend);
//使用滚轮放大/缩小
(void) new QwtPlotMagnifier( plot.canvas() );
//使用鼠标左键平移
(void) new QwtPlotPanner( plot.canvas() );
//计算曲线数据
QVector<double> xs;
QVector<double> ys;
for (double x = 0; x < 2.0 * M_PI; x+=(M_PI / 10.0))
{
xs.append(x);
ys.append(qSin(x));
}
//构造曲线数据
QwtPointArrayData * const data = new QwtPointArrayData(xs, ys);
QwtPlotCurve curve("Sine");
curve.setData(data);//设置数据
curve.setStyle(QwtPlotCurve::Lines);//直线形式
curve.setCurveAttribute(QwtPlotCurve::Fitted, true);//是曲线更光滑
curve.setPen(QPen(Qt::blue));//设置画笔
curve.attach(&plot);//把曲线附加到plot上
plot.show();
return a.exec();
}
设计器设计
#include <QtGui/QApplication>
#include <Qt/qmath.h>
#include <QVector>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_magnifier.h>
#include <qwt_plot_panner.h>
#include <qwt_legend.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QwtPlot plot(QwtText("CppQwtExample1"));
plot.resize(640,400);
//设置坐标轴的名称
plot.setAxisTitle(QwtPlot::xBottom, "x->");
plot.setAxisTitle(QwtPlot::yLeft, "y->");
//设置坐标轴的范围
plot.setAxisScale(QwtPlot::xBottom, 0.0, 2.0 * M_PI);
plot.setAxisScale(QwtPlot::yLeft, -1.0, 1.0);
//设置右边标注
plot.insertLegend(new QwtLegend(), QwtPlot::RightLegend);
//使用滚轮放大/缩小
(void) new QwtPlotMagnifier( plot.canvas() );
//使用鼠标左键平移
(void) new QwtPlotPanner( plot.canvas() );
//计算曲线数据
QVector<double> xs;
QVector<double> ys;
for (double x = 0; x < 2.0 * M_PI; x+=(M_PI / 10.0))
{
xs.append(x);
ys.append(qSin(x));
}
//构造曲线数据
QwtPointArrayData * const data = new QwtPointArrayData(xs, ys);
QwtPlotCurve curve("Sine");
curve.setData(data);//设置数据
curve.setStyle(QwtPlotCurve::Lines);//直线形式
curve.setCurveAttribute(QwtPlotCurve::Fitted, true);//是曲线更光滑
curve.setPen(QPen(Qt::blue));//设置画笔
curve.attach(&plot);//把曲线附加到plot上
plot.show();
return a.exec();
}
设计器设计
#include "mainwindow.h" #include "ui_mainwindow.h" #include "qwt_legend.h" #include "qwt_plot_magnifier.h" #include "qwt_plot_panner.h" #include "qwt_point_data.h" #include "qwt_plot_curve.h" #include <QVector> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); ui->qwtPlot->setAxisScale(QwtPlot::xBottom, 0.0, 2.0 * M_PI); ui->qwtPlot->setAxisScale(QwtPlot::yLeft, -1.0, 1.0); //计算曲线数据 QVector<double> xs; QVector<double> ys; for (double x = 0; x < 2.0 * M_PI; x+=(M_PI / 10.0)) { xs.append(x); ys.append(qSin(x)); } //QwtPlot; //构造曲线数据 QwtPointArrayData * const data = new QwtPointArrayData(xs, ys); QwtPlotCurve *curve = new QwtPlotCurve("Sine"); curve->setStyle(QwtPlotCurve::Lines);//直线形式 curve->setCurveAttribute(QwtPlotCurve::Fitted, true);//是曲线更光滑 curve->setPen(QPen(Qt::blue));//设置画笔 curve->setData(data);//设置数据 curve->attach(ui->qwtPlot); /* QwtPlotCurve curve("Sine"); curve.setData(data);//设置数据 curve.setStyle(QwtPlotCurve::Lines);//直线形式 curve.setCurveAttribute(QwtPlotCurve::Fitted, true);//是曲线更光滑 curve.setPen(QPen(Qt::blue));//设置画笔 curve.attach(&plot);//把曲线附加到plot上 */ }
相关文章推荐
- Zend_Json 简单介绍 --(手册)
- 给phpcms v9增加远程模型及远程栏目
- phpcms v9 企业黄页系统发布没有表单出现的解决方案
- ThinkPHP 模板 Volist 标签嵌套循环输出多维数组
- PHP站内搜索:多关键字、加亮显示
- PHP--froeach语句
- PHP Curl post上传图片版本不兼容而引起服务器端接收不到图片问题。
- php发送邮件二种方法 php使用smtp发送邮件
- PHP常量
- Leetcode之nextPermutation
- 使用 Zend_Form 生成表单 --(手册)
- 基于Zend framework的投票系统的实现
- 基于zend Framework 的购物车系统的实现
- 干货分享:PHPCMS V9 删除链接URL中的域名
- 如何配置Lync Windows Time Service(NTP)
- php 连接mysql数据库类
- js模仿php中strtotime()与date()函数实现方法
- FileZilla读取目录列表失败的解决办法 ftp
- 判断一个点是否在某个区域内。百度,高德,腾讯都能用。(php版)
- php实现金字塔图案