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 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)
// 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:
graph->setKeyColumn(columnK);
graph->setValueColumn(columnV);
// set TwoColor fill Mode
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);
This is a base-class for all bar graphs with vertical or horizontal orientation (the orientation is i...
Definition jkqtpbarchartbase.h:152
JKQTPGraphFillStyleMixin & fillStyleBelow()
if m_fillMode ==FillAboveAndBelowDifferently then this fill style is used below the baseline and the ...
void setFillMode(JKQTPBarGraphBase::FillMode mode)
specifies how the area of the graph is filles
@ TwoColorFilling
the area above and below baseline with the two different colors/pattern
Definition jkqtpbarchartbase.h:174
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
void setFillColor(const QColor &__value)
set the color of the graph filling
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(),...
plotter widget for scientific plots (uses JKQTBasePlotter to do the actual drawing)
Definition jkqtplotter.h:364
void zoomToFit(bool zoomX=true, bool zoomY=true, bool includeX0=false, bool includeY0=false, double scaleX=1.05, double scaleY=1.05)
this method zooms the graph so that all plotted datapoints are visible.
Definition jkqtplotter.h:1039
void addGraph(JKQTPPlotElement *gr)
Definition jkqtplotter.h:784
JKQTPDatastore * getDatastore()
returns a pointer to the datastore used by this object
Definition jkqtplotter.h:611
#define JKQTPSTATISTICS_PI
Definition jkqtpmathtools.h:52

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