Medical Imaging Interaction Toolkit  2024.06.00
Medical Imaging Interaction Toolkit
QmitkChartWidget Class Reference

QmitkChartWidget is a widget to display various charts based on the javascript chart library plotly. More...

#include <QmitkChartWidget.h>

Inheritance diagram for QmitkChartWidget:
Collaboration diagram for QmitkChartWidget:

Public Types

enum  ChartType {
  ChartType::bar, ChartType::line, ChartType::spline, ChartType::pie,
  ChartType::area, ChartType::area_spline, ChartType::scatter
}
 enum of diagram types. More...
 
enum  ColorTheme { ColorTheme::darkstyle, ColorTheme::lightstyle }
 enum of chart style (modifies background and line color). More...
 
enum  LineStyle { LineStyle::solid, LineStyle::dashed }
 
enum  MarkerSymbol {
  MarkerSymbol::circle, MarkerSymbol::diamond, MarkerSymbol::cross, MarkerSymbol::square,
  MarkerSymbol::pentagon, MarkerSymbol::star, MarkerSymbol::x, MarkerSymbol::diamond_tall,
  MarkerSymbol::star_diamond, MarkerSymbol::star_triangle_up, MarkerSymbol::star_triangle_down, MarkerSymbol::asterisk,
  MarkerSymbol::cross_thin, MarkerSymbol::x_thin
}
 
enum  ChartColor {
  ChartColor::red, ChartColor::orange, ChartColor::yellow, ChartColor::green,
  ChartColor::blue, ChartColor::purple, ChartColor::brown, ChartColor::magenta,
  ChartColor::tan, ChartColor::cyan, ChartColor::olive, ChartColor::maroon,
  ChartColor::navy, ChartColor::aquamarine, ChartColor::turqouise, ChartColor::silver,
  ChartColor::lime, ChartColor::teal, ChartColor::indigo, ChartColor::violet,
  ChartColor::pink, ChartColor::black, ChartColor::white, ChartColor::grey
}
 
enum  AxisScale { AxisScale::linear, AxisScale::log }
 
enum  LegendPosition {
  LegendPosition::bottomMiddle, LegendPosition::bottomRight, LegendPosition::topRight, LegendPosition::topLeft,
  LegendPosition::middleRight
}
 enum of legend position. See https://plot.ly/javascript/legend/ More...
 

Public Slots

void OnLoadFinished (bool isLoadSuccessful)
 
void OnPageSuccessfullyLoaded ()
 

Signals

void PageSuccessfullyLoaded ()
 

Public Member Functions

 QmitkChartWidget (QWidget *parent=nullptr)
 
 QmitkChartWidget (QWidget *parent, bool unitTest)
 
 ~QmitkChartWidget () override
 
void AddData1D (const std::vector< double > &data1D, const std::string &label, ChartType chartType=ChartType::bar)
 Adds 1D data to the widget. More...
 
void UpdateData1D (const std::vector< double > &data1D, const std::string &label)
 Updates data of an existing label. More...
 
void UpdateData2D (const std::vector< std::pair< double, double > > &data2D, const std::string &label)
 
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=0)
 
void AddData2D (const std::vector< std::pair< double, double > > &data2D, const std::string &label, ChartType chartType=ChartType::bar)
 Adds 2D data to the widget. Call repeatedly for displaying multiple charts. 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=0)
 
void RemoveData (const std::string &label)
 Removes data from the widget, works for 1D and 2D Data. More...
 
void UpdateLabel (const std::string &existingLabel, const std::string &newLabel)
 
QmitkChartxyDataGetDataElementByLabel (const std::string &label) const
 
void SetColor (const std::string &label, const std::string &colorName)
 Sets the color of one data entry (identifier is previously assigned label) More...
 
void SetLineStyle (const std::string &label, LineStyle style)
 Sets the line style of one data entry (identifier is previously assigned label) More...
 
