MCPcopy Create free account
hub / github.com/KDAB/KDChart / ChartWidget

Class ChartWidget

examples/Grids/CartesianGrid/main.cpp:27–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25using namespace KDChart;
26
27class ChartWidget : public QWidget
28{
29 Q_OBJECT
30public:
31 explicit ChartWidget(QWidget *parent = nullptr)
32 : QWidget(parent)
33 {
34 m_model.insertRows(0, 6, QModelIndex());
35 m_model.insertColumns(0, 4, QModelIndex());
36 for (int row = 0; row < 6; ++row) {
37 for (int column = 0; column < 4; ++column) {
38 QModelIndex index = m_model.index(row, column, QModelIndex());
39 m_model.setData(index, QVariant(row * 0.5 + column));
40 }
41 }
42
43 auto *diagram = new LineDiagram;
44 diagram->setModel(&m_model);
45
46 auto *xAxis = new CartesianAxis(diagram);
47 auto *yAxis = new CartesianAxis(diagram);
48 xAxis->setPosition(KDChart::CartesianAxis::Bottom);
49 yAxis->setPosition(KDChart::CartesianAxis::Left);
50 diagram->addAxis(xAxis);
51 diagram->addAxis(yAxis);
52
53 m_chart.coordinatePlane()->replaceDiagram(diagram);
54
55 /* Header */
56
57 // Add at one Header and set it up
58 auto *header = new HeaderFooter(&m_chart);
59 header->setPosition(Position::North);
60 header->setText("A Line Chart with Grid Configured");
61 m_chart.addHeaderFooter(header);
62
63 // Configure the Header text attributes
64 TextAttributes hta;
65 hta.setPen(QPen(Qt::red));
66
67 // let the header resize itself
68 // together with the widget.
69 // so-called relative size
70 Measure m(35.0);
71 m.setRelativeMode(header->autoReferenceArea(),
72 KDChartEnums::MeasureOrientationMinimum);
73 hta.setFontSize(m);
74 // min font size
75 m.setValue(3.0);
76 m.setCalculationMode(KDChartEnums::MeasureCalculationModeAbsolute);
77 hta.setMinimalFontSize(m);
78 header->setTextAttributes(hta);
79
80 // Configure the Header's Background
81 BackgroundAttributes hba;
82 hba.setBrush(Qt::white);
83 hba.setVisible(true);
84 header->setBackgroundAttributes(hba);

Callers

nothing calls this directly

Calls 15

QFontClass · 0.85
insertRowsMethod · 0.80
autoReferenceAreaMethod · 0.80
setFontSizeMethod · 0.80
setMinimalFontSizeMethod · 0.80
setPaddingMethod · 0.80
setSubGridPenMethod · 0.80
setZeroLinePenMethod · 0.80
setGridStepWidthMethod · 0.80
setGridSubStepWidthMethod · 0.80
setSubGridVisibleMethod · 0.80
dataValueAttributesMethod · 0.80

Tested by

no test coverage detected