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 Error Bars

This project (see barchart_errorbars shows how to draw barcharts with different styles of error indicators.

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

// 1. create a plotter window and get a pointer to the internal datastore (for convenience)
JKQTPDatastore* ds=plot.getDatastore();
// 2. now we create three columns for key and value
size_t columnK=ds->addLinearColumn(6, 0.4*JKQTPSTATISTICS_PI, 2.2*JKQTPSTATISTICS_PI,"k");
size_t columnV=ds->addColumnCalculatedFromColumn(columnK, &cos, "v");
size_t columnE=ds->addColumnCalculatedFromColumn(columnK, [](double x) { return 0.05+0.06*(1.0+sin(x)); }, "error");
// 3. create a graph in the plot, which plots the dataset with symmetric:
graph1->setKeyColumn(columnK);
graph1->setValueColumn(columnV);
graph1->setBarErrorColumn(columnE);
// set error indicator style
graph1->setTitle(QObject::tr("JKQTPErrorBars"));
plot.addGraph(graph1);
// 4. create a second graph in the plot, which plots the second dataset with outer error bars only:
graph2->setKeyColumn(columnK);
graph2->setValueColumn(columnV);
graph2->setBarErrorColumn(columnE);
// set error indicator style
graph2->setTitle(QObject::tr("JKQTPErrorHalfBarsOutwards"));
plot.addGraph(graph2);
// 5. now we set the graphs, so they are plotted side-by-side
// This function searches all JKQTPBarHorizontalGraph in the current
// plot and sets their shift/scale so they form a nice plot with
// side-by-side groups
graph1->autoscaleBarWidthAndShift(0.9, 0.9);
// 6 autoscale the plot so the graph is contained
plot.zoomToFit();
// 7. show plotter and make it a decent size
plot.getPlotter()->setKeyPosition(JKQTPKeyInsideTopLeft);
plot.setWindowTitle(title);
plot.show();
plot.resize(400,400);
virtual void autoscaleBarWidthAndShift(double maxWidth=0.75, double shrinkFactor=0.9)
finds all bar charts of the same orientation and determines width and shift, so they stand side by si...
This implements a vertical bar graph with bars between and and error indicator.
Definition jkqtpbarchart.h:90
void setBarErrorStyle(JKQTPErrorPlotstyle __value)
sets the error style of the bar
void setBarErrorColumn(int column)
sets the column that contains the bar height errors
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 setTitle(const QString &__value)
sets the title of the plot (for display in key!).
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(),...
@ JKQTPErrorHalfBarsOutwards
half error bars for each data point, pointing outwards
Definition jkqtptools.h:714
@ JKQTPErrorBars
error bars for each data point
Definition jkqtptools.h:711
@ JKQTPKeyInsideTopLeft
the key is positioned inside on the top-left
Definition jkqtptools.h:583
#define JKQTPSTATISTICS_PI
Definition jkqtpmathtools.h:52

The result looks like this:

barchart_errorbars

In order to draw horizontal error bars, you have to use JKQTPBarHorizontalErrorGraph instead of JKQTPBarVerticalErrorGraph:

barchart_errorbars_hor