2019-06-21 04:24:47 +08:00
|
|
|
/** \example stepplots.cpp
|
2019-04-22 19:27:50 +08:00
|
|
|
* JKQTPlotter: Examples: Special/Step Line Plots in Different Styles
|
2019-01-13 01:53:16 +08:00
|
|
|
*
|
2019-04-22 19:27:50 +08:00
|
|
|
* \ref JKQTPlotterSpecialStepLinePlot
|
2019-01-13 01:53:16 +08:00
|
|
|
*/
|
|
|
|
|
2022-08-27 04:32:48 +08:00
|
|
|
#include "jkqtpexampleapplication.h"
|
2018-12-29 00:46:47 +08:00
|
|
|
#include <QApplication>
|
|
|
|
#include "jkqtplotter/jkqtplotter.h"
|
2019-06-20 22:06:31 +08:00
|
|
|
#include "jkqtplotter/graphs/jkqtpscatter.h"
|
|
|
|
#include "jkqtplotter/graphs/jkqtpspecialline.h"
|
2019-05-30 04:40:02 +08:00
|
|
|
#include "jkqtplotter/jkqtptools.h"
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2022-04-16 05:01:09 +08:00
|
|
|
|
2022-08-27 04:32:48 +08:00
|
|
|
JKQTPAppSettingController highDPIController(argc, argv);
|
|
|
|
JKQTPExampleApplication app(argc, argv);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
2022-04-16 05:01:09 +08:00
|
|
|
|
2018-12-29 00:46:47 +08:00
|
|
|
// 1. create a plotter window and get a pointer to the internal datastore (for convenience)
|
2019-01-20 23:15:10 +08:00
|
|
|
JKQTPlotter plot;
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPDatastore* ds=plot.getDatastore();
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// 2. now we create data a vector of x-values for a simple plot and several sets of y-values for
|
|
|
|
// cosine curves stacked above each other
|
2019-04-22 19:27:50 +08:00
|
|
|
QVector<double> X, Y1, Y2, Y3, Y4, Y5;
|
|
|
|
const int Ndata=7; // number of plot points in each curve
|
|
|
|
for (int i=0; i<=Ndata; i++) {
|
2019-11-24 17:42:44 +08:00
|
|
|
const double x=0.0+double(i)*0.6*JKQTPSTATISTICS_PI;
|
2018-12-29 00:46:47 +08:00
|
|
|
X<<x;
|
2019-04-22 19:27:50 +08:00
|
|
|
Y1<<sin(x)+1.0*1.5;
|
|
|
|
Y2<<sin(x)+3.0*1.5;
|
|
|
|
Y3<<sin(x)+5.0*1.5;
|
|
|
|
Y4<<sin(x)+7.0*1.5;
|
|
|
|
Y5<<sin(x)+9.0*1.5;
|
2018-12-29 00:46:47 +08:00
|
|
|
}
|
2019-04-22 19:27:50 +08:00
|
|
|
|
2018-12-29 00:46:47 +08:00
|
|
|
// and copy it to the datastore
|
|
|
|
size_t columnX=ds->addCopiedColumn(X, "x");
|
|
|
|
size_t columnY1=ds->addCopiedColumn(Y1, "y1");
|
|
|
|
size_t columnY2=ds->addCopiedColumn(Y2, "y2");
|
|
|
|
size_t columnY3=ds->addCopiedColumn(Y3, "y3");
|
2019-04-22 19:27:50 +08:00
|
|
|
size_t columnY4=ds->addCopiedColumn(Y4, "y5");
|
|
|
|
size_t columnY5=ds->addCopiedColumn(Y5, "y4");
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// 3 now we make several plots with different step styles, each one also contains a
|
|
|
|
// symbol plot indicating the location of the datapoints themselves
|
2019-04-22 19:27:50 +08:00
|
|
|
JKQTPSpecialLineHorizontalGraph* graph;
|
2018-12-29 00:46:47 +08:00
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
//-- JKQTPStepLeft ----------------------------------------------------------------------------------------
|
2019-04-22 19:27:50 +08:00
|
|
|
graph=new JKQTPSpecialLineHorizontalGraph(&plot);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
2019-04-22 19:27:50 +08:00
|
|
|
// set data for the graph
|
|
|
|
graph->setXColumn(columnX);
|
|
|
|
graph->setYColumn(columnY1);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// set step style
|
2019-04-22 19:27:50 +08:00
|
|
|
graph->setSpecialLineType(JKQTPStepLeft);
|
2019-01-26 03:16:04 +08:00
|
|
|
graph->setLineWidth(1);
|
2019-01-26 20:00:40 +08:00
|
|
|
graph->setFillCurve(true);
|
2019-04-22 19:27:50 +08:00
|
|
|
/*QRadialGradient radialGrad(QPointF(0.5, 0.5), 0.5);
|
|
|
|
radialGrad.setColorAt(0, Qt::red);
|
|
|
|
radialGrad.setColorAt(0.5, Qt::blue);
|
|
|
|
radialGrad.setColorAt(1, Qt::green);
|
|
|
|
radialGrad.setCoordinateMode(QGradient::ObjectBoundingMode);
|
|
|
|
graph->setFillGradient(radialGrad);*/
|
2019-01-26 20:00:40 +08:00
|
|
|
graph->setDrawLine(true);
|
|
|
|
graph->setTitle("JKQTPStepLeft, filled");
|
2019-04-22 19:27:50 +08:00
|
|
|
graph->setBaseline(0.0);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
2019-04-22 19:27:50 +08:00
|
|
|
// enable symbols
|
|
|
|
graph->setDrawSymbols(true);
|
|
|
|
graph->setSymbolType(JKQTPGraphSymbols::JKQTPCircle);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// add the graphs to the plot, so it is actually displayed
|
|
|
|
plot.addGraph(graph);
|
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
//-- JKQTPStepCenter ----------------------------------------------------------------------------------------
|
2019-04-22 19:27:50 +08:00
|
|
|
graph=new JKQTPSpecialLineHorizontalGraph(&plot);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
2019-04-22 19:27:50 +08:00
|
|
|
// set data for the graph
|
|
|
|
graph->setXColumn(columnX);
|
|
|
|
graph->setYColumn(columnY2);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// set step style
|
2019-04-22 19:27:50 +08:00
|
|
|
graph->setSpecialLineType(JKQTPStepCenter);
|
2019-01-26 03:16:04 +08:00
|
|
|
graph->setLineWidth(1);
|
2019-01-26 20:00:40 +08:00
|
|
|
graph->setFillCurve(false);
|
|
|
|
graph->setDrawLine(true);
|
|
|
|
graph->setTitle("JKQTPStepCenter");
|
2018-12-29 00:46:47 +08:00
|
|
|
|
2019-04-22 19:27:50 +08:00
|
|
|
// enable symbols
|
|
|
|
graph->setDrawSymbols(true);
|
|
|
|
graph->setSymbolType(JKQTPGraphSymbols::JKQTPCircle);
|
|
|
|
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// add the graphs to the plot, so it is actually displayed
|
|
|
|
plot.addGraph(graph);
|
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
//-- JKQTPStepRight ----------------------------------------------------------------------------------------
|
2019-04-22 19:27:50 +08:00
|
|
|
graph=new JKQTPSpecialLineHorizontalGraph(&plot);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
2019-04-22 19:27:50 +08:00
|
|
|
// set data for the graph
|
|
|
|
graph->setXColumn(columnX);
|
|
|
|
graph->setYColumn(columnY3);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// set step style
|
2019-04-22 19:27:50 +08:00
|
|
|
graph->setSpecialLineType(JKQTPStepRight);
|
2019-01-26 03:16:04 +08:00
|
|
|
graph->setLineWidth(1);
|
2019-01-26 20:00:40 +08:00
|
|
|
graph->setFillCurve(false);
|
|
|
|
graph->setDrawLine(true);
|
|
|
|
graph->setTitle("JKQTPStepRight");
|
2018-12-29 00:46:47 +08:00
|
|
|
|
2019-04-22 19:27:50 +08:00
|
|
|
// enable symbols
|
|
|
|
graph->setDrawSymbols(true);
|
|
|
|
graph->setSymbolType(JKQTPGraphSymbols::JKQTPCircle);
|
|
|
|
|
|
|
|
// add the graphs to the plot, so it is actually displayed
|
|
|
|
plot.addGraph(graph);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-- JKQTPStepAverage ----------------------------------------------------------------------------------------
|
|
|
|
graph=new JKQTPSpecialLineHorizontalGraph(&plot);
|
|
|
|
|
|
|
|
// set data for the graph
|
|
|
|
graph->setXColumn(columnX);
|
|
|
|
graph->setYColumn(columnY4);
|
|
|
|
|
|
|
|
// set step style
|
|
|
|
graph->setSpecialLineType(JKQTPStepAverage);
|
|
|
|
graph->setLineWidth(1);
|
|
|
|
graph->setFillCurve(false);
|
|
|
|
graph->setDrawLine(true);
|
|
|
|
graph->setTitle("JKQTPStepAverage");
|
|
|
|
|
|
|
|
// enable symbols
|
|
|
|
graph->setDrawSymbols(true);
|
|
|
|
graph->setSymbolType(JKQTPGraphSymbols::JKQTPCircle);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// add the graphs to the plot, so it is actually displayed
|
|
|
|
plot.addGraph(graph);
|
|
|
|
|
|
|
|
|
2019-04-22 19:27:50 +08:00
|
|
|
//-- JKQTPDirectLine ----------------------------------------------------------------------------------------
|
|
|
|
graph=new JKQTPSpecialLineHorizontalGraph(&plot);
|
|
|
|
|
|
|
|
// set data for the graph
|
|
|
|
graph->setXColumn(columnX);
|
|
|
|
graph->setYColumn(columnY5);
|
|
|
|
|
|
|
|
// set step style
|
|
|
|
graph->setSpecialLineType(JKQTPDirectLine);
|
|
|
|
graph->setLineWidth(1);
|
|
|
|
graph->setFillCurve(false);
|
|
|
|
graph->setDrawLine(true);
|
|
|
|
graph->setTitle("JKQTPDirectLine");
|
|
|
|
|
|
|
|
// enable symbols
|
|
|
|
graph->setDrawSymbols(true);
|
|
|
|
graph->setSymbolType(JKQTPGraphSymbols::JKQTPCircle);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add the graphs to the plot, so it is actually displayed
|
|
|
|
plot.addGraph(graph);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
// 4. scale plot manually
|
2019-04-22 19:27:50 +08:00
|
|
|
plot.setXY(-0.5, X.last()+0.5, -0.5, 18);
|
|
|
|
|
|
|
|
// 5. style the plot
|
|
|
|
plot.setGrid(false);
|
|
|
|
plot.getXAxis()->setShowZeroAxis(false);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
2019-04-22 19:27:50 +08:00
|
|
|
// 6. show plotter and make it a decent size
|
2018-12-29 00:46:47 +08:00
|
|
|
plot.show();
|
2022-08-29 04:48:14 +08:00
|
|
|
plot.resize(800/plot.devicePixelRatioF(),600/plot.devicePixelRatioF());
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
return app.exec();
|
|
|
|
}
|