##// END OF EJS Templates
More examples on QChartView qdoc
Tero Ahola -
r321:13ac9d78995f
parent child
Show More
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -3,6 +3,11
3 #include <qchartglobal.h>
3 #include <qchartglobal.h>
4 #include <qchartview.h>
4 #include <qchartview.h>
5 #include <qlinechartseries.h>
5 #include <qlinechartseries.h>
6 #include <qscatterseries.h>
7 #include <qbarchartseries.h>
8 #include <qbarset.h>
9 #include <qbarcategory.h>
10 #include <qpieseries.h>
6
11
7 QTCOMMERCIALCHART_USE_NAMESPACE
12 QTCOMMERCIALCHART_USE_NAMESPACE
8
13
@@ -13,26 +18,54 int main(int argc, char *argv[])
13 //! [1]
18 //! [1]
14 // Create chart view
19 // Create chart view
15 QChartView *chartView = new QChartView();
20 QChartView *chartView = new QChartView();
16 chartView->setChartTheme(QChart::ChartThemeIcy);
21 // Add series to the chart
22 QLineChartSeries *line = new QLineChartSeries();
23 line->add(0.0, 0.8);
24 line->add(1.1, 1.1);
25 line->add(2.0, 2.5);
26 chartView->addSeries(line);
17 //! [1]
27 //! [1]
18
28
19 //! [2]
29 //! [2]
20 // Add series to the chart
30 // Change theme
21 QLineChartSeries *series = new QLineChartSeries();
31 chartView->setChartTheme(QChart::ChartThemeScientific);
22 series->add(0.0, 0.8);
23 series->add(1.1, 1.1);
24 series->add(1.6, 1.8);
25 series->add(2.0, 2.5);
26 chartView->addSeries(series);
27 //! [2]
32 //! [2]
28
33
29 //! [3]
34 //! [3]
30 // Change theme
35 // Add pie series
31 chartView->setChartTheme(QChart::ChartThemeScientific);
36 QPieSeries *pie = new QPieSeries();
37 pie->add(3.4, "slice1");
38 pie->add(6.7, "slice2");
39 chartView->addSeries(pie);
32 //! [3]
40 //! [3]
33
41
42 //! [4]
43 // Add scatter series
44 QScatterSeries *scatter = new QScatterSeries();
45 for (qreal x(0); x < 100; x += 0.5) {
46 qreal y = rand() % 100;
47 *(scatter) << QPointF(x, y);
48 }
49 chartView->addSeries(scatter);
50 //! [4]
51
52 //! [5]
53 // Add bar series
54 QBarCategory *barCategory = new QBarCategory();
55 *barCategory << "Jan"
56 << "Feb"
57 << "Mar";
58 QBarChartSeries *bar = new QBarChartSeries(barCategory);
59 QBarSet *barSet = new QBarSet("Sales");
60 *barSet << 123.2
61 << 301.3
62 << 285.8;
63 bar->addBarSet(barSet);
64 chartView->addSeries(bar);
65 //! [5]
66
34 QMainWindow w;
67 QMainWindow w;
35 w.resize(640, 480);
68 w.resize(350, 250);
36 w.setCentralWidget(chartView);
69 w.setCentralWidget(chartView);
37 w.show();
70 w.show();
38
71
@@ -57,7 +57,7 ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme)
57 {
57 {
58 switch(theme) {
58 switch(theme) {
59 case QChart::ChartThemeDefault:
59 case QChart::ChartThemeDefault:
60 return new ChartTheme();
60 return new ChartThemeIcy();
61 case QChart::ChartThemeVanilla:
61 case QChart::ChartThemeVanilla:
62 return new ChartThemeVanilla();
62 return new ChartThemeVanilla();
63 case QChart::ChartThemeIcy:
63 case QChart::ChartThemeIcy:
@@ -22,20 +22,30
22 \class QChartView
22 \class QChartView
23 \brief Standalone charting widget.
23 \brief Standalone charting widget.
24
24
25 QChartView is a standalone widget that can display charts. It does not require separate QGraphicsScene to work. It manages the graphical
25 QChartView is a standalone widget that can display charts. It does not require separate
26 representation of different types of QChartSeries and other chart related objects like
26 QGraphicsScene to work. It manages the graphical representation of different types of
27 QChartAxis and QChartLegend. If you want to display a chart in your existing QGraphicsScene, you can use the QChart class instead.
27 QChartSeries and other chart related objects like QChartAxis and QChartLegend. If you want to
28 display a chart in your existing QGraphicsScene, you can use the QChart class instead.
28
29
29 For example, to create an empty chart in a widget based application:
30 For example, to create a chart with line series using a widget based application:
30 \snippet ../example/chartview/main.cpp 1
31 \snippet ../example/chartview/main.cpp 1
31 \image chartview_example.jpg
32 \image chartview_example.jpg
32
33
33 To add a line series:
34 Showing a few more series:
34 \snippet ../example/chartview/main.cpp 2
35 \image chartview_example_series.jpg
36
37 To modify the visual appearance of the chart, you can use the pre-defined themes:
38 \snippet ../example/chartview/main.cpp 3
35 \snippet ../example/chartview/main.cpp 3
36 \codeline
37 \snippet ../example/chartview/main.cpp 4
38 \codeline
39 \snippet ../example/chartview/main.cpp 5
40
41 And the corresponding results:
42 \image chartview_example_pie.jpg
43 \image chartview_example_scatter.jpg
44 \image chartview_example_bar.jpg
45
46 If you need to give a more professional touch to your chart you can switch to one of the
47 pre-defined themes:
48 \snippet ../example/chartview/main.cpp 2
39 \image chartview_example_theme.jpg
49 \image chartview_example_theme.jpg
40
50
41 \sa QChart
51 \sa QChart
1 NO CONTENT: file was removed, binary diff hidden
NO CONTENT: file was removed, binary diff hidden
General Comments 0
You need to be logged in to leave comments. Login now