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): Simple Graph Labels Example

This project (see graphlabels demonstrates the use of JKQTPXYGraphLabels to add labels to the datapoints of a graph.

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

Here is a short summary of the important parts of the code:

// 1. create a plotter window and get a pointer to the internal datastore (for convenience)
// 2. make up some arbitrary data to be used for plotting
const size_t columnX=ds->addLinearColumn(Ndata, -1,1,"x");
const size_t columnY=ds->addCalculatedColumnFromColumn(columnX, [](double x) { return jkqtp_roundToDigits(-sin(x*3.0),2);}, "data");
// 3. create barchart and line-chart to display the data:
// 3.1 Barcart:
graph1->setBarPositionColumn(columnX);
graph1->setBarHeightColumn(columnY);
graph1->setTitle(QObject::tr("dataset: bars"));
graph1->setColor(QColorWithAlphaF(graph1->getFillColor(),0.25));
// 3.2: LineChart:
graph2->setXColumn(columnX);
graph2->setYColumn(columnY);
graph2->setTitle(QObject::tr("dataset: lines"));
graph2->setColor(QColorWithAlphaF(graph2->getLineColor(),0.5));
// 4. now we add the data labels:
// 4.1. create a JKQTPXYGraphLabels instance that displays the y-values at each location:
// use the same (x,y) dataset as above. This is used on the one hand to derive the position of the label and on the other hand the label contents
graphLabels->setXColumn(graph1->getXColumn());
graphLabels->setYColumn(graph1->getYColumn());
// 4.2. set position of labels and some styling options
graphLabels->setTextFontSize(14);
// 5. add the graphs to the plot, so it is actually displayed
plot.addGraph(graph1);
plot.addGraph(graph2);
plot.addGraph(graphLabels);
void setBarHeightColumn(int column)
returns xColumn or yColumn, whichever is used for the height of the bars (depending on whether the ba...
virtual void setColor(QColor c)
set outline and fill color at the same time
void setBarPositionColumn(int column)
returns xColumn or yColumn, whichever is used for the position of the bars (depending on whether the ...
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 addCalculatedColumnFromColumn(size_t otherColumn, const std::function< double(double)> &f, const QString &name=QString(""))
add a column with the same number of entries, as in the other column otherColumn ,...
QColor getFillColor() const
set the color of the graph filling
QColor getLineColor() const
get the color of the graph line
void setTextFontSize(double __value)
set the base font size of text
void setLabelPosition(JKQTPGraphLabelPosition r)
position of the label
virtual void setTitle(const QString &__value)
sets the title of the plot (for display in key!).
void setYColumn(int __value)
the column that contains the y-component of the datapoints
void setXColumn(int __value)
the column that contains the x-component of the datapoints
int getXColumn() const
the column that contains the x-component of the datapoints
int getYColumn() const
the column that contains the y-component of the datapoints
This graph plots a series of data labels. This can be used to add number-labels to e....
Definition jkqtpgraphlabels.h:103
@ YValueLabel
generates a label with the y-coordinate only, calls setDefaultYLabelGenerator()
Definition jkqtpgraphlabels.h:108
This implements xy line plots. This also alows to draw symbols at the data points.
Definition jkqtplines.h:61
void setColor(QColor c)
set color of line and symbol
plotter widget for scientific plots (uses JKQTBasePlotter to do the actual drawing)
Definition jkqtplotter.h:364
size_t addGraph(JKQTPPlotElement *gr)
Definition jkqtplotter.h:784
JKQTPDatastore * getDatastore()
returns a pointer to the datastore used by this object
Definition jkqtplotter.h:611
@ JKQTPGLabelAwayFromXAxis
all labels pointing away from the x-axis
Definition jkqtpgraphlabelstylemixin.h:50
QColor QColorWithAlphaF(const QColor &color, qreal alphaF)
construct a QColor, based on the given color, but with alpha set to the specified value alphaF
Definition jkqtptools.h:364
double jkqtp_roundToDigits(const double &v, const int decDigits)
round a double v using round() to a given number of decimal digits
Definition jkqtpmathtools.h:162

The result looks like this:

graphlabels

or this:

graphlabels_hor