Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
QmitkChartWidget Class Reference

Qt widget for displaying interactive charts based on the plotly.js library. More...

#include <QmitkChartWidget.h>

Inheritance diagram for QmitkChartWidget:
Collaboration diagram for QmitkChartWidget:

Public Types

enum class  ChartType {
  bar , line , spline , pie ,
  area , area_spline , scatter
}
 Enumeration of supported chart types. More...
 
enum class  ColorTheme { darkstyle , lightstyle }
 Enumeration of chart color themes. More...
 
enum class  LineStyle { solid , dashed }
 Enumeration of line drawing styles. More...
 
enum class  MarkerSymbol {
  circle , diamond , cross , square ,
  pentagon , star , x , diamond_tall ,
  star_diamond , star_triangle_up , star_triangle_down , asterisk ,
  cross_thin , x_thin
}
 Enumeration of data point marker symbols. More...
 
enum class  ChartColor {
  red , orange , yellow , green ,
  blue , purple , brown , magenta ,
  tan , cyan , olive , maroon ,
  navy , aquamarine , turqouise , silver ,
  lime , teal , indigo , violet ,
  pink , black , white , grey
}
 Enumeration of named chart colors. More...
 
enum class  AxisScale { linear , log }
 Enumeration of axis scale types. More...
 
enum class  LegendPosition {
  bottomMiddle , bottomRight , topRight , topLeft ,
  middleRight
}
 Enumeration of legend positions within the chart. More...
 

Public Slots

void OnLoadFinished (bool isLoadSuccessful)
 Slot called when the web page finishes loading. More...
 
void OnPageSuccessfullyLoaded ()
 Slot called when the chart page has been successfully loaded and is ready. More...
 

Signals

void PageSuccessfullyLoaded ()
 Emitted when the chart page has been successfully loaded and is ready for use. More...
 

Public Member Functions

 QmitkChartWidget (QWidget *parent=nullptr)
 Construct a chart widget. More...
 
 QmitkChartWidget (QWidget *parent, bool unitTest)
 Construct a chart widget for unit testing. More...
 
 ~QmitkChartWidget () override
 Destructor. More...
 
void AddData1D (const std::vector< double > &data1D, const std::string &label, ChartType chartType=ChartType::bar)
 Add a 1D data series to the chart. More...
 
void UpdateData1D (const std::vector< double > &data1D, const std::string &label)
 Update the data of an existing 1D data series. More...
 
void UpdateData2D (const std::vector< std::pair< double, double > > &data2D, const std::string &label)
 Update the data of an existing 2D data series. More...
 
void UpdateChartExampleData (const std::vector< std::pair< double, double > > &data2D, const std::string &label, const std::string &type, const std::string &color, const std::string &lineStyle, const std::string &pieLabelsData={})
 Update chart example data with full property specification. More...
 
void AddData2D (const std::vector< std::pair< double, double > > &data2D, const std::string &label, ChartType chartType=ChartType::bar)
 Add a 2D data series to the chart. More...
 
void AddChartExampleData (const std::vector< std::pair< double, double > > &data2D, const std::string &label, const std::string &type, const std::string &color, const std::string &style, const std::string &pieLabelsData={})
 Add chart example data with full property specification. More...
 
void RemoveData (const std::string &label)
 Remove a data series from the chart. More...
 
void UpdateLabel (const std::string &existingLabel, const std::string &newLabel)
 Rename an existing data series. More...
 
QmitkChartxyData * GetDataElementByLabel (const std::string &label) const
 Retrieve the data element for a given label. More...
 
void SetColor (const std::string &label, const std::string &colorName)
 Set the color of a data series. More...
 
void SetLineStyle (const std::string &label, LineStyle style)
 Set the line style of a data series. More...
 
void SetMarkerSymbol (const std::string &label, MarkerSymbol symbol)
 Set the marker symbol for a data series. More...
 
void SetYAxisScale (AxisScale scale)
 Set the Y axis scale type. More...
 
void SetXAxisLabel (const std::string &label)
 Set the X axis label text. More...
 
void SetYAxisLabel (const std::string &label)
 Set the Y axis label text. More...
 
void SetPieLabels (const std::vector< std::string > &pieLabels, const std::string &label)
 Set category labels for pie chart segments. More...
 
void SetTitle (const std::string &title)
 Set the chart title. More...
 
void SetChartType (const std::string &label, ChartType type)
 Change the chart type of an existing data series. More...
 
