##// END OF EJS Templates
Logvalueaxis and multiaxis examples updated
Marek Rosa -
r2371:64c51f3e619b
parent child
Show More
@@ -1,73 +1,74
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include <QApplication>
21 #include <QApplication>
22 #include <QMainWindow>
22 #include <QMainWindow>
23 #include <QChartView>
23 #include <QChartView>
24 #include <QLineSeries>
24 #include <QLineSeries>
25 #include <QValueAxis>
25 #include <QValueAxis>
26 #include <QLogValueAxis>
26 #include <QLogValueAxis>
27
27
28 QTCOMMERCIALCHART_USE_NAMESPACE
28 QTCOMMERCIALCHART_USE_NAMESPACE
29
29
30 int main(int argc, char *argv[])
30 int main(int argc, char *argv[])
31 {
31 {
32 QApplication a(argc, argv);
32 QApplication a(argc, argv);
33
33
34 //![1]
34 //![1]
35 QLineSeries *series = new QLineSeries();
35 QLineSeries *series = new QLineSeries();
36 *series << QPointF(1, 7) << QPointF(2, 73) << QPointF(3, 268) << QPointF(4, 17) << QPointF(5, 4325) << QPointF(6, 723);
36 *series << QPointF(1, 1) << QPointF(2, 73) << QPointF(3, 268) << QPointF(4, 17) << QPointF(5, 4325) << QPointF(6, 723);
37 //![1]
37 //![1]
38
38
39 //![3]
39 //![3]
40 QChart *chart = new QChart();
40 QChart *chart = new QChart();
41 chart->addSeries(series);
41 chart->addSeries(series);
42 chart->legend()->hide();
42 chart->legend()->hide();
43 chart->setTitle("QLogValueAxis chart example");
43 //![3]
44 //![3]
44
45
45 //![4]
46 //![4]
46 QValueAxis *axisX = new QValueAxis;
47 QValueAxis *axisX = new QValueAxis;
47 axisX->setTitleText("Data point");
48 axisX->setTitleText("Data point");
48 axisX->setTickCount(6);
49 axisX->setTickCount(6);
49 axisX->setLabelFormat("%i");
50 axisX->setLabelFormat("%i");
50 chart->addAxis(axisX, Qt::AlignBottom);
51 chart->addAxis(axisX, Qt::AlignBottom);
51 series->attachAxis(axisX);
52 series->attachAxis(axisX);
52
53
53 QLogValueAxis *axisY = new QLogValueAxis;
54 QLogValueAxis *axisY = new QLogValueAxis;
54 axisY->setBase(2);
55 axisY->setLabelFormat("%g");
55 axisY->setTitleText("Values");
56 axisY->setTitleText("Values");
56 chart->addAxis(axisY, Qt::AlignLeft);
57 chart->addAxis(axisY, Qt::AlignLeft);
57 series->attachAxis(axisY);
58 series->attachAxis(axisY);
58 //![4]
59 //![4]
59
60
60 //![5]
61 //![5]
61 QChartView *chartView = new QChartView(chart);
62 QChartView *chartView = new QChartView(chart);
62 chartView->setRenderHint(QPainter::Antialiasing);
63 chartView->setRenderHint(QPainter::Antialiasing);
63 //![5]
64 //![5]
64
65
65 //![6]
66 //![6]
66 QMainWindow window;
67 QMainWindow window;
67 window.setCentralWidget(chartView);
68 window.setCentralWidget(chartView);
68 window.resize(800, 600);
69 window.resize(400, 300);
69 window.show();
70 window.show();
70 //![6]
71 //![6]
71
72
72 return a.exec();
73 return a.exec();
73 }
74 }
@@ -1,83 +1,90
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include <QApplication>
21 #include <QApplication>
22 #include <QMainWindow>
22 #include <QMainWindow>
23 #include <QChartView>
23 #include <QChartView>
24 #include <QLineSeries>
24 #include <QLineSeries>
25 #include <QSplineSeries>
25 #include <QValueAxis>
26 #include <QValueAxis>
26 #include <QTime>
27 #include <QCategoryAxis>
27 #include <QValueAxis>
28
28
29 QTCOMMERCIALCHART_USE_NAMESPACE
29 QTCOMMERCIALCHART_USE_NAMESPACE
30
30
31 int main(int argc, char *argv[])
31 int main(int argc, char *argv[])
32 {
32 {
33 QApplication a(argc, argv);
33 QApplication a(argc, argv);
34
34
35 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
36
37 //![1]
35 //![1]
38 QLineSeries *series;
39 QValueAxis *axisX;
40 QValueAxis *axisY;
41 QChart *chart = new QChart();
36 QChart *chart = new QChart();
42 for (int i = 0; i < 5; i++) {
37 QValueAxis *axisX = new QValueAxis;
43 series = new QLineSeries;
38 axisX->setTickCount(10);
44 for (int k(0); k < 8; k++)
39
45 series->append(i + k, qrand() % 20);
40 QSplineSeries *series = new QSplineSeries;
46 chart->addSeries(series);
41 *series << QPointF(1, 5) << QPointF(3.5, 18) << QPointF(4.8, 7.5) << QPointF(10, 2.5);
47
42 chart->addSeries(series);
48 axisX = new QValueAxis;
43
49 axisX->setTickCount(7 + i);
44 QValueAxis *axisY = new QValueAxis;
50 axisX->setLinePenColor(series->pen().color());
45 axisY->setLinePenColor(series->pen().color());
51
46
52 axisY = new QValueAxis;
47 chart->addAxis(axisX, Qt::AlignBottom);
53 axisY->setTickCount(7 + i);
48 chart->addAxis(axisY, Qt::AlignLeft);
54 axisY->setLinePenColor(series->pen().color());
49 series->attachAxis(axisX);
55
50 series->attachAxis(axisY);
56 chart->addAxis(axisX,i % 2?Qt::AlignTop:Qt::AlignBottom);
51
57 chart->addAxis(axisY,i % 2?Qt::AlignRight:Qt::AlignLeft);
52 series = new QSplineSeries;
58 series->attachAxis(axisX);
53 *series << QPointF(1, 0.5) << QPointF(1.5, 4.5) << QPointF(2.4, 2.5) << QPointF(4.3, 12.5)
59 series->attachAxis(axisY);
54 << QPointF(5.2, 3.5) << QPointF(7.4, 16.5) << QPointF(8.3, 7.5) << QPointF(10, 17);
60 }
55 chart->addSeries(series);
56
57 QCategoryAxis *axisY3 = new QCategoryAxis;
58 axisY3->append("Low", 5);
59 axisY3->append("Medium", 12);
60 axisY3->append("High", 17);
61 axisY3->setLinePenColor(series->pen().color());
62 axisY3->setGridLinePen((series->pen()));
63
64 chart->addAxis(axisY3, Qt::AlignRight);
65 series->attachAxis(axisX);
66 series->attachAxis(axisY3);
67
61 //![2]
68 //![2]
62
69
63 //![3]
70 //![3]
64 chart->legend()->hide();
71 chart->legend()->hide();
65
72 chart->setTitle("Multiaxis chart example");
66 chart->setTitle("Simple line chart example");
67 //![3]
73 //![3]
68
74
69 //![4]
75 //![4]
70 QChartView *chartView = new QChartView(chart);
76 QChartView *chartView = new QChartView(chart);
71 chartView->setRenderHint(QPainter::Antialiasing);
77 chartView->setRenderHint(QPainter::Antialiasing);
72 //![4]
78 //![4]
73
79
74
80
75 //![5]
81 //![5]
76 QMainWindow window;
82 QMainWindow window;
77 window.setCentralWidget(chartView);
83 window.setCentralWidget(chartView);
78 window.resize(800, 600);
84 window.resize(800, 600);
79 window.show();
85 window.show();
80 //![5]
86 //![5]
81
87
82 return a.exec();
88 return a.exec();
83 }
89 }
90
General Comments 0
You need to be logged in to leave comments. Login now