diff --git a/README.md b/README.md index 8860a12840..6dedc142b6 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ All test-projects are Qt-projects that use qmake to build. You can load them int | [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_logaxes_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_logaxes) | [logarithmic axes](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_logaxes) | `JKQTPxyLineGraph` and `JKQTPgeoText`
C++ vector of data
logarithmic axes
plot line styles
internal LaTeX parser
add commenting text to a graph | | [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_dateaxes_small.png)
![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_dateaxes_dates_small.png)
![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_dateaxes_timeaxis_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_dateaxes) | [date/time axes](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_dateaxes) | `JKQTPxyLineGraph` and `JKQTPfilledVerticalRangeGraph`
C++ vector of data
date/time axes
plot min/max range graph
internal LaTeX parser
data from CSV files | | [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_symbols_and_errors_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_symbols_and_errors) | [Simple Line/Symbol Graph With Errorbars](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_symbols_and_errors) | `JKQTPxyLineErrorGraph`
C-style arrays of data | +| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_errorbarstyles_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_errorbarstyles) | [Different Types of Errorindicators](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_errorbarstyles) | `JKQTPxyLineErrorGraph`
different styles of error indicators for x- and y-errors
C++-style QVector for data
styling error indicators
moving key and formatting plotter grid | | [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_barchart_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_barchart) | [Simple Bar Charts](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_barchart) | `JKQTPbarVerticalGraph`
C-style arrays of data | | [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/JKQTPbarVerticalGraphStacked_small.png)
![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/JKQTPbarHorizontalGraphStacked_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_stackedbars) | [Stacked Bar Charts](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_stackedbars) | `JKQTPbarVerticalStackableGraph`, `JKQTPbarHorizontalStackableGraph`
C++-style vectors of data | diff --git a/lib/jkqtplotter/jkqtpbaseplotter.cpp b/lib/jkqtplotter/jkqtpbaseplotter.cpp index 55507247f6..e9ec9e6f75 100644 --- a/lib/jkqtplotter/jkqtpbaseplotter.cpp +++ b/lib/jkqtplotter/jkqtpbaseplotter.cpp @@ -3158,13 +3158,13 @@ void JKQtBasePlotter::resetMasterSynchronization() { size_t JKQtBasePlotter::addGraph(size_t xColumn, size_t yColumn, QString title, JKQTPgraphPlotstyle graphStyle) { if (graphStyle==JKQTPimpulsesHorizontal) { - JKQTPimpulsesHorizontalGraph* gr=new JKQTPimpulsesHorizontalGraph(this); + JKQTPimpulsesVerticalGraph* gr=new JKQTPimpulsesVerticalGraph(this); gr->set_title(title); gr->set_xColumn(xColumn); gr->set_yColumn(yColumn); return addGraph(gr); } else if (graphStyle==JKQTPimpulsesVertical) { - JKQTPimpulsesVerticalGraph* gr=new JKQTPimpulsesVerticalGraph(this); + JKQTPimpulsesHorizontalGraph* gr=new JKQTPimpulsesHorizontalGraph(this); gr->set_title(title); gr->set_xColumn(xColumn); gr->set_yColumn(yColumn); @@ -3207,7 +3207,7 @@ size_t JKQtBasePlotter::addGraph(size_t xColumn, size_t yColumn, QString title, size_t JKQtBasePlotter::addGraph(size_t xColumn, size_t yColumn, QString title, JKQTPgraphPlotstyle graphStyle, QColor color, JKQTPgraphSymbols symbol, Qt::PenStyle penstyle, double width) { if (graphStyle==JKQTPimpulsesHorizontal) { - JKQTPimpulsesHorizontalGraph* gr=new JKQTPimpulsesHorizontalGraph(this); + JKQTPimpulsesVerticalGraph* gr=new JKQTPimpulsesVerticalGraph(this); gr->set_title(title); gr->set_xColumn(xColumn); gr->set_yColumn(yColumn); @@ -3215,7 +3215,7 @@ size_t JKQtBasePlotter::addGraph(size_t xColumn, size_t yColumn, QString title, gr->set_lineWidth(width); return addGraph(gr); } else if (graphStyle==JKQTPimpulsesVertical) { - JKQTPimpulsesVerticalGraph* gr=new JKQTPimpulsesVerticalGraph(this); + JKQTPimpulsesHorizontalGraph* gr=new JKQTPimpulsesHorizontalGraph(this); gr->set_title(title); gr->set_xColumn(xColumn); gr->set_yColumn(yColumn); diff --git a/lib/jkqtplotter/jkqtpelements.cpp b/lib/jkqtplotter/jkqtpelements.cpp index ad57987b0c..fc773477b8 100644 --- a/lib/jkqtplotter/jkqtpelements.cpp +++ b/lib/jkqtplotter/jkqtpelements.cpp @@ -526,7 +526,7 @@ void JKQTPxyLineErrorGraph::drawErrorsBefore(JKQTPEnhancedPainter &painter) -JKQTPimpulsesHorizontalGraph::JKQTPimpulsesHorizontalGraph(JKQtBasePlotter* parent): +JKQTPimpulsesVerticalGraph::JKQTPimpulsesVerticalGraph(JKQtBasePlotter* parent): JKQTPxyGraph(parent) { baseline=0; @@ -540,7 +540,7 @@ JKQTPimpulsesHorizontalGraph::JKQTPimpulsesHorizontalGraph(JKQtBasePlotter* pare } } -JKQTPimpulsesHorizontalGraph::JKQTPimpulsesHorizontalGraph(JKQtPlotter* parent): +JKQTPimpulsesVerticalGraph::JKQTPimpulsesVerticalGraph(JKQtPlotter* parent): JKQTPxyGraph(parent) { baseline=0; @@ -553,9 +553,9 @@ JKQTPimpulsesHorizontalGraph::JKQTPimpulsesHorizontalGraph(JKQtPlotter* parent): color=parent->getPlotStyle(parentPlotStyle).color(); } } -void JKQTPimpulsesHorizontalGraph::draw(JKQTPEnhancedPainter& painter) { +void JKQTPimpulsesVerticalGraph::draw(JKQTPEnhancedPainter& painter) { #ifdef JKQTBP_AUTOTIMER - JKQTPAutoOutputTimer jkaaot("JKQTPimpulsesHorizontalGraph::draw"); + JKQTPAutoOutputTimer jkaaot("JKQTPimpulsesVerticalGraph::draw"); #endif if (parent==nullptr) return; JKQTPdatastore* datastore=parent->getDatastore(); @@ -627,7 +627,7 @@ void JKQTPimpulsesHorizontalGraph::draw(JKQTPEnhancedPainter& painter) { drawErrorsAfter(painter); } -void JKQTPimpulsesHorizontalGraph::drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) { +void JKQTPimpulsesVerticalGraph::drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) { painter.save(); @@ -642,7 +642,7 @@ void JKQTPimpulsesHorizontalGraph::drawKeyMarker(JKQTPEnhancedPainter& painter, painter.restore(); } -QColor JKQTPimpulsesHorizontalGraph::getKeyLabelColor() { +QColor JKQTPimpulsesVerticalGraph::getKeyLabelColor() { return color; } @@ -656,20 +656,20 @@ QColor JKQTPimpulsesHorizontalGraph::getKeyLabelColor() { -JKQTPimpulsesVerticalGraph::JKQTPimpulsesVerticalGraph(JKQtBasePlotter* parent): - JKQTPimpulsesHorizontalGraph(parent) +JKQTPimpulsesHorizontalGraph::JKQTPimpulsesHorizontalGraph(JKQtBasePlotter* parent): + JKQTPimpulsesVerticalGraph(parent) { } -JKQTPimpulsesVerticalGraph::JKQTPimpulsesVerticalGraph(JKQtPlotter *parent): - JKQTPimpulsesHorizontalGraph(parent) +JKQTPimpulsesHorizontalGraph::JKQTPimpulsesHorizontalGraph(JKQtPlotter *parent): + JKQTPimpulsesVerticalGraph(parent) { } -void JKQTPimpulsesVerticalGraph::draw(JKQTPEnhancedPainter& painter) { +void JKQTPimpulsesHorizontalGraph::draw(JKQTPEnhancedPainter& painter) { #ifdef JKQTBP_AUTOTIMER - JKQTPAutoOutputTimer jkaaot("JKQTPimpulsesVerticalGraph::draw"); + JKQTPAutoOutputTimer jkaaot("JKQTPimpulsesHorizontalGraph::draw"); #endif if (parent==nullptr) return; JKQTPdatastore* datastore=parent->getDatastore(); @@ -1805,7 +1805,7 @@ QBrush JKQTPxyLineGraph::getBrush(JKQTPEnhancedPainter& /*painter*/) const { } -QPen JKQTPimpulsesHorizontalGraph::getPen(JKQTPEnhancedPainter& painter) const { +QPen JKQTPimpulsesVerticalGraph::getPen(JKQTPEnhancedPainter& painter) const { QPen p; p.setColor(color); p.setWidthF(qMax(JKQTPLOTTER_ABS_MIN_LINEWIDTH,parent->pt2px(painter, parent->get_lineWidthMultiplier()*lineWidth))); @@ -1870,7 +1870,7 @@ QPen JKQTPhorizontalRange::getLinePen(JKQTPEnhancedPainter& painter) const { bool JKQTPimpulsesHorizontalErrorGraph::usesColumn(int c) { - return JKQTPimpulsesHorizontalGraph::usesColumn(c)|| JKQTPxGraphErrors::errorUsesColumn(c); + return JKQTPimpulsesVerticalGraph::usesColumn(c)|| JKQTPxGraphErrors::errorUsesColumn(c); } void JKQTPimpulsesHorizontalErrorGraph::drawErrorsAfter(JKQTPEnhancedPainter &painter) @@ -1880,20 +1880,20 @@ void JKQTPimpulsesHorizontalErrorGraph::drawErrorsAfter(JKQTPEnhancedPainter &pa } JKQTPimpulsesVerticalErrorGraph::JKQTPimpulsesVerticalErrorGraph(JKQtBasePlotter *parent): - JKQTPimpulsesVerticalGraph(parent), JKQTPyGraphErrors() + JKQTPimpulsesHorizontalGraph(parent), JKQTPyGraphErrors() { setErrorColorFromGraphColor(color); } JKQTPimpulsesVerticalErrorGraph::JKQTPimpulsesVerticalErrorGraph(JKQtPlotter *parent): - JKQTPimpulsesVerticalGraph(parent), JKQTPyGraphErrors() + JKQTPimpulsesHorizontalGraph(parent), JKQTPyGraphErrors() { setErrorColorFromGraphColor(color); } bool JKQTPimpulsesVerticalErrorGraph::usesColumn(int c) { - return JKQTPimpulsesVerticalGraph::usesColumn(c)|| JKQTPyGraphErrors::errorUsesColumn(c); + return JKQTPimpulsesHorizontalGraph::usesColumn(c)|| JKQTPyGraphErrors::errorUsesColumn(c); } void JKQTPimpulsesVerticalErrorGraph::drawErrorsAfter(JKQTPEnhancedPainter &painter) diff --git a/lib/jkqtplotter/jkqtpelements.h b/lib/jkqtplotter/jkqtpelements.h index 466ea3a27f..d077d8c011 100644 --- a/lib/jkqtplotter/jkqtpelements.h +++ b/lib/jkqtplotter/jkqtpelements.h @@ -360,13 +360,13 @@ class LIB_EXPORT JKQTPxyParametrizedErrorScatterGraph: public JKQTPxyParametrize \image html plot_impulsesxplots.png */ -class LIB_EXPORT JKQTPimpulsesHorizontalGraph: public JKQTPxyGraph { +class LIB_EXPORT JKQTPimpulsesVerticalGraph: public JKQTPxyGraph { Q_OBJECT public: /** \brief class constructor */ - JKQTPimpulsesHorizontalGraph(JKQtBasePlotter* parent=nullptr); + JKQTPimpulsesVerticalGraph(JKQtBasePlotter* parent=nullptr); /** \brief class constructor */ - JKQTPimpulsesHorizontalGraph(JKQtPlotter* parent); + JKQTPimpulsesVerticalGraph(JKQtPlotter* parent); /** \brief plots the graph to the plotter object specified as parent */ virtual void draw(JKQTPEnhancedPainter& painter); @@ -401,17 +401,17 @@ class LIB_EXPORT JKQTPimpulsesHorizontalGraph: public JKQTPxyGraph { \image html plot_impulsesxerrorsplots.png */ -class LIB_EXPORT JKQTPimpulsesHorizontalErrorGraph: public JKQTPimpulsesHorizontalGraph, public JKQTPxGraphErrors { +class LIB_EXPORT JKQTPimpulsesHorizontalErrorGraph: public JKQTPimpulsesVerticalGraph, public JKQTPxGraphErrors { Q_OBJECT public: /** \brief class constructor */ inline JKQTPimpulsesHorizontalErrorGraph(JKQtBasePlotter* parent=nullptr): - JKQTPimpulsesHorizontalGraph(parent), JKQTPxGraphErrors() + JKQTPimpulsesVerticalGraph(parent), JKQTPxGraphErrors() { setErrorColorFromGraphColor(color); } inline JKQTPimpulsesHorizontalErrorGraph(JKQtPlotter* parent): - JKQTPimpulsesHorizontalGraph(parent), JKQTPxGraphErrors() + JKQTPimpulsesVerticalGraph(parent), JKQTPxGraphErrors() { setErrorColorFromGraphColor(color); } @@ -432,13 +432,13 @@ class LIB_EXPORT JKQTPimpulsesHorizontalErrorGraph: public JKQTPimpulsesHorizont \image html plot_impulsesyplots.png */ -class LIB_EXPORT JKQTPimpulsesVerticalGraph: public JKQTPimpulsesHorizontalGraph { +class LIB_EXPORT JKQTPimpulsesHorizontalGraph: public JKQTPimpulsesVerticalGraph { Q_OBJECT public: /** \brief class constructor */ - JKQTPimpulsesVerticalGraph(JKQtBasePlotter* parent=nullptr); + JKQTPimpulsesHorizontalGraph(JKQtBasePlotter* parent=nullptr); /** \brief class constructor */ - JKQTPimpulsesVerticalGraph(JKQtPlotter* parent); + JKQTPimpulsesHorizontalGraph(JKQtPlotter* parent); /** \brief plots the graph to the plotter object specified as parent */ virtual void draw(JKQTPEnhancedPainter& painter); @@ -451,7 +451,7 @@ class LIB_EXPORT JKQTPimpulsesVerticalGraph: public JKQTPimpulsesHorizontalGraph \image html plot_impulsesyerrorsplots.png */ -class LIB_EXPORT JKQTPimpulsesVerticalErrorGraph: public JKQTPimpulsesVerticalGraph, public JKQTPyGraphErrors { +class LIB_EXPORT JKQTPimpulsesVerticalErrorGraph: public JKQTPimpulsesHorizontalGraph, public JKQTPyGraphErrors { Q_OBJECT public: /** \brief class constructor */ diff --git a/screenshots/jkqtplotter_simpletest_errorbarstyles.png b/screenshots/jkqtplotter_simpletest_errorbarstyles.png new file mode 100644 index 0000000000..f789454e1a Binary files /dev/null and b/screenshots/jkqtplotter_simpletest_errorbarstyles.png differ diff --git a/screenshots/jkqtplotter_simpletest_errorbarstyles_barcharts.png b/screenshots/jkqtplotter_simpletest_errorbarstyles_barcharts.png new file mode 100644 index 0000000000..21bbe73ee6 Binary files /dev/null and b/screenshots/jkqtplotter_simpletest_errorbarstyles_barcharts.png differ diff --git a/screenshots/jkqtplotter_simpletest_errorbarstyles_filledcurves.png b/screenshots/jkqtplotter_simpletest_errorbarstyles_filledcurves.png new file mode 100644 index 0000000000..cc08efee61 Binary files /dev/null and b/screenshots/jkqtplotter_simpletest_errorbarstyles_filledcurves.png differ diff --git a/screenshots/jkqtplotter_simpletest_errorbarstyles_impulses.png b/screenshots/jkqtplotter_simpletest_errorbarstyles_impulses.png new file mode 100644 index 0000000000..96bb673474 Binary files /dev/null and b/screenshots/jkqtplotter_simpletest_errorbarstyles_impulses.png differ diff --git a/screenshots/jkqtplotter_simpletest_errorbarstyles_small.png b/screenshots/jkqtplotter_simpletest_errorbarstyles_small.png new file mode 100644 index 0000000000..33cf93515c Binary files /dev/null and b/screenshots/jkqtplotter_simpletest_errorbarstyles_small.png differ diff --git a/test/jkqtplotter_simpletest_errorbarstyles/README.md b/test/jkqtplotter_simpletest_errorbarstyles/README.md new file mode 100644 index 0000000000..af5451f872 --- /dev/null +++ b/test/jkqtplotter_simpletest_errorbarstyles/README.md @@ -0,0 +1,120 @@ +[Back to JKQTPlotter main page](https://github.com/jkriege2/JKQtPlotter/) + +# JKQtPlotter + +## Different Types of Errorindicators +This project (see `./test/jkqtplotter_simpletest_errorbarstyles/`) simply creates a JKQtPlotter widget (as a new window) and adds several curves show-casing different styles of error indicators. Data is initialized from two QVector objects. + +The source code of the main application can be found in [`jkqtplotter_simpletest_errorbarstyles.cpp`](https://github.com/jkriege2/JKQtPlotter/blob/master/test/jkqtplotter_simpletest_errorbarstyles/jkqtplotter_simpletest_errorbarstyles.cpp). + +First some data is added to the internal datastore (mostly, like explained in several other examples, like e.g. [Line Graph with Different Symbols and Line Styles](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_symbols_and_styles)). The (in a loop) several graphs are added, each with a distinct style for its error indicators: + +```c++ + // 3. now we make several plots with different error styles + // for that we iterate over every style from the vector errorStyles + // the array showXandYError indicates whether we want x- and y-error + // for a style for all stywhere this is false, only y-error-indicators + // are shown + QVector errorStyles {JKQTPnoError, JKQTPerrorBars, JKQTPerrorSimpleBars, JKQTPerrorLines, JKQTPerrorPolygons, JKQTPerrorBoxes, JKQTPerrorEllipses, JKQTPerrorBarsPolygons, JKQTPerrorBarsLines, JKQTPerrorSimpleBarsLines, JKQTPerrorSimpleBarsPolygons }; + QVector showXandYError { false , true , true , false , false , true , true , false , false , false , false }; + + for (int errorID=0; errorID Y; + for (auto& xx: X) { + Y<(errorID)*2.5; + } + + // create a graph object + JKQTPxyLineErrorGraph* graph=new JKQTPxyLineErrorGraph(&plot); + + // copy data into datastore and immediately set the yColumn + graph->set_xColumn(columnX); + graph->set_yColumn(ds->addCopiedColumn(Y, "y"+QString::number(errorID))); + graph->set_xErrorColumn(columnXError); + graph->set_yErrorColumn(columnYError); + + // set error style, for the y-axis + graph->set_yErrorStyle(errorStyles[errorID]); + // no error indicators for the x-values + graph->set_xErrorStyle(JKQTPnoError); + // ... unless: for some error styles we want error in both directions + if (showXandYError[errorID]) { + graph->set_xErrorStyle(errorStyles[errorID]); + graph->set_drawLine(false); + } + // make error indicator 30% transparent + QColor c=graph->get_errorFillColor(); + c.setAlphaF(0.3); + graph->set_errorFillColor(c); + // set error indicator line width + graph->set_errorWidth(1); + // set length of small bars at the end of error bars + graph->set_errorbarSize(15); + + + // set symbol (cross/X) + pen style (and color)dashed) + graph->set_symbol(JKQTPcross); + graph->set_style(Qt::DashLine); + // set symbol size + graph->set_symbolSize(5); + // set width of symbol lines + graph->set_symbolWidth(1); + // set width of graph line + graph->set_lineWidth(1); + + // graph title is made from symbol+errorStylestyle, we use the LaTeX instruction \verb around the + // result of JKQTPerrorPlotstyle2String(), because it contains underscores that would otherwise + // lead to lower-case letter, which we don't want + graph->set_title("\\verb{"+JKQTPerrorPlotstyle2String(errorStyles[errorID])+"}"); + + // add the graph to the plot, so it is actually displayed + plot.addGraph(graph); + } +``` + +The error styles are set in these lines: +```c++ + // set error style, for the y-axis + graph->set_yErrorStyle(errorStyles[errorID]); + // no error indicators for the x-values + graph->set_xErrorStyle(errorStyles[errorID]); +``` + +There are several variables that can be used to further style the error indicator, like: +```c++ + // make error indicator 30% transparent + QColor c=graph->get_errorFillColor(); + c.setAlphaF(0.3); + graph->set_errorFillColor(c); + // set error indicator line width + graph->set_errorWidth(1); + // set length of small bars at the end of error bars + graph->set_errorbarSize(15); +``` + +There are more properties that you can find in the documentation of the mix-in classes `JKQTPxyGraphErrors`, `JKQTPxGraphErrors`, `JKQTPyGraphErrors`, `JKQTPgraphErrors`. + +In addition the plot key is moved outside the pot and the grid in the plot is switched off: +```c++ + // 6. change locaion of key (outside top-right) + plot.get_plotter()->set_keyPosition(JKQTPkeyOutsideRightTop); + // ... and switch off the grid + plot.getXAxis()->set_drawGrid(false); + plot.getXAxis()->set_drawMinorGrid(false); + plot.getYAxis()->set_drawGrid(false); + plot.getYAxis()->set_drawMinorGrid(false); +``` + +The result looks like this: + +![jkqtplotter_simpletest_errorbarstyles](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_errorbarstyles.png) + +Error bars are implemented in the mixin-classes `JKQTPxyGraphErrors`, `JKQTPxGraphErrors` and `JKQTPyGraphErrors` that are all derived from `JKQTPgraphErrors`. With these it is simple to add error indicators to several different plot styles. Usually you can recognize these by looking at the class name, e.g. `JKQTPxyLineGraph` is a simple line+symbol graph, and `JKQTPxyLineErrorGraph` is the same with error indictaors (see above). There are also several other plots with error indicators: + - `JKQTPbarVerticalErrorGraph` for barcharts with errors:
![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_errorbarstyles_barcharts.png) + - `JKQTPimpulsesVerticalGraph` for impulse/candle-stick charts with errors:
![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_errorbarstyles_impulses.png) + - `JKQTPfilledCurveXErrorGraph` for filled curves with errors:
![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_errorbarstyles_filledcurves.png) +. + + +[Back to JKQTPlotter main page](https://github.com/jkriege2/JKQtPlotter/) \ No newline at end of file diff --git a/test/jkqtplotter_simpletest_errorbarstyles/jkqtplotter_simpletest_errorbarstyles.cpp b/test/jkqtplotter_simpletest_errorbarstyles/jkqtplotter_simpletest_errorbarstyles.cpp new file mode 100644 index 0000000000..95336ceb8a --- /dev/null +++ b/test/jkqtplotter_simpletest_errorbarstyles/jkqtplotter_simpletest_errorbarstyles.cpp @@ -0,0 +1,109 @@ +#include +#include "jkqtplotter/jkqtplotter.h" +#include "jkqtplottertools/jkqtptools.h" + + +int main(int argc, char* argv[]) +{ + QApplication app(argc, argv); + + // 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 data a vector of x-values for a simple plot + // and generate some values for varying errors + // y-data for the pot will be generated later to position the + // plot at different locations. + QVector X, Yerror, Xerror; + const int Ndata=7; // number of plot points in each curve + for (int i=0; iaddCopiedColumn(X, "x"); + size_t columnXError=ds->addCopiedColumn(Xerror, "xerror"); + size_t columnYError=ds->addCopiedColumn(Yerror, "yerror"); + + + // 3. now we make several plots with different error styles + // for that we iterate over every style from the vector errorStyles + // the array showXandYError indicates whether we want x- and y-error + // for a style for all stywhere this is false, only y-error-indicators + // are shown + QVector errorStyles {JKQTPnoError, JKQTPerrorBars, JKQTPerrorSimpleBars, JKQTPerrorLines, JKQTPerrorPolygons, JKQTPerrorBoxes, JKQTPerrorEllipses, JKQTPerrorBarsPolygons, JKQTPerrorBarsLines, JKQTPerrorSimpleBarsLines, JKQTPerrorSimpleBarsPolygons }; + QVector showXandYError { false , true , true , false , false , true , true , false , false , false , false }; + + for (int errorID=0; errorID Y; + for (auto& xx: X) { + Y<(errorID)*2.5; + } + + JKQTPxyLineErrorGraph* graph=new JKQTPxyLineErrorGraph(&plot); + + // copy data into datastore and immediately set the yColumn + graph->set_xColumn(columnX); + graph->set_yColumn(ds->addCopiedColumn(Y, "y"+QString::number(errorID))); + graph->set_xErrorColumn(columnXError); + graph->set_yErrorColumn(columnYError); + + // set error style, for the y-axis + graph->set_yErrorStyle(errorStyles[errorID]); + // no error indicators for the x-values + graph->set_xErrorStyle(JKQTPnoError); + // ... unless: for some error styles we want error in both directions + if (showXandYError[errorID]) { + graph->set_xErrorStyle(errorStyles[errorID]); + graph->set_drawLine(false); + } + // make error indicator 30% transparent + QColor c=graph->get_errorFillColor(); + c.setAlphaF(0.3); + graph->set_errorFillColor(c); + // set error indicator line width + graph->set_errorWidth(1); + // set length of small bars at the end of error bars + graph->set_errorbarSize(15); + + + // set symbol (cross/X) + pen style (and color)dashed) + graph->set_symbol(JKQTPcross); + graph->set_style(Qt::DashLine); + // set symbol size + graph->set_symbolSize(5); + // set width of symbol lines + graph->set_symbolWidth(1); + // set width of graph line + graph->set_lineWidth(1); + + // graph title is made from symbol+errorStylestyle, we use the LaTeX instruction \verb around the + // result of JKQTPerrorPlotstyle2String(), because it contains underscores that would otherwise + // lead to lower-case letter, which we don't want + graph->set_title("\\verb{"+JKQTPerrorPlotstyle2String(errorStyles[errorID])+"}"); + + // add the graph to the plot, so it is actually displayed + plot.addGraph(graph); + } + + // 4. autoscale the plot so the graph is contained + plot.zoomToFit(); + + // 6. change locaion of key (outside top-right) + plot.get_plotter()->set_keyPosition(JKQTPkeyOutsideRightTop); + // ... and switch off the grid + plot.getXAxis()->set_drawGrid(false); + plot.getXAxis()->set_drawMinorGrid(false); + plot.getYAxis()->set_drawGrid(false); + plot.getYAxis()->set_drawMinorGrid(false); + + // 7. show plotter and make it a decent size + plot.show(); + plot.resize(800,600); + + return app.exec(); +} diff --git a/test/jkqtplotter_simpletest_errorbarstyles/jkqtplotter_simpletest_errorbarstyles.pro b/test/jkqtplotter_simpletest_errorbarstyles/jkqtplotter_simpletest_errorbarstyles.pro new file mode 100644 index 0000000000..1d5b490233 --- /dev/null +++ b/test/jkqtplotter_simpletest_errorbarstyles/jkqtplotter_simpletest_errorbarstyles.pro @@ -0,0 +1,16 @@ +# source code for this simple demo +SOURCES = jkqtplotter_simpletest_errorbarstyles.cpp + +# configure Qt +CONFIG += qt +QT += core gui svg +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport + +# output executable name +TARGET = jkqtplotter_simpletest_errorbarstyles + +# include JKQtPlotter source code +include(../../lib/jkqtplotter.pri) +# here you can activate some debug options +#DEFINES += SHOW_JKQTPLOTTER_DEBUG +#DEFINES += JKQTBP_AUTOTIMER