void SetXErrorBars (const std::string &label, const std::vector< double > &errorPlus, const std::vector< double > &errorMinus=std::vector< double >())
 Set error bars in the X direction for a data series. More...
 
void SetYErrorBars (const std::string &label, const std::vector< double > &errorPlus, const std::vector< double > &errorMinus=std::vector< double >())
 Set error bars in the Y direction for a data series. More...
 
void SetLegendPosition (LegendPosition position)
 Set the legend position. More...
 
void SetShowLegend (bool show)
 Set whether the chart legend is visible. More...
 
void SetStackedData (bool stacked)
 Set whether data series are displayed in stacked mode. More...
 
void Show (bool showSubChart=false)
 Render and display the chart in the widget. More...
 
void SetShowDataPoints (bool showDataPoints)
 Set whether data point markers are visible. More...
 
void Clear ()
 Clear all data series and reset the widget. More...
 
void SetTheme (ColorTheme themeEnabled)
 Set the chart color theme. More...
 
void SetShowSubchart (bool showSubChart)
 Set whether the subchart (overview navigator) is shown. More...
 
void SetShowErrorBars (bool showErrorBars)
 Set whether error bars are shown. More...
 
void SetMinMaxValueXView (double minValueX, double maxValueX)
 Set the visible X axis range (zoom). More...
 
void SetMinMaxValueYView (double minValueY, double maxValueY)
 Set the visible Y axis range (zoom). More...
 
void Reload ()
 Reload the chart to reflect property or data changes. More...
 
QSize sizeHint () const override
 Return the recommended size for the widget. More...
 
void SavePlotAsImage ()
 Save the current chart as an SVG image file. More...
 

Detailed Description

Qt widget for displaying interactive charts based on the plotly.js library.

QmitkChartWidget provides a high-level C++ API for creating interactive charts within MITK applications. Data is added via AddData1D() or AddData2D(), and multiple data series with different chart types and properties can be displayed simultaneously.

Supported chart types:

  • Line chart
  • Bar chart
  • Spline chart (smoothed line)
  • Pie chart
  • Scatter chart
  • Area chart
  • Area spline chart

Features include configurable colors, line styles, marker symbols, error bars, legend positioning, axis labels and scales, themes, and data point visibility.

Internally, chart rendering is handled by JavaScript (plotly.js) embedded in a QWebEngineView. Data and configuration are passed to JavaScript via QWebChannel.

See also
https://plot.ly/javascript/ for the underlying JavaScript charting library.
QmitkChartData
QmitkChartxyData

Definition at line 50 of file QmitkChartWidget.h.

Member Enumeration Documentation

◆ AxisScale

Enumeration of axis scale types.

Enumerator
linear 

Linear axis scale (default).

log 

Logarithmic axis scale.

Definition at line 137 of file QmitkChartWidget.h.

◆ ChartColor

Enumeration of named chart colors.

Enumerator
red 

Red.

orange 

Orange.

yellow 

Yellow.

green 

Green.

blue 

Blue.

purple 

Purple.

brown 

Brown.

magenta 

Magenta.

tan 

Tan.

cyan 

Cyan.

olive 

Olive.

maroon 

Maroon.

navy 

Navy.

aquamarine 

Aquamarine.

turqouise 

Turquoise.

silver 

Silver.

lime 

Lime.

teal 

Teal.

indigo 

Indigo.

violet 

Violet.

pink 

Pink.

black 

Black.

white 

White.

grey 

Grey.

Definition at line 107 of file QmitkChartWidget.h.

◆ ChartType

Enumeration of supported chart types.

Enumerator
bar 

Bar chart.

See also
https://plot.ly/javascript/bar-charts/
line 

Line chart.

See also
https://plot.ly/javascript/line-charts/
spline 

Spline chart (smoothed line).

See also
https://plot.ly/~jduelfer/23/spline/
pie 

Pie chart.

See also
https://plot.ly/javascript/pie-charts/
area 

Filled area chart.

See also
https://plot.ly/javascript/filled-area-plots/
area_spline 

Area chart with spline interpolation.

scatter 

Scatter chart.

See also
https://plot.ly/javascript/line-and-scatter/

Definition at line 58 of file QmitkChartWidget.h.

◆ ColorTheme

Enumeration of chart color themes.

Enumerator
darkstyle 

Dark gray background, white foreground.

lightstyle 

White background, black foreground.

Definition at line 71 of file QmitkChartWidget.h.

◆ LegendPosition

Enumeration of legend positions within the chart.

See also
https://plot.ly/javascript/legend/
Enumerator
bottomMiddle 

