Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
QmitkChartWidget.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 #ifndef QmitkChartWidget_h
13 #define QmitkChartWidget_h
14 
15 #include <map>
16 #include <memory>
17 #include <QWidget>
18 
19 #include <MitkChartExports.h>
20 
21 class QmitkChartxyData;
22 
50 class MITKCHART_EXPORT QmitkChartWidget : public QWidget
51 {
52  Q_OBJECT
53 
54 public:
58  enum class ChartType {
59  bar,
60  line,
61  spline,
62  pie,
63  area,
64  area_spline,
65  scatter
66  };
67 
71  enum class ColorTheme {
72  darkstyle,
73  lightstyle
74  };
75 
79  enum class LineStyle {
80  solid,
81  dashed
82  };
83 
87  enum class MarkerSymbol {
88  circle,
89  diamond,
90  cross,
91  square,
92  pentagon,
93  star,
94  x,
95  diamond_tall,
96  star_diamond,
97  star_triangle_up,
98  star_triangle_down,
99  asterisk,
100  cross_thin,
101  x_thin
102  };
103 
107  enum class ChartColor {
108  red,
109  orange,
110  yellow,
111  green,
112  blue,
113  purple,
114  brown,
115  magenta,
116  tan,
117  cyan,
118  olive,
119  maroon,
120  navy,
121  aquamarine,
122  turqouise,
123  silver,
124  lime,
125  teal,
126  indigo,
127  violet,
128  pink,
129  black,
130  white,
131  grey
132  };
133 
137  enum class AxisScale {
138  linear,
139  log
140  };
141 
146  enum class LegendPosition {
147  bottomMiddle,
148  bottomRight,
149  topRight,
150  topLeft,
151  middleRight
152  };
153 
158  explicit QmitkChartWidget(QWidget* parent = nullptr);
159 
165  explicit QmitkChartWidget(QWidget *parent, bool unitTest);
166 
168  ~QmitkChartWidget() override;
169 
183  void AddData1D(const std::vector<double>& data1D, const std::string& label, ChartType chartType = ChartType::bar);
184 
195  void UpdateData1D(const std::vector<double> &data1D, const std::string &label);
196 
208  void UpdateData2D(const std::vector< std::pair<double, double> > &data2D, const std::string &label);
209 
220  void UpdateChartExampleData(const std::vector< std::pair<double, double> >& data2D,
221  const std::string& label,
222  const std::string& type,
223  const std::string& color,
224  const std::string& lineStyle,
225  const std::string& pieLabelsData = {});
226 
240  void AddData2D(const std::vector< std::pair<double, double> > &data2D,
241  const std::string &label,
242  ChartType chartType = ChartType::bar);
243 
257  void AddChartExampleData(const std::vector< std::pair<double, double> >& data2D,
258  const std::string& label,
259  const std::string& type,
260  const std::string& color,
261  const std::string& style,
262  const std::string& pieLabelsData = {});
263 
275  void RemoveData(const std::string& label);
276 
283  void UpdateLabel(const std::string& existingLabel, const std::string& newLabel);
284 
291  QmitkChartxyData *GetDataElementByLabel(const std::string& label) const;
292 
305  void SetColor(const std::string& label, const std::string& colorName);
306 
317  void SetLineStyle(const std::string& label, LineStyle style);
318 
327  void SetMarkerSymbol(const std::string &label, MarkerSymbol symbol);
328 
337 
342  void SetXAxisLabel(const std::string& label);
343 
348  void SetYAxisLabel(const std::string& label);
349 
358  void SetPieLabels(const std::vector<std::string> &pieLabels, const std::string &label);
359 
364  void SetTitle(const std::string &title);
365 
377  void SetChartType(const std::string& label, ChartType type);
378 
387  void SetXErrorBars(const std::string &label, const std::vector<double> &errorPlus, const std::vector<double>& errorMinus = std::vector<double>());
388 
399  void SetYErrorBars(const std::string &label, const std::vector<double> &errorPlus, const std::vector<double> &errorMinus = std::vector<double>());
400 
409 
414  void SetShowLegend(bool show);
415 
420  void SetStackedData(bool stacked);
421 
432  void Show(bool showSubChart=false);
433 
442  void SetShowDataPoints(bool showDataPoints);
443 
447  void Clear();
448 
456  void SetTheme(ColorTheme themeEnabled);
457 
465  void SetShowSubchart(bool showSubChart);
466 
474  void SetShowErrorBars(bool showErrorBars);
475 
482  void SetMinMaxValueXView(double minValueX,double maxValueX);
483 
490  void SetMinMaxValueYView(double minValueY, double maxValueY);
491 
498  void Reload();
499 
504  QSize sizeHint() const override;
505 
513 
514 public slots:
519  void OnLoadFinished(bool isLoadSuccessful);
520 
525 
526 signals:
531 
532 private:
534  std::string convertBooleanValue(bool value) const;
535 
536  class Impl;
537  std::unique_ptr<Impl> m_Impl;
538 };
539 
540 #endif
#define MITKCHART_EXPORT
Qt widget for displaying interactive charts based on the plotly.js library.
void SetYAxisScale(AxisScale scale)
Set the Y axis scale type.
AxisScale
Enumeration of axis scale types.
MarkerSymbol
Enumeration of data point marker symbols.
void SetStackedData(bool stacked)
Set whether data series are displayed in stacked mode.
~QmitkChartWidget() override
Destructor.
void SetShowDataPoints(bool showDataPoints)
Set whether data point markers are visible.
ColorTheme
Enumeration of chart color themes.
LegendPosition
Enumeration of legend positions within the chart.
QmitkChartWidget(QWidget *parent=nullptr)
Construct a chart widget.
ChartColor
Enumeration of named chart colors.
void SetPieLabels(const std::vector< std::string > &pieLabels, const std::string &label)
Set category labels for pie chart segments.
QSize sizeHint() const override
Return the recommended size for the widget.
void Clear()
Clear all data series and reset the widget.
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.
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.
void SetTitle(const std::string &title)
Set the chart title.
void SetMinMaxValueYView(double minValueY, double maxValueY)
Set the visible Y axis range (zoom).
void SetChartType(const std::string &label, ChartType type)
Change the chart type of an existing data series.
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.
void SetXAxisLabel(const std::string &label)
Set the X axis label text.
void PageSuccessfullyLoaded()
Emitted when the chart page has been successfully loaded and is ready for use.
QmitkChartWidget(QWidget *parent, bool unitTest)
Construct a chart widget for unit testing.
void Show(bool showSubChart=false)
Render and display the chart in the widget.
void UpdateData2D(const std::vector< std::pair< double, double > > &data2D, const std::string &label)
Update the data of an existing 2D data series.
void SetTheme(ColorTheme themeEnabled)
Set the chart color theme.
void SetShowErrorBars(bool showErrorBars)
Set whether error bars are shown.
QmitkChartxyData * GetDataElementByLabel(const std::string &label) const
Retrieve the data element for a given label.
void Reload()
Reload the chart to reflect property or data changes.
void SetShowLegend(bool show)
Set whether the chart legend is visible.
void SetShowSubchart(bool showSubChart)
Set whether the subchart (overview navigator) is shown.
void SetYAxisLabel(const std::string &label)
Set the Y axis label text.
void SetMarkerSymbol(const std::string &label, MarkerSymbol symbol)
Set the marker symbol for a data series.
void SetMinMaxValueXView(double minValueX, double maxValueX)
Set the visible X axis range (zoom).
void SetLineStyle(const std::string &label, LineStyle style)
Set the line style of a data series.
void SavePlotAsImage()
Save the current chart as an SVG image file.
void UpdateData1D(const std::vector< double > &data1D, const std::string &label)
Update the data of an existing 1D data series.
void RemoveData(const std::string &label)
Remove a data series from the chart.
void OnLoadFinished(bool isLoadSuccessful)
Slot called when the web page finishes loading.
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.
void AddData1D(const std::vector< double > &data1D, const std::string &label, ChartType chartType=ChartType::bar)
Add a 1D data series to the chart.
void SetColor(const std::string &label, const std::string &colorName)
Set the color of a data series.
LineStyle
Enumeration of line drawing styles.
void UpdateLabel(const std::string &existingLabel, const std::string &newLabel)
Rename an existing data series.
void OnPageSuccessfullyLoaded()
Slot called when the chart page has been successfully loaded and is ready.
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.
void SetLegendPosition(LegendPosition position)
Set the legend position.
ChartType
Enumeration of supported chart types.
Holds data for chart generation via C3/Plotly.