JKQTPlotter trunk/v5.0.0
an extensive Qt5+Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
Loading...
Searching...
No Matches
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:
graph->setKeyColumn(columnK);
graph->setValueColumn(columnV);
// set FunctorFilling fill Mode
// define filling functor
[](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);
void setFillBrushFunctor(const JKQTPBarGraphBase::FillBrushFunctor &f)
functor, used to determine the color in m_fillMode==FunctorFilling
void setFillMode(JKQTPBarGraphBase::FillMode mode)
specifies how the area of the graph is filles
@ FunctorFilling
a functor (use setFillBrushFunctor() to define one) is used to determine the fill color
Definition jkqtpbarchartbase.h:175
This implements a vertical bar graph with bars between and .
Definition jkqtpbarchart.h:51
This class manages data columns (with entries of type double ), used by JKQTPlotter/JKQTBasePlotter t...
Definition jkqtpdatastorage.h:282
size_t addLinearColumn(size_t rows, double start, double end, const QString &name=QString(""))
add a column to the datastore that contains rows rows with monotonely increasing value starting at st...
size_t addColumnCalculatedFromColumn(size_t otherColumn, const std::function< double(double)> &f, const QString &name=QString(""))
Definition jkqtpdatastorage.h:1333
virtual void setValueColumn(int __value)
sets the column used as "value" for the current graph (typically this call setXColumn(),...
virtual void setKeyColumn(int __value)
sets the column used as "key" for the current graph (typically this call setXColumn(),...

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