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

Function main

examples/Plotter/Simple/main.cpp:30–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28// #define PLOTTED_POINTS
29
30int main(int argc, char **argv)
31{
32 QApplication app(argc, argv);
33
34#if defined PLOTTED_POINTS
35 const int points = 60;
36#else
37 const int points = 1000;
38#endif
39 const qreal xMin = -2 * PI;
40 const qreal xMax = 2 * PI;
41 const qreal step = (xMax - xMin) / (points - 1);
42
43 QStandardItemModel model(points, 6);
44
45 double x = xMin;
46 for (int n = 0; n < points; ++n, x += step) {
47 QModelIndex index = model.index(n, 0);
48 model.setData(index, x);
49 index = model.index(n, 1);
50 model.setData(index, sin(x) * 100.0);
51
52 index = model.index(n, 2);
53 model.setData(index, x);
54 index = model.index(n, 3);
55 model.setData(index, x);
56
57 index = model.index(n, 4);
58 model.setData(index, x);
59 index = model.index(n, 5);
60 model.setData(index, x * x * x);
61 }
62
63 model.setHeaderData(0, Qt::Horizontal, QString::fromLatin1("100 * sin(x)"));
64 model.setHeaderData(2, Qt::Horizontal, QString::fromLatin1("x"));
65 model.setHeaderData(4, Qt::Horizontal, QString::fromLatin1("x^3"));
66
67 auto *chart = new KDChart::Chart();
68
69 KDChart::AbstractCartesianDiagram *diagram = new KDChart::Plotter;
70 diagram->setModel(&model);
71 chart->coordinatePlane()->replaceDiagram(diagram);
72
73#if defined PLOTTED_POINTS
74 diagram->setPen(QPen(Qt::NoPen));
75 const int colCount = model.columnCount(diagram->rootIndex());
76 for (int iColumn = 0; iColumn < colCount; ++iColumn) {
77 const QPen markerPen(diagram->brush(iColumn).color());
78 KDChart::DataValueAttributes dva(diagram->dataValueAttributes(iColumn));
79 KDChart::TextAttributes ta(dva.textAttributes());
80 KDChart::MarkerAttributes ma(dva.markerAttributes());
81 ma.setPen(markerPen);
82 ma.setMarkerStyle(KDChart::MarkerAttributes::MarkerCircle);
83 ma.setMarkerSize(QSize(3, 3));
84
85 dva.setVisible(true);
86 ta.setVisible(false);
87 ma.setVisible(true);

Callers

nothing calls this directly

Calls 15

setHeaderDataMethod · 0.80
dataValueAttributesMethod · 0.80
setMarkerStyleMethod · 0.80
QPenClass · 0.50
indexMethod · 0.45
setDataMethod · 0.45
setModelMethod · 0.45
replaceDiagramMethod · 0.45
coordinatePlaneMethod · 0.45
setPenMethod · 0.45
columnCountMethod · 0.45

Tested by

no test coverage detected