Bottom center of the chart.

bottomRight 

Bottom right corner.

topRight 

Top right corner (default).

topLeft 

Top left corner.

middleRight 

Middle right side.

Definition at line 146 of file QmitkChartWidget.h.

◆ LineStyle

Enumeration of line drawing styles.

Enumerator
solid 

Solid line.

dashed 

Dashed line.

Definition at line 79 of file QmitkChartWidget.h.

◆ MarkerSymbol

Enumeration of data point marker symbols.

Enumerator
circle 

Circle marker.

diamond 

Diamond marker.

cross 

Cross (+) marker.

square 

Square marker.

pentagon 

Pentagon marker.

star 

Star marker.

x 

X marker.

diamond_tall 

Tall diamond marker.

star_diamond 

Star-diamond marker.

star_triangle_up 

Upward star-triangle marker.

star_triangle_down 

Downward star-triangle marker.

asterisk 

Asterisk marker.

cross_thin 

Thin cross marker.

x_thin 

Thin X marker.

Definition at line 87 of file QmitkChartWidget.h.

Constructor & Destructor Documentation

◆ QmitkChartWidget() [1/2]

QmitkChartWidget::QmitkChartWidget ( QWidget *  parent = nullptr)
explicit

Construct a chart widget.

Parameters
[in]parentThe parent QWidget (default: nullptr).

◆ QmitkChartWidget() [2/2]

QmitkChartWidget::QmitkChartWidget ( QWidget *  parent,
bool  unitTest 
)
explicit

Construct a chart widget for unit testing.

Parameters
[in]parentThe parent QWidget.
[in]unitTestIf true, the widget is constructed in unit test mode.

◆ ~QmitkChartWidget()

QmitkChartWidget::~QmitkChartWidget ( )
override

Destructor.

Member Function Documentation

◆ AddChartExampleData()

void QmitkChartWidget::AddChartExampleData ( const std::vector< std::pair< double, double > > &  data2D,
const std::string &  label,
const std::string &  type,
const std::string &  color,
const std::string &  style,
const std::string &  pieLabelsData = {} 
)

Add chart example data with full property specification.

Convenience method for the chart example plugin that accepts chart properties as strings rather than enum values.

Parameters
[in]data2DThe (x, y) data pairs.
[in]labelThe data series label.
[in]typeThe chart type as a string.
[in]colorThe color as a string.
[in]styleThe line style as a string.
[in]pieLabelsDataOptional pie chart labels (default: empty).

◆ AddData1D()

void QmitkChartWidget::AddData1D ( const std::vector< double > &  data1D,
const std::string &  label,
ChartType  chartType = ChartType::bar 
)

Add a 1D data series to the chart.

The values are automatically assigned integer x-values starting at 0.

Parameters
[in]data1DThe y-values of the data series.
[in]labelA unique name for this data series, also used as the display label.
[in]chartTypeThe chart type to use for this series (default: bar).
Note
If the label already exists, a unique suffix is appended.
Data can be cleared with Clear().
Warning
For pie charts, each element represents a separate category and values are summed.

◆ AddData2D()

void QmitkChartWidget::AddData2D ( const std::vector< std::pair< double, double > > &  data2D,
const std::string &  label,
ChartType  chartType = ChartType::bar 
)

Add a 2D data series to the chart.

Each entry is an (x, y) pair. Call repeatedly to display multiple series.

Parameters
[in]data2DThe (x-value, y-value) data pairs.
[in]labelA unique name for this data series.
[in]chartTypeThe chart type to use (default: bar).
Note
If the label already exists, a unique suffix is appended.
Data can be cleared with Clear().
Warning
For pie charts, each element represents a separate category.

◆ Clear()

void QmitkChartWidget::Clear ( )

Clear all data series and reset the widget.

◆ GetDataElementByLabel()

QmitkChartxyData* QmitkChartWidget::GetDataElementByLabel ( const std::string &  label) const

Retrieve the data element for a given label.

Parameters
[in]labelThe label identifier of the data series.
Returns
A pointer to the QmitkChartxyData, or nullptr if not found.

◆ OnLoadFinished

void QmitkChartWidget::OnLoadFinished ( bool  isLoadSuccessful)
slot

Slot called when the web page finishes loading.

Parameters
[in]isLoadSuccessfultrue if the page loaded successfully.

◆ OnPageSuccessfullyLoaded

void QmitkChartWidget::OnPageSuccessfullyLoaded ( )
slot

Slot called when the chart page has been successfully loaded and is ready.