void SetMarkerSymbol (const std::string &label, MarkerSymbol symbol)
 Sets the marker style of one data entry (identifier is previously assigned label) More...
 
void SetYAxisScale (AxisScale scale)
 Sets the axis scale to either linear (default) or logarithmic. More...
 
void SetXAxisLabel (const std::string &label)
 
void SetYAxisLabel (const std::string &label)
 
void SetPieLabels (const std::vector< std::string > &pieLabels, const std::string &label)
 Sets labels for pie chart data. More...
 
void SetTitle (const std::string &title)
 Sets a title for the chart. More...
 
void SetChartType (const std::string &label, ChartType type)
 Sets the chart type for a data entry. More...
 
void SetXErrorBars (const std::string &label, const std::vector< double > &errorPlus, const std::vector< double > &errorMinus=std::vector< double >())
 Sets error bars for data in x direction. More...
 
void SetYErrorBars (const std::string &label, const std::vector< double > &errorPlus, const std::vector< double > &errorMinus=std::vector< double >())
 Sets error bars for data in y direction. More...
 
void SetLegendPosition (LegendPosition position)
 Sets the legend position. More...
 
void SetShowLegend (bool show)
 
void SetStackedData (bool stacked)
 
void Show (bool showSubChart=false)
 Displays the chart in the widget. More...
 
void SetShowDataPoints (bool showDataPoints)
 Either displays the dataPoints or not. More...
 
void Clear ()
 Clears all data inside and resets the widget. More...
 
void SetTheme (ColorTheme themeEnabled)
 Sets the theme of the widget. More...
 
void SetShowSubchart (bool showSubChart)
 Sets whether the subchart shall be shown. More...
 
void SetShowErrorBars (bool showErrorBars)
 Sets whether the error bars shall be shown. More...
 
void SetMinMaxValueXView (double minValueX, double maxValueX)
 Sets the min and max x values of the chart. More...
 
void SetMinMaxValueYView (double minValueY, double maxValueY)
 Sets the min and max y values of the chart. More...
 
void Reload ()
 Reloads the chart in the widget. More...
 
QSize sizeHint () const override
 
void SavePlotAsImage ()
 

Detailed Description

QmitkChartWidget is a widget to display various charts based on the javascript chart library plotly.

Data is added via AddData1D() or AddData2D().
There can be multiple charts (of different types with different properties) created by calling AddData1D or AddData2D multiple times.

The following chart types are supported:

  • line chart
  • bar chart
  • spline chart
  • pie chart
  • scatter chart
  • area chart
  • area spline chart.

Technical details: The javascript code is embedded in a QWebEngineView. The actual js code is implemented in resource\Chart.js.

See also
https://plot.ly/javascript/ for further information about the used javaScript library. /

Definition at line 40 of file QmitkChartWidget.h.

Member Enumeration Documentation

◆ AxisScale

Enumerator
linear 
log 

Definition at line 110 of file QmitkChartWidget.h.

◆ ChartColor

Enumerator
red 
orange 
yellow 
green 
blue 
purple 
brown 
magenta 
tan 
cyan 
olive 
maroon 
navy 
aquamarine 
turqouise 
silver 
lime 
teal 
indigo 
violet 
pink 
black 
white 
grey 

Definition at line 84 of file QmitkChartWidget.h.

◆ ChartType

enum of diagram types.

Enumerator
bar 

bar chart, see https://plot.ly/javascript/bar-charts/

line 

line chart, see https://plot.ly/javascript/line-charts/

spline 

spline chart (smoothed line chart), see https://plot.ly/~jduelfer/23/spline/#/

pie 

pie chart, see https://plot.ly/javascript/pie-charts/

area 

area chart, see https://plot.ly/javascript/filled-area-plots/

area_spline 

area-spline chart, similar to https://plot.ly/~jduelfer/23/spline/#/

scatter 

scatter chart, see https://plot.ly/javascript/line-and-scatter/

