2019-01-20 23:15:10 +08:00
# Example (JKQTPlotter): Simple impulse plots {#JKQTPlotterImpulsePlots}
This project (see `./examples/simpletest_impulsesplot/` ) simply creates a JKQTPlotter widget (as a new window) and adds a single impulse graph.
The source code of the main application is (see [`jkqtplotter_simpletest_impulsesplot.cpp` ](../simpletest_impulsesplot/jkqtplotter_simpletest_impulsesplot.cpp ).
2018-12-29 00:46:47 +08:00
First data for a curve is calculated and stored in `QVector<double>` :
2019-01-19 16:40:52 +08:00
```.cpp
2018-12-29 00:46:47 +08:00
QVector< double > X, Y;
for (int i=0; i< Ndata ; i + + ) {
const double xx=double(i)/double(Ndata)*6.0*M_PI;
X < < xx ;
Y < < cos ( xx ) * exp ( -xx / 10 . 0 ) ;
}
```
... and finally the data is copied into the datastore
2019-01-19 16:40:52 +08:00
```.cpp
2018-12-29 00:46:47 +08:00
size_t columnX=ds->addCopiedColumn(X, "x");
size_t columnY=ds->addCopiedColumn(Y, "y");
```
Now an impulse graph object is generated and added to the plot:
2019-01-19 16:40:52 +08:00
```.cpp
2019-01-20 17:49:29 +08:00
JKQTPImpulsesVerticalGraph* graph=new JKQTPImpulsesVerticalGraph(&plot);
2019-01-26 20:00:40 +08:00
graph->setXColumn(columnX);
graph->setYColumn(columnY);
2019-01-26 03:16:04 +08:00
graph->setLineWidth(2);
2019-01-26 20:00:40 +08:00
graph->setColor(QColor("red"));
graph->setTitle(QObject::tr("$\\cos(x)\\cdot\\exp(-x/10)$"));
2018-12-29 00:46:47 +08:00
plot.addGraph(graph);
```
The result looks like this:
2019-01-12 20:43:12 +08:00
![jkqtplotter_simpletest_impulsesplot ](../../screenshots/jkqtplotter_simpletest_impulsesplot.png )
2018-12-29 00:46:47 +08:00
2019-01-20 17:49:29 +08:00
There is an alternative class `JKQTPImpulsesHorizontalGraph` which draws horizontal impulse plots:
2019-01-19 16:40:52 +08:00
```.cpp
2019-01-20 17:49:29 +08:00
JKQTPImpulsesHorizontalGraph* graph=new JKQTPImpulsesHorizontalGraph(&plot);
2019-01-26 20:00:40 +08:00
graph->setYColumn(columnX);
graph->setXColumn(columnY);
2019-01-26 03:16:04 +08:00
graph->setLineWidth(2);
2019-01-26 20:00:40 +08:00
graph->setColor(QColor("blue"));
graph->setTitle(QObject::tr("$\\cos(x)\\cdot\\exp(-x/10)$"));
2018-12-29 00:46:47 +08:00
```
This code snippet results in a plot like this:
2019-01-12 20:43:12 +08:00
![jkqtplotter_simpletest_impulsesplot ](../../screenshots/jkqtplotter_simpletest_impulsesplot_horizontal.png )
2018-12-29 00:46:47 +08:00