◆ PageSuccessfullyLoaded

void QmitkChartWidget::PageSuccessfullyLoaded ( )
signal

Emitted when the chart page has been successfully loaded and is ready for use.

◆ Reload()

void QmitkChartWidget::Reload ( )

Reload the chart to reflect property or data changes.

Call this after modifying chart properties or adding data to an already-displayed chart.

◆ RemoveData()

void QmitkChartWidget::RemoveData ( const std::string &  label)

Remove a data series from the chart.

Works for both 1D and 2D data.

Parameters
[in]labelThe label identifier of the data series to remove.
Exceptions
std::invalid_argumentIf the label is not found.
Note
Use Clear() to remove all data at once.

◆ SavePlotAsImage()

void QmitkChartWidget::SavePlotAsImage ( )

Save the current chart as an SVG image file.

Triggers the JavaScript side to generate the SVG, which is then saved via a file dialog.

◆ SetChartType()

void QmitkChartWidget::SetChartType ( const std::string &  label,
ChartType  type 
)

Change the chart type of an existing data series.

Parameters
[in]labelThe label identifier of the data series.
[in]typeThe new chart type.
Note
If an unknown label is given, nothing happens.
Warning
Pie charts differ significantly from other types.
See also
ChartType

◆ SetColor()

void QmitkChartWidget::SetColor ( const std::string &  label,
const std::string &  colorName 
)

Set the color of a data series.

Parameters
[in]labelThe label identifier of the data series.
[in]colorNameThe color as a CSS color name or hex code (e.g. "red" or "#FF0000").
Note
If an unknown label is given, nothing happens.
Warning
Either set colors for all series or none. Mixed approaches may cause plotly to assign conflicting colors.
See also
https://www.w3schools.com/cssref/css_colors.asp

◆ SetLegendPosition()

void QmitkChartWidget::SetLegendPosition ( LegendPosition  position)

Set the legend position.

Parameters
[in]positionThe desired legend position.
See also
LegendPosition

◆ SetLineStyle()

void QmitkChartWidget::SetLineStyle ( const std::string &  label,
LineStyle  style 
)

Set the line style of a data series.

Parameters
[in]labelThe label identifier of the data series.
[in]styleThe line style (solid or dashed).
Note
If an unknown label is given, nothing happens.
Warning
Only takes visual effect when the chart type is ChartType::line. The style is retained if the chart type changes later.

◆ SetMarkerSymbol()

void QmitkChartWidget::SetMarkerSymbol ( const std::string &  label,
MarkerSymbol  symbol 
)

Set the marker symbol for a data series.

Parameters
[in]labelThe label identifier of the data series.
[in]symbolThe marker symbol to use.
Note
If an unknown label is given, nothing happens.

◆ SetMinMaxValueXView()

void QmitkChartWidget::SetMinMaxValueXView ( double  minValueX,
double  maxValueX 
)

Set the visible X axis range (zoom).

Parameters
[in]minValueXThe minimum X value to display.
[in]maxValueXThe maximum X value to display.

◆ SetMinMaxValueYView()

void QmitkChartWidget::SetMinMaxValueYView ( double  minValueY,
double  maxValueY 
)

Set the visible Y axis range (zoom).

Parameters
[in]minValueYThe minimum Y value to display.
[in]maxValueYThe maximum Y value to display.

◆ SetPieLabels()

void QmitkChartWidget::SetPieLabels ( const std::vector< std::string > &  pieLabels,
const std::string &  label 
)

Set category labels for pie chart segments.

Parameters
[in]pieLabelsThe category labels, one per data element.
[in]labelThe label of the pie chart data series.
Note
The series label (from AddData1D) still serves as the unique identifier.

◆ SetShowDataPoints()

void QmitkChartWidget::SetShowDataPoints ( bool  showDataPoints)

Set whether data point markers are visible.

Parameters
[in]showDataPointstrue to display data point markers.
See also
https://plot.ly/javascript/line-charts/#styling-line-plot
https://plot.ly/javascript/pointcloud/

◆ SetShowErrorBars()

void QmitkChartWidget::SetShowErrorBars ( bool  showErrorBars)

Set whether error bars are shown.

Parameters
[in]showErrorBarstrue to display error bars.
Note
Requires Reload() to display the change.

◆ SetShowLegend()

void QmitkChartWidget::SetShowLegend ( bool  show)

Set whether the chart legend is visible.

Parameters
[in]showtrue to show the legend, false to hide it.

◆ SetShowSubchart()

void QmitkChartWidget::SetShowSubchart ( bool  showSubChart)

