mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-11-15 18:15:52 +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 |
||
---|---|---|
.. | ||
barchart_twocolor.cpp | ||
CMakeLists.txt | ||
README.md |
Example (JKQTPlotter): Barchart With Two-Color Fill-Mode
This project (see barchart_twocolor
shows how to draw barcharts, where the bars are filled differently if their value is above or below the baseline.
The source code of the main application is (see barchart_twocolor.cpp
:
// 1. create a plotter window and get a pointer to the internal datastore (for convenience)
JKQTPlotter plot;
JKQTPDatastore* ds=plot.getDatastore();
// 2. now we create two columns for key and value
size_t columnK=ds->addLinearColumn(10, 0, 2.0*JKQTPSTATISTICS_PI,"k");
size_t columnV=ds->addColumnCalculatedFromColumn(columnK, &cos, "v");
// 3. create graph in the plot, which plots the dataset:
JKQTPBarGraphBase* graph=new JKQTPBarVerticalGraph(&plot);
graph->setKeyColumn(columnK);
graph->setValueColumn(columnV);
// set TwoColor fill Mode
graph->setFillMode(JKQTPBarGraphBase::FillMode::TwoColorFilling);
graph->setFillColor(QColor("green"));
graph->fillStyleBelow().setFillColor(QColor("red"));
plot.addGraph(graph);
// 4 autoscale the plot so the graph is contained
plot.zoomToFit();
// 5. show plotter and make it a decent size
plot.setWindowTitle(title);
plot.show();
plot.resize(400,400);
The result looks like this:
In order to draw horizontal error bars, you have to use JKQTPBarHorizontalGraph
instead of JKQTPBarVerticalGraph
: