This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mainwindow.h" | |
#include "ui_mainwindow.h" | |
#include <QDebug> | |
MainWindow::MainWindow(QWidget *parent) : | |
QMainWindow(parent), | |
ui(new Ui::MainWindow) | |
{ | |
ui->setupUi(this); | |
customPlot = ui->widget; | |
//グラフのタイトル | |
customPlot->plotLayout()->insertRow(0); | |
customPlot->plotLayout()->addElement(0, 0, new QCPPlotTitle(customPlot, "グラフのタイトル")); | |
//グラフのデータを作成 | |
QVector<double> sinX,sinY;//空のベクタ宣言 | |
QVector<double> cosX,cosY;//空のベクタ宣言 | |
for( double d = 0.0 ; d < 1.01 ; d += 0.01 ){ | |
sinX.append( d ); | |
sinY.append( sin(2.0*M_PI*d) ); | |
cosX.append( d ); | |
cosY.append( cos(2.0*M_PI*d) ); | |
} | |
// グラフのデータを挿入 | |
customPlot->addGraph(); | |
customPlot->graph(0)->setData(sinX, sinY); | |
customPlot->graph(0)->setName("sin");//凡例の名前 | |
customPlot->addGraph(); | |
customPlot->graph(1)->setData(cosX, cosY); | |
customPlot->graph(1)->setName("cos"); | |
customPlot->graph(1)->setPen(QPen(Qt::red));//線の色 | |
customPlot->xAxis->setLabel("x");//X軸の目盛のタイトル | |
customPlot->yAxis->setLabel("y"); | |
//目盛関係 | |
customPlot->xAxis->setRange(0, 1.0);//目盛の始点終点 | |
customPlot->yAxis->setRange(-1.0, 1.0); | |
customPlot->xAxis->setAutoTickStep(false); | |
customPlot->yAxis->setAutoTickStep(false); | |
customPlot->xAxis->setTickStep(0.2);// | |
customPlot->yAxis->setTickStep(0.2); | |
// 凡例の表示 | |
customPlot->legend->setVisible(true); | |
// 凡例の表示位置:右下 | |
customPlot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignBottom|Qt::AlignRight); | |
customPlot->replot(); | |
} | |
MainWindow::~MainWindow() | |
{ | |
delete ui; | |
} | |
0 件のコメント:
コメントを投稿