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.

## Protected Member Functions

void | changeEvent (QEvent *event) override

## 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

  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

## addSeries()

bool addSeries | ( | const std::vector< float > & | y,
|  | const color4ub & | color = color4ub{ 0, 0, 0, 255 },
|  | const QString & | name = "" )

Parameters

  y | The y values
  color | The color of the line
  name | The 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

  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

## setXAxisTitle()

void setXAxisTitle | ( | const QString & | title | ) |

Parameters

  title | The title

## setYAxisTitle()

void setYAxisTitle | ( | const QString & | title | ) |

Parameters

  title | The title

## setTickLabels()

void setTickLabels | ( | Axis | a,
|  | const std::vector< float > & | tickPositions,
|  | const QStringList & | tickLabels )

Parameters

  a | The axis
  tickPositions | The tick positions
  tickLabels | The tick labels

Returns
  True if successful

## setAxisLimits()

void setAxisLimits | ( | Axis | a,
|  | float | min,
|  | float | max )

Parameters

  a | The axis
  min | The minimum value
  max | The 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

  min | The minimum value
  max | The 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

  min | The minimum value
  max | The maximum value

Returns
  True if successful

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

## setFontSize()

void setFontSize | ( | int | size = 14 | ) |

Parameters

  size | The font size

Returns
  True if successful

## setLineWidth()

void setLineWidth | ( | float | width = 1.0 | ) |

Parameters

  width | The line width

Returns
  True if successful

## setAxisLogScale()

void setAxisLogScale | ( | Axis | a,
|  | bool | logScale )

Parameters

  a | The axis
  logScale | True for log scale, false for linear

Returns
  True if successful

## setAxisDigits()

void setAxisDigits | ( | Axis | a,
|  | int | digits = 2 )

Parameters

  a | The axis
  digits | The number of digits

Returns
  True if successful

## labelPeaks()

void labelPeaks | ( | int | yColumn = 1,
|  | float | threshold = 1.0,
|  | int | windowSize = 5 )

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)

## setAxisColor()

void setAxisColor | ( | Axis | a,
|  | const color4ub & | color )

Parameters

  a | The axis
  color | The color

## setBackgroundColor()

void setBackgroundColor | ( | const color4ub & | color | ) |

Parameters

  color | The color

## setLegendLocation()

void setLegendLocation | ( | LegendLocation | location | ) |

Parameters

  location | The location

## setShowPoints()

void setShowPoints | ( | bool | visible | ) |

Parameters

  visible | True to show data points, false to hide them

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

- chartwidget.h