AvogadroLibs 1.103.0
Loading...
Searching...
No Matches
ChartWidget Class Reference

A Qt widget for displaying charts via JKQtPlotter. More...

#include <avogadro/qtgui/chartwidget.h>

Inheritance diagram for ChartWidget:

Public Types

enum class  Axis {
  x ,
  y
}
 Axis enumeration.
enum class  LegendLocation {
  None ,
  TopLeft ,
  TopRight ,
  BottomLeft ,
  BottomRight
}
 Legend location enumeration, relative to the plot.

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.

Public Member Functions

 ChartWidget (QWidget *p=nullptr)
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.
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.
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.
void clearPlots ()
 Clear all plots and data.
void setXAxisTitle (const QString &title)
 Set the title of the x axis.
void setYAxisTitle (const QString &title)
 Set the title of the y axis.
void setTickLabels (Axis a, const std::vector< float > &tickPositions, const QStringList &tickLabels)
 Set the custom tick positions and labels for an axis.
void setAxisLimits (Axis a, float min, float max)
 Set the default axis limits.
void setXAxisLimits (float min, float max)
 Set the default x-axis limits.
void setYAxisLimits (float min, float max)
 Set the default y-axis limits.
void setFontSize (int size=14)
 Set the font size for the ticks and axis titles.
void setLineWidth (float width=1.0)
 Set the line width of the graph lines (in pt).
void setAxisLogScale (Axis a, bool logScale)
 Set to logarithmic scale.
void setAxisDigits (Axis a, int digits=2)
 Set the number of digits to display in tick labels.
void labelPeaks (int yColumn=1, float threshold=1.0, int windowSize=5)
 Label peaks in the plot.
void setAxisColor (Axis a, const color4ub &color)
 Set the color of an axis.
void setBackgroundColor (const color4ub &color)
 Set the color of the plot area.
void setLegendLocation (LegendLocation location)
 Set the location of the legend.
void setShowPoints (bool visible)
 Set the visibility of data points.

Detailed Description

A wrapper around the JKQtPlotter library, providing a widget for displaying line charts, with multiple series, configurable axes, and a legend, etc.

Member Function Documentation

◆ addPlot()

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" )
Parameters
xThe x values
yThe y values
colorThe color of the line
xNameThe name of the x axis
yNameThe name of the y axis
Returns
True if successful

◆ addSeries()

bool addSeries ( const std::vector< float > & y,
const color4ub & color = color4ub{ 0, 0, 0, 255 },
const QString & name = "" )
Parameters
yThe y values
colorThe color of the line
nameThe name of the series
Returns
True if successful

◆ addPlots()

bool addPlots ( const std::vector< std::vector< float > > & plotData,
const color4ub & color = color4ub{ 0, 0, 0, 255 },
const QStringList & names = {} )
Parameters
plotDataThe data for the plots, column[0] is x, rest are y
colorThe color of the lines
namesThe names of the lines (including for the x axis)
Returns
True if successful

◆ setXAxisTitle()

void setXAxisTitle ( const QString & title)
Parameters
titleThe title

◆ setYAxisTitle()

void setYAxisTitle ( const QString & title)
Parameters
titleThe title

◆ setTickLabels()

void setTickLabels ( Axis a,
const std::vector< float > & tickPositions,
const QStringList & tickLabels )
Parameters
aThe axis
tickPositionsThe tick positions
tickLabelsThe tick labels
Returns
True if successful

◆ setAxisLimits()

void setAxisLimits ( Axis a,
float min,
float max )
Parameters
aThe axis
minThe minimum value
maxThe maximum value
Returns
True if successful

If minimum is bigger than maximum, the axis will be reversed

◆ setXAxisLimits()

void setXAxisLimits ( float min,
float max )
Parameters
minThe minimum value
maxThe maximum value
Returns
True if successful

If minimum is bigger than maximum, the axis will be reversed

◆ setYAxisLimits()

void setYAxisLimits ( float min,
float max )
Parameters
minThe minimum value
maxThe maximum value
Returns
True if successful

If minimum is bigger than maximum, the axis will be reversed

◆ setFontSize()

void setFontSize ( int size = 14)
Parameters
sizeThe font size
Returns
True if successful

◆ setLineWidth()

void setLineWidth ( float width = 1.0)
Parameters
widthThe line width
Returns
True if successful

◆ setAxisLogScale()

void setAxisLogScale ( Axis a,
bool logScale )
Parameters
aThe axis
logScaleTrue for log scale, false for linear
Returns
True if successful

◆ setAxisDigits()

void setAxisDigits ( Axis a,
int digits = 2 )
Parameters
aThe axis
digitsThe number of digits
Returns
True if successful

◆ labelPeaks()

void labelPeaks ( int yColumn = 1,
float threshold = 1.0,
int windowSize = 5 )
Parameters
yColumnThe column of the y values
thresholdThe threshold for peak detection
windowSizeThe window size for peak detection (in samples along the x-axis)

◆ setAxisColor()

void setAxisColor ( Axis a,
const color4ub & color )
Parameters
aThe axis
colorThe color

◆ setBackgroundColor()

void setBackgroundColor ( const color4ub & color)
Parameters
colorThe color

◆ setLegendLocation()

void setLegendLocation ( LegendLocation location)
Parameters
locationThe location

◆ setShowPoints()

void setShowPoints ( bool visible)
Parameters
visibleTrue to show data points, false to hide them

The documentation for this class was generated from the following file: