JKQtPlotter/examples/stepplots
jkriege2 b0df7a1fd7 NEW/BREAKING: provide general targets JKQTPlotter5/6::JKQTPlotter5/6, JKQTPlotter5/6::JKQTMathText5/6, ... which are independent of the type of build (shared/static)
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
2024-01-16 13:07:08 +01:00
..
CMakeLists.txt NEW/BREAKING: provide general targets JKQTPlotter5/6::JKQTPlotter5/6, JKQTPlotter5/6::JKQTMathText5/6, ... which are independent of the type of build (shared/static) 2024-01-16 13:07:08 +01:00
README.md using CMake now to build examples 2019-06-20 22:24:47 +02:00
stepplots_and_lib.pro using CMake now to build examples 2019-06-20 22:24:47 +02:00
stepplots_vertical.cpp added more auto-generated screenshots 2022-08-26 22:32:48 +02:00
stepplots.cpp updated many documentation images to auto-generated ones 2022-08-28 22:48:14 +02:00
stepplots.pro using CMake now to build examples 2019-06-20 22:24:47 +02:00

Example (JKQTPlotter): Step Line Plots in Different Styles

This project (see ./examples/stepplots/) simply creates a JKQTPlotter widget (as a new window) and adds a single line-graph (a sine-wave). Data is initialized from two QVector objects.

The source code of the main application can be found in stepplots.cpp. For the most part, several datasets of cosine-curves are generated. Then graphs of type JKQTPSpecialLineHorizontalGraph are added to the plot:

	// 3 now we make several plots with different step styles, each one also contains a
    //     symbol plot indicating the location of the datapoints themselves
    JKQTPSpecialLineHorizontalGraph* graph;

    //-- JKQTPStepLeft ----------------------------------------------------------------------------------------
    graph=new JKQTPSpecialLineHorizontalGraph(&plot);

    // set data for the graph
    graph->setXColumn(columnX);
    graph->setYColumn(columnY1);

    // set step style
    graph->setSpecialLineType(JKQTPStepLeft);
    graph->setLineWidth(1);
    graph->setFillCurve(true);
    graph->setDrawLine(true);
    graph->setTitle("JKQTPStepLeft, filled");

    // enable symbols
    graph->setDrawSymbols(true);
    graph->setSymbolType(JKQTPGraphSymbols::JKQTPCircle);
    

Note that you can configure the step type (left/center/right by graph->setSpecialLineType(JKQTPStepLeft). With graph->setFillCurve(true) you can draw the curve filled until the y=0-axis and with graph->setDrawLine(true) you can switch the line along the values on and off (e.g. to only have the filled area, but no line). With graph->setDrawSymbols(true) you can switch on drawing of symbols at the location of the data points.

... and all graphs are added to the plot:

    // add the graphs to the plot, so it is actually displayed
    plot.addGraph(graph);

In addition to the symbol type and line style, you can also alter the size of the symbols (graph->setSymbolSize(14)), the line-width used to draw them (graph->setSymbolLineWidth(1.5)) and the line width of the graph line (graph->setLineWidth(1)). If you want to switch off the line altogether, use graph->setDrawLine(false.

The result looks like this:

stepplots

If you use instead of the horizontal variant and exchange x- for y-data, you will get a plot like this:

stepplots_vertical.png

Also note how the red graph is filled towards the y-axis, not the x-axis.