Avogadro::QtGui::ChartWidget#
-
class ChartWidget : public QWidget#
A Qt widget for displaying charts via JKQtPlotter.
A wrapper around the JKQtPlotter library, providing a widget for displaying line charts, with multiple series, configurable axes, and a legend, etc.
Public Types
Public Functions
-
explicit ChartWidget(QWidget *p = nullptr)#
-
~ChartWidget() override#
-
bool addPlot(const std::vector<float> &x, const std::vector<float> &y, const color4ub &color = color4ub{0, 0, 0, 255}, const QString &xName = "x", const QString &yName = "y")#
Add a plot to the chart.
- Parameters:
x – The x values
y – The y values
color – The color of the line
xName – The name of the x axis
yName – The name of the y axis
- Returns:
True if successful
-
bool addSeries(const std::vector<float> &y, const color4ub &color = color4ub{0, 0, 0, 255}, const QString &name = "")#
Add a series to an existing chart.
- Parameters:
y – The y values
color – The color of the line
name – The name of the series
- Returns:
True if successful
-
bool addPlots(const std::vector<std::vector<float>> &plotData, const color4ub &color = color4ub{0, 0, 0, 255}, const QStringList &names = {})#
Add multiple lines to the chart.
- Parameters:
plotData – The data for the plots, column[0] is x, rest are y
color – The color of the lines
names – The names of the lines (including for the x axis)
- Returns:
True if successful
-
void clearPlots()#
Clear all plots and data.
-
void setXAxisTitle(const QString &title)#
Set the title of the x axis.
- Parameters:
title – The title
-
void setYAxisTitle(const QString &title)#
Set the title of the y axis.
- Parameters:
title – The title
-
void setTickLabels(Axis a, const std::vector<float> &tickPositions, const QStringList &tickLabels)#
Set the custom tick positions and labels for an axis.
- Parameters:
a – The axis
tickPositions – The tick positions
tickLabels – The tick labels
- Returns:
True if successful
-
void setAxisLimits(Axis a, float min, float max)#
Set the default axis limits.
If minimum is bigger than maximum, the axis will be reversed
- Parameters:
a – The axis
min – The minimum value
max – The maximum value
- Returns:
True if successful
-
void setXAxisLimits(float min, float max)#
Set the default x-axis limits.
If minimum is bigger than maximum, the axis will be reversed
- Parameters:
min – The minimum value
max – The maximum value
- Returns:
True if successful
-
void setYAxisLimits(float min, float max)#
Set the default y-axis limits.
If minimum is bigger than maximum, the axis will be reversed
- Parameters:
min – The minimum value
max – The maximum value
- Returns:
True if successful
-
void setFontSize(int size = 14)#
Set the font size for the ticks and axis titles.
- Parameters:
size – The font size
- Returns:
True if successful
-
void setLineWidth(float width = 1.0)#
Set the line width of the graph lines (in pt)
- Parameters:
width – The line width
- Returns:
True if successful
-
void setAxisLogScale(Axis a, bool logScale)#
Set to logarithmic scale.
- Parameters:
a – The axis
logScale – True for log scale, false for linear
- Returns:
True if successful
-
void setAxisDigits(Axis a, int digits = 2)#
Set the number of digits to display in tick labels.
- Parameters:
a – The axis
digits – The number of digits
- Returns:
True if successful
-
void labelPeaks(int yColumn = 1, float threshold = 1.0, int windowSize = 5)#
Label peaks in the plot.
- Parameters:
yColumn – The column of the y values
threshold – The threshold for peak detection
windowSize – The window size for peak detection (in samples along the x-axis)
-
void setAxisColor(Axis a, const color4ub &color)#
Set the color of an axis.
- Parameters:
a – The axis
color – The color
-
void setBackgroundColor(const color4ub &color)#
Set the color of the plot area.
- Parameters:
color – The color
-
void setLegendLocation(LegendLocation location)#
Set the location of the legend.
- Parameters:
location – The location
-
inline void setShowPoints(bool visible)#
Set the visibility of data points.
- Parameters:
visible – True to show data points, false to hide them
Public Slots
-
void plotClicked(double x, double y, Qt::KeyboardModifiers modifiers, Qt::MouseButton button)#
register a callback for when the user clicks on the chart
-
void resetZoom()#
Reset the zoom level of the plot (auto-scale to data)
Signals
-
void clicked(float x, float y, Qt::KeyboardModifiers modifiers)#
Emitted when the user single-clicks on the chart.
-
explicit ChartWidget(QWidget *p = nullptr)#