Set whether the subchart (overview navigator) is shown.

Parameters
[in]showSubCharttrue to show the subchart.
Note
Requires Reload() to display the change.

◆ SetStackedData()

void QmitkChartWidget::SetStackedData ( bool  stacked)

Set whether data series are displayed in stacked mode.

Parameters
[in]stackedtrue to stack data series.

◆ SetTheme()

void QmitkChartWidget::SetTheme ( ColorTheme  themeEnabled)

Set the chart color theme.

Parameters
[in]themeEnabledThe color theme to apply.
Warning
Must be called before Show() or Reload() to take effect.

◆ SetTitle()

void QmitkChartWidget::SetTitle ( const std::string &  title)

Set the chart title.

Parameters
[in]titleThe title text displayed above the chart.

◆ SetXAxisLabel()

void QmitkChartWidget::SetXAxisLabel ( const std::string &  label)

Set the X axis label text.

Parameters
[in]labelThe label text.

◆ SetXErrorBars()

void QmitkChartWidget::SetXErrorBars ( const std::string &  label,
const std::vector< double > &  errorPlus,
const std::vector< double > &  errorMinus = std::vector< double >() 
)

Set error bars in the X direction for a data series.

Parameters
[in]labelThe label identifier of the data series.
[in]errorPlusThe error values in the positive X direction.
[in]errorMinusThe error values in the negative X direction. If empty, symmetric error bars (same as errorPlus) are used.

◆ SetYAxisLabel()

void QmitkChartWidget::SetYAxisLabel ( const std::string &  label)

Set the Y axis label text.

Parameters
[in]labelThe label text.

◆ SetYAxisScale()

void QmitkChartWidget::SetYAxisScale ( AxisScale  scale)

Set the Y axis scale type.

Parameters
[in]scaleThe axis scale (linear or logarithmic).
See also
https://plot.ly/javascript/log-plot/

◆ SetYErrorBars()

void QmitkChartWidget::SetYErrorBars ( const std::string &  label,
const std::vector< double > &  errorPlus,
const std::vector< double > &  errorMinus = std::vector< double >() 
)

Set error bars in the Y direction for a data series.

Parameters
[in]labelThe label identifier of the data series.
[in]errorPlusThe error values in the positive Y direction.
[in]errorMinusThe error values in the negative Y direction. If empty, symmetric error bars (same as errorPlus) are used.
See also
SetXErrorBars

◆ Show()

void QmitkChartWidget::Show ( bool  showSubChart = false)

Render and display the chart in the widget.

Parameters
[in]showSubChartWhether to show a subchart (overview navigator) below the main chart (default: false).
Note
If no data has been added, an empty chart is displayed.
See also
AddData1D
AddData2D

◆ sizeHint()

QSize QmitkChartWidget::sizeHint ( ) const
override

Return the recommended size for the widget.

Returns
The size hint as a QSize.

◆ UpdateChartExampleData()

void QmitkChartWidget::UpdateChartExampleData ( const std::vector< std::pair< double, double > > &  data2D,
const std::string &  label,
const std::string &  type,
const std::string &  color,
const std::string &  lineStyle,
const std::string &  pieLabelsData = {} 
)

Update chart example data with full property specification.

Parameters
[in]data2DThe (x, y) data pairs.
[in]labelThe data series label.
[in]typeThe chart type as a string.
[in]colorThe color as a string.
[in]lineStyleThe line style as a string.
[in]pieLabelsDataOptional pie chart labels (default: empty).

◆ UpdateData1D()

void QmitkChartWidget::UpdateData1D ( const std::vector< double > &  data1D,
const std::string &  label 
)

Update the data of an existing 1D data series.

Parameters
[in]data1DThe new y-values.
[in]labelThe label of the existing data series.
Note
If the label does not exist, nothing happens.
See also
AddData1D

◆ UpdateData2D()

void QmitkChartWidget::UpdateData2D ( const std::vector< std::pair< double, double > > &  data2D,
const std::string &  label 
)

Update the data of an existing 2D data series.

Parameters
[in]data2DThe new (x, y) value pairs.
[in]labelThe label of the existing data series.
Note
If the label does not exist, nothing happens.
See also
UpdateData1D
AddData2D

◆ UpdateLabel()

void QmitkChartWidget::UpdateLabel ( const std::string &  existingLabel,
const std::string &  newLabel 
)

Rename an existing data series.

Parameters
[in]existingLabelThe current label of the data series.
[in]newLabelThe new label to assign.

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