JKQtPlotter/examples/barchart_twocolor
2024-02-04 21:42:53 +01:00
..
barchart_twocolor.cpp RENAMED JKQTPDatastore::addColumnCalculatedFromColumn() to JKQTPDatastore::addCalculatedColumnFromColumn(), which is more in line with the other add...()-function names. Aliases with the old function names remain for compatibility 2024-02-04 21:42:53 +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 JKQTPlotter: NEW: barcharts (derived from JKQTPBarGraphBase) can be configured to use different fill styles above and below the baseline 2022-09-10 14:35:16 +02:00

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:

barchart_twocolor

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

barchart_twocolor_hor