JKQtPlotter/examples/barchart_functorfill
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
..
barchart_functorfill.cpp NEW: barcharts can be colored by a user-specified functor 2022-10-22 16:40:44 +02: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 NEW: you can provide a custom draw functor to barcharts to completely customize their look 2022-10-28 21:48:42 +02:00

Example (JKQTPlotter): Barchart With Functor Fill-Mode

This project (see barchart_functorfill shows how to draw barcharts, where the bars are filled differently, as defined by a custom functor.

The source code of the main application is (see barchart_functorfill.cpp:

        // 1. create a plotter window and get a pointer to the internal datastore (for convenience)
    JKQTPDatastore* ds=plot.getDatastore();

    // 2. now we create two columns for key and value
    size_t columnK=ds->addLinearColumn(11, 0, 10, "k");
    size_t columnV=ds->addColumnCalculatedFromColumn(columnK, [](double x) { return 5.0+x; }, "v");

    // 3. create graph in the plot, which plots the dataset:
    JKQTPBarVerticalGraph* graph=new JKQTPBarVerticalGraph(&plot);
    graph->setKeyColumn(columnK);
    graph->setValueColumn(columnV);
    // set FunctorFilling fill Mode
    graph->setFillMode(JKQTPBarGraphBase::FillMode::FunctorFilling);
    // define filling functor
    graph->setFillBrushFunctor(
      [](double key, double value) {
        return QBrush(QColor::fromHsvF(key/12.0, 1.0, 1.0)); 
      }
    );
    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:

barchart_functorfill

In order to draw horizontal error bars, you have to use JKQTPBarHorizontalGraph instead of JKQTPBarVerticalGraph:

barchart_functorfill_hor