mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-26 10:31:39 +08:00
b0df7a1fd7
NEW/BREAKING: refactor CMake-Code, so static/dynamic switch is done via <code>BUILD_SHARED_LIBS</code>, which retires <code>JKQtPlotter_BUILD_STATIC_LIBS</code>, <code>JKQtPlotter_BUILD_SHARED_LIBS</code> and removes the capability to build static and shared libraries in one location (fixes issue #104) NEW: prepareed library for CMake's <a href="https://cmake.org/cmake/help/latest/module/FetchContent.html">FetchContent</a>-API NEW: the different sub-libraries JKQTPlotter, JKQTFastPlotter (DEPRECATED), JKQTMath, JKQTMathText can be activated/deactivated with CMake options JKQtPlotter_BUILD_LIB_JKQTPLOTTER, JKQtPlotter_BUILD_LIB_JKQTFASTPLOTTER, JKQtPlotter_BUILD_LIB_JKQTMATHTEXT, JKQtPlotter_BUILD_LIB_JKQTMATH |
||
---|---|---|
.. | ||
CMakeLists.txt | ||
README.md | ||
scatter_and_lib.pro | ||
scatter.cpp | ||
scatter.pro |
Example (JKQTPlotter): Very simple scatter-graph
This project (see ./examples/scatter/
) simply creates a JKQTPlotter widget (as a new window) and adds a single scatter graph of type JKQTPXYScatterGraph (a sine-wave with noise).
The source code of the example can be found in jkqtplotter_scatter.cpp
.
First we create a plotter window and get a pointer to the internal datastore (for convenience):
JKQTPlotter plot;
JKQTPDatastore* ds=plot.getDatastore();
Now we add two columns to the JKQTPDatastore and obtain back-inserter iterators for these:
size_t columnX=ds->addColumn("x");
auto colXInserter=ds->backInserter(columnX);
size_t columnY=ds->addColumn("y");
auto colYInserter=ds->backInserter(columnY);
Now we create data for a simple plot (a sine curve with random noise):
std::default_random_engine generator;
std::normal_distribution<double> distribution(0,0.5);
const int Ndata=100;
for (int i=0; i<Ndata; i++) {
// put data
const double x=double(i)/double(Ndata)*8.0*JKQTPSTATISTICS_PI;
*colXInserter=x;
*colYInserter=sin(x)+distribution(generator);
// advance back-inserters
colXInserter++;
colYInserter++;
}
Here we create a graph in the plot, which plots the dataset X/Y:
JKQTPXYScatterGraph* graph1=new JKQTPXYScatterGraph(&plot);
graph1->setXColumn(columnX);
graph1->setYColumn(columnY);
graph1->setTitle(QObject::tr("sine graph"));
Now we add the graph to the plot, so it is actually displayed:
plot.addGraph(graph1);
Finally we autoscale the plot so the graph is contained:
plot.zoomToFit();
The result looks like this: