First, configure the Qcustomplot
Official: Http://www.qcustomplot.com/index.php/download
650) this.width=650; "Src=" http://img.blog.csdn.net/20151010144651708?watermark/2/text/ Ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/southeast "style= "Border:none;"/>
Unzip the file after downloading (do not have Chinese path)
Open QT, create a new form project
Copy the header file Qcustomplot.h and source files from the extracted folder to the project folder Qcustomplot.cpp
In Qt, add the existing files, enter the header file qcustomplot.h and the promotion class name into "Qcustomplot", click Add Source file Qcustomplot.cpp add to the project
650) this.width=650; "Src=" http://img.blog.csdn.net/20151010150356138?watermark/2/text/ Ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/southeast "style= "Border:none;"/>
Add a printsupport to the project Pro
650) this.width=650; "Src=" http://img.blog.csdn.net/20151010150556149?watermark/2/text/ Ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/southeast "style= "Border:none;"/>
Open the interface file, enter the UI, add a widget area to the main window, right-click on the widget area you added, and select the "Promote to" button
650) this.width=650; "Src=" http://img.blog.csdn.net/20151010150654879?watermark/2/text/ Ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/southeast "style= "Border:none;"/>
Promote class name enter "Qcustomplot", click Add
650) this.width=650; "Src=" http://img.blog.csdn.net/20151010150825906?watermark/2/text/ Ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/southeast "style= "Border:none;"/>
Click Promote to complete the configuration
Second, the use of Qcustomplot
Principle:
Qcustomplot can understood as is a drawing board class, which inherits from Widgets, the Widget class in the interface is promoted to Qcustomplot to be able to draw
each curve in the Qcustomplot is a Graph objects, which are related to the display of data, we manipulate graph or invoke the method provided by the graph object
There are four axes in a qcustomplot, of which Xaxis and the YAxis is the x and Y axes we see, there are two axes xAxis1 and yAxis1 for the x and Y coordinates above and to the right, which are hidden by default and can be programmed to display
then the above operation, First, rename the object above the container interface promoted to the Qcustomplot class to Qcustomplot
Add the following code to the main class widget constructor to draw a standard standard y=x^3 curve
[CPP] view plain copy
Widget::widget (Qwidget *parent):
Qwidget (parent),
UI (new ui::widget)
{
UI->SETUPUI (this);
//Define two variable arrays to hold the coordinate data of the drawing
-
qvector<double > x (101), Y ( 101); / /storing data for x and Y coordinates, 101 for data length
-
//add data, we show here y=x^3, for positive and negative symmetry, we x from 10 to +10 &NBSP;&NBSP;
for (int i=0;i<101;i++)
{
X[i] = I/5-10;
Y[i] = x[i] * x[i] * x[i];
}
//Add a curve to the drawing area qcustomplot (lifted from the widget)
Ui->qcustomplot->addgraph ();
//Add Data
Ui->qcustomplot->graph (0)->setdata (x, y);
//Set axis label name
Ui->qcustomplot->xaxis->setlabel ("x");
Ui->qcustomplot->yaxis->setlabel ("y");
//Set the axis display range, otherwise we can only see the default range
Ui->qcustomplot->xaxis->setrange ( -11,11);
Ui->qcustomplot->yaxis->setrange ( -1100,1100);
//Redraw, not available here, official example, auto redraw after executing SetData function
//I think it should be used for dynamic display or for dynamic display after changing the axis range, we'll explore
//ui->qcustomplot->replot ();
}
Compile
650) this.width=650; "Src=" http://img.blog.csdn.net/20151010151429374?watermark/2/text/ Ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/southeast "style= "Border:none;"/>
Finally, I encountered an error here during the operation
650) this.width=650; "Src=" http://img.blog.csdn.net/20151010151513497?watermark/2/text/ Ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/southeast "style= "Border:none;"/>
Will
[CPP] view plain copy
#include ". /.. /qcustomplot.h "
Change into
[CPP] view plain copy
#include <qcustomplot.h>
You can do it.
qt Drawing plugin qcustomplot download installation configuration use