2019-01-13 01:53:16 +08:00
|
|
|
/** \example jkqtplotter_simpletest_stepplots.cpp
|
2019-01-20 23:15:10 +08:00
|
|
|
* JKQTPlotter: Examples: Step Line Plots in Different Styles
|
2019-01-13 01:53:16 +08:00
|
|
|
*
|
2019-01-20 23:15:10 +08:00
|
|
|
* \ref JKQTPlotterStepPlot
|
2019-01-13 01:53:16 +08:00
|
|
|
*/
|
|
|
|
|
2018-12-29 00:46:47 +08:00
|
|
|
#include <QApplication>
|
|
|
|
#include "jkqtplotter/jkqtplotter.h"
|
|
|
|
#include "jkqtplotter/jkqtpgraphs.h"
|
|
|
|
#include "jkqtplottertools/jkqtptools.h"
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
QApplication app(argc, argv);
|
|
|
|
|
|
|
|
// 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
|
|
|
|
QVector<double> X, Y1, Y2, Y3;
|
|
|
|
const int Ndata=10; // number of plot points in each curve
|
|
|
|
for (int i=0; i<Ndata; i++) {
|
|
|
|
const double x=double(i)/double(Ndata)*2.0*M_PI;
|
|
|
|
X<<x;
|
|
|
|
Y1<<cos(x)+1.0*1.5;
|
|
|
|
Y2<<cos(x)+2.0*1.5;
|
|
|
|
Y3<<cos(x)+3.0*1.5;
|
|
|
|
}
|
|
|
|
// 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");
|
|
|
|
|
|
|
|
// 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-01-20 17:49:29 +08:00
|
|
|
JKQTPStepHorizontalGraph* graph;
|
|
|
|
JKQTPXYLineGraph* graphL;
|
2018-12-29 00:46:47 +08:00
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
//-- JKQTPStepLeft ----------------------------------------------------------------------------------------
|
|
|
|
graph=new JKQTPStepHorizontalGraph(&plot);
|
|
|
|
graphL=new JKQTPXYLineGraph(&plot);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// set data for both graphs
|
2019-01-26 20:00:40 +08:00
|
|
|
graph->setXColumn(columnX); graphL->setXColumn(graph->getXColumn());
|
|
|
|
graph->setYColumn(columnY1); graphL->setYColumn(graph->getYColumn());
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// set step style
|
2019-01-26 20:00:40 +08:00
|
|
|
graph->setStepType(JKQTPStepLeft);
|
2019-01-26 03:16:04 +08:00
|
|
|
graph->setLineWidth(1);
|
2019-01-26 20:00:40 +08:00
|
|
|
graph->setFillCurve(true);
|
|
|
|
graph->setDrawLine(true);
|
|
|
|
graph->setTitle("JKQTPStepLeft, filled");
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// set symbol + pen style and color for the added circles, copy color
|
2019-01-26 20:00:40 +08:00
|
|
|
graphL->setSymbol(JKQTPGraphSymbols::JKQTPCircle);
|
|
|
|
graphL->setDrawLine(false);
|
|
|
|
graphL->setSymbolSize(9);
|
|
|
|
graphL->setSymbolWidth(1);
|
|
|
|
graphL->setColor(graph->getColor());
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// add the graphs to the plot, so it is actually displayed
|
|
|
|
plot.addGraph(graph);
|
|
|
|
plot.addGraph(graphL);
|
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
//-- JKQTPStepCenter ----------------------------------------------------------------------------------------
|
|
|
|
graph=new JKQTPStepHorizontalGraph(&plot);
|
|
|
|
graphL=new JKQTPXYLineGraph(&plot);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// set data for both graphs
|
2019-01-26 20:00:40 +08:00
|
|
|
graph->setXColumn(columnX); graphL->setXColumn(graph->getXColumn());
|
|
|
|
graph->setYColumn(columnY2); graphL->setYColumn(graph->getYColumn());
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// set step style
|
2019-01-26 20:00:40 +08:00
|
|
|
graph->setStepType(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
|
|
|
|
|
|
|
// set symbol + pen style and color for the added circles, copy color
|
2019-01-26 20:00:40 +08:00
|
|
|
graphL->setSymbol(JKQTPGraphSymbols::JKQTPCircle);
|
|
|
|
graphL->setDrawLine(false);
|
|
|
|
graphL->setSymbolSize(9);
|
|
|
|
graphL->setSymbolWidth(1);
|
|
|
|
graphL->setColor(graph->getColor());
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// add the graphs to the plot, so it is actually displayed
|
|
|
|
plot.addGraph(graph);
|
|
|
|
plot.addGraph(graphL);
|
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
//-- JKQTPStepRight ----------------------------------------------------------------------------------------
|
|
|
|
graph=new JKQTPStepHorizontalGraph(&plot);
|
|
|
|
graphL=new JKQTPXYLineGraph(&plot);
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// set data for both graphs
|
2019-01-26 20:00:40 +08:00
|
|
|
graph->setXColumn(columnX); graphL->setXColumn(graph->getXColumn());
|
|
|
|
graph->setYColumn(columnY3); graphL->setYColumn(graph->getYColumn());
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// set step style
|
2019-01-26 20:00:40 +08:00
|
|
|
graph->setStepType(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
|
|
|
|
|
|
|
// set symbol + pen style and color for the added circles, copy color
|
2019-01-26 20:00:40 +08:00
|
|
|
graphL->setSymbol(JKQTPGraphSymbols::JKQTPCircle);
|
|
|
|
graphL->setDrawLine(false);
|
|
|
|
graphL->setSymbolSize(9);
|
|
|
|
graphL->setSymbolWidth(1);
|
|
|
|
graphL->setColor(graph->getColor());
|
2018-12-29 00:46:47 +08:00
|
|
|
|
|
|
|
// add the graphs to the plot, so it is actually displayed
|
|
|
|
plot.addGraph(graph);
|
|
|
|
plot.addGraph(graphL);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 4. scale plot manually
|
|
|
|
plot.setXY(-0.5, X.last()+0.5, -0.5, 7);
|
|
|
|
|
|
|
|
// 5. show plotter and make it a decent size
|
|
|
|
plot.show();
|
|
|
|
plot.resize(800,600);
|
|
|
|
|
|
|
|
return app.exec();
|
|
|
|
}
|