Definition at line 48 of file QmitkChartWidget.h.

◆ ColorTheme

enum of chart style (modifies background and line color).

Enumerator
darkstyle 

background color: dark gray, foreground color: white

lightstyle 

background color: white, foreground color: black

Definition at line 60 of file QmitkChartWidget.h.

◆ LegendPosition

enum of legend position. See https://plot.ly/javascript/legend/

Enumerator
bottomMiddle 
bottomRight 
topRight 
topLeft 
middleRight 

Definition at line 119 of file QmitkChartWidget.h.

◆ LineStyle

Enumerator
solid 
dashed 

Definition at line 64 of file QmitkChartWidget.h.

◆ MarkerSymbol

Enumerator
circle 
diamond 
cross 
square 
pentagon 
star 
diamond_tall 
star_diamond 
star_triangle_up 
star_triangle_down 
asterisk 
cross_thin 
x_thin 

Definition at line 68 of file QmitkChartWidget.h.

Constructor & Destructor Documentation

◆ QmitkChartWidget() [1/2]

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

◆ QmitkChartWidget() [2/2]

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

◆ ~QmitkChartWidget()

QmitkChartWidget::~QmitkChartWidget ( )
override

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 = 0 
)

◆ AddData1D()

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

Adds 1D data to the widget.

internally, the list is converted to a map with increasing integers keys starting at 0.

Parameters
data1D
labelthe name of the data that is also used as identifier.
chartTypethe chart type that should be used for this data entry
Note
the data can be cleared with ClearDiagram()
If the label name already exists, the name is replaced with a unique one by concatenating numbers to it.
Warning
Pie chart is significantly different than the other chart types. Here, the data given by AddData1D is summed. Each entry represents a different category.

◆ AddData2D()

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

Adds 2D data to the widget. Call repeatedly for displaying multiple charts.

each entry represents a data point: key: value --> x-value: y-value.

Parameters
data2D
labelthe name of the data that is also used as identifier.
chartTypethe chart type that should be used for this data entry
Note
the data can be cleared with ClearDiagram()
If the label name already exists, the name is replaced with a unique one by concatenating numbers to it.
Warning
Pie chart is significantly different than the other chart types. Here, the data given by AddData1D is summed. Each entry represents a different category.

◆ Clear()

void QmitkChartWidget::Clear ( )

Clears all data inside and resets the widget.

◆ GetDataElementByLabel()

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

◆ OnLoadFinished

void QmitkChartWidget::OnLoadFinished ( bool  isLoadSuccessful)
slot

◆ OnPageSuccessfullyLoaded

void QmitkChartWidget::OnPageSuccessfullyLoaded ( )
slot

◆ PageSuccessfullyLoaded

void QmitkChartWidget::PageSuccessfullyLoaded ( )
signal

◆ Reload()

void QmitkChartWidget::Reload ( )

Reloads the chart in the widget.

reloading may be needed to display added data in an existing chart

◆ RemoveData()

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

Removes data from the widget, works for 1D and 2D Data.

Parameters
labelthe name of the data that is also used as identifier.
Note
All data can be cleared with Clear()
Exceptions
InvalidArgument Exception when the label cannot be found

◆ SavePlotAsImage()

void QmitkChartWidget::SavePlotAsImage ( )

◆ SetChartType()

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

Sets the chart type for a data entry.

for available types, see ChartType

Note
If an unknown label is given, nothing happens.
Warning
Pie chart is significantly different than the other chart types. Here, the data given by AddData1D is summed. Each entry represents a different category.
See also
DiagramType for available types

◆ SetColor()

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

Sets the color of one data entry (identifier is previously assigned label)

the color name can be "red" or a hex number (#FF0000 ).

Warning
Either define all data entries with a color or no data entry. If a mixed approach is used, plotly choses the color of the data entry (that could be the same as a user defined color).
Note
If an unknown label is given, nothing happens.
See also
https://www.w3schools.com/cssref/css_colors.asp

◆ SetLegendPosition()

void QmitkChartWidget::SetLegendPosition ( LegendPosition  position)

Sets the legend position.

Default position is bottom.

See also
LegendPosition for available types

◆ SetLineStyle()

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

Sets the line style of one data entry (identifier is previously assigned label)

two line styles are possible: LineStyle::solid and LineStyle::dashed. The default line style is solid.

Note
If an unknown label is given, nothing happens.
Warning
only sets the line style if the current chart type is ChartType::line. However, the line style remains also if the chart changes (e.g. new chart type)

◆ SetMarkerSymbol()

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

Sets the marker style of one data entry (identifier is previously assigned label)

Note
If an unknown label is given, nothing happens.

◆ SetMinMaxValueXView()

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

Sets the min and max x values of the chart.

Zooms in to view the values between minValue and maxValue in x direction

◆ SetMinMaxValueYView()

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

Sets the min and max y values of the chart.

Zooms in to view the values between minValue and maxValue in y direction

◆ SetPieLabels()

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

Sets labels for pie chart data.

Note
in AddData1D, the label still has to be given that acts as a unique id. However, the label is omitted then.

◆ SetShowDataPoints()

void QmitkChartWidget::SetShowDataPoints ( bool  showDataPoints)

Either displays the dataPoints or not.

Parameters
showDataPointsif dataPoints are displayed inside the widget or not.

: example for not showing points: https://plot.ly/javascript/line-charts/#styling-line-plot example for showing the points: https://plot.ly/javascript/pointcloud/

◆ SetShowErrorBars()

void QmitkChartWidget::SetShowErrorBars ( bool  showErrorBars)

Sets whether the error bars shall be shown.

Changes the state of the current chart object.

Note
Needs to be reloaded with Reload() to display changes.
Parameters
showErrorBarsif error bars are displayed or not.

◆ SetShowLegend()

void QmitkChartWidget::SetShowLegend ( bool  show)

◆ SetShowSubchart()

void QmitkChartWidget::SetShowSubchart ( bool  showSubChart)

Sets whether the subchart shall be shown.

Changes the state of the current chart object.

Note
Needs to be reloaded with Reload() to display changes.

◆ SetStackedData()

void QmitkChartWidget::SetStackedData ( bool  stacked)

◆ SetTheme()

void QmitkChartWidget::SetTheme ( ColorTheme  themeEnabled)

Sets the theme of the widget.

default is dark theme as in MITK.

Warning
has to be called before Show() or Reload() to work

◆ SetTitle()

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

Sets a title for the chart.

◆ SetXAxisLabel()

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

◆ SetXErrorBars()

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

Sets error bars for data in x direction.

Note
If only error plus is provided, the error bars are symmetrical
Parameters
labelthe name of the data that is also used as identifier.
errorPlusthe error in positive direction
errorMinusthe error in negative direction. Same as error plus if omitted

◆ SetYAxisLabel()

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

◆ SetYAxisScale()

void QmitkChartWidget::SetYAxisScale ( AxisScale  scale)

Sets the axis scale to either linear (default) 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 >() 
)

Sets error bars for data in y direction.

for parameters, see SetXErrorBars

Note
If only error plus is provided, the error bars are symmetrical

◆ Show()

void QmitkChartWidget::Show ( bool  showSubChart = false)

Displays the chart in the widget.

Parameters
showSubChartif a subchart is displayed inside the widget or not.
Note
if no data has been provided, (
See also
AddData1D AddData2D), an empty chart is displayed.

◆ sizeHint()

QSize QmitkChartWidget::sizeHint ( ) const
override

◆ 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 = 0 
)

◆ UpdateData1D()

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

Updates data of an existing label.

Parameters
data1Dthe 1D data ,
See also
AddData1D
Parameters
labelthe (existing) label
Note
if the label does not exist, nothing happens

◆ UpdateData2D()

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

◆ UpdateLabel()

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

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