@@ -0,0 +1,5 | |||
|
1 | !include( ../examples.pri ) { | |
|
2 | error( "Couldn't find the examples.pri file!" ) | |
|
3 | } | |
|
4 | TARGET = datetimeaxis | |
|
5 | SOURCES += main.cpp |
@@ -0,0 +1,82 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | #include <QApplication> | |
|
22 | #include <QMainWindow> | |
|
23 | #include <QChartView> | |
|
24 | #include <QLineSeries> | |
|
25 | #include <QDateTime> | |
|
26 | #include <QDateTimeAxis> | |
|
27 | ||
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
|
29 | ||
|
30 | int main(int argc, char *argv[]) | |
|
31 | { | |
|
32 | QApplication a(argc, argv); | |
|
33 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
|
34 | ||
|
35 | //![1] | |
|
36 | QLineSeries* series = new QLineSeries(); | |
|
37 | //![1] | |
|
38 | ||
|
39 | //![2] | |
|
40 | QDateTime momentInTime; | |
|
41 | for (int i = 0; i < 100; i++) { | |
|
42 | momentInTime.setDate(QDate(2012, 1 , (1 + i / 9) % 28)); | |
|
43 | momentInTime.setTime(QTime(9 + i % 9, 0)); | |
|
44 | if (i > 0) | |
|
45 | series->append(momentInTime.toMSecsSinceEpoch(), series->points().at(i - 1).y() * (0.95 + (qrand() % 11) / 100.0)); | |
|
46 | else | |
|
47 | series->append(momentInTime.toMSecsSinceEpoch(), 45); | |
|
48 | } | |
|
49 | //![2] | |
|
50 | ||
|
51 | //![3] | |
|
52 | QChart* chart = new QChart(); | |
|
53 | chart->legend()->hide(); | |
|
54 | chart->addSeries(series); | |
|
55 | chart->createDefaultAxes(); | |
|
56 | QDateTimeAxis *axisX = new QDateTimeAxis; | |
|
57 | axisX->setTicksCount(20); | |
|
58 | momentInTime.setDate(QDate(2012,1,1)); | |
|
59 | momentInTime.setTime(QTime(6, 0)); | |
|
60 | axisX->setMin(momentInTime); | |
|
61 | momentInTime.setDate(QDate(2012,1,7)); | |
|
62 | momentInTime.setTime(QTime(18, 0)); | |
|
63 | axisX->setMax(momentInTime); | |
|
64 | chart->setAxisX(axisX, series); | |
|
65 | chart->setTitle("Date and Time axis chart example"); | |
|
66 | //![3] | |
|
67 | ||
|
68 | //![4] | |
|
69 | QChartView* chartView = new QChartView(chart); | |
|
70 | chartView->setRenderHint(QPainter::Antialiasing); | |
|
71 | //![4] | |
|
72 | ||
|
73 | ||
|
74 | //![5] | |
|
75 | QMainWindow window; | |
|
76 | window.setCentralWidget(chartView); | |
|
77 | window.resize(800, 600); | |
|
78 | window.show(); | |
|
79 | //![5] | |
|
80 | ||
|
81 | return a.exec(); | |
|
82 | } |
@@ -29,4 +29,5 SUBDIRS += \ | |||
|
29 | 29 | horizontalpercentbarchart \ |
|
30 | 30 | donut \ |
|
31 | 31 | donutdrilldown \ |
|
32 | scrollchart | |
|
32 | scrollchart \ | |
|
33 | datetimeaxis |
@@ -255,7 +255,7 QDateTimeAxisPrivate::QDateTimeAxisPrivate(QDateTimeAxis* q): | |||
|
255 | 255 | { |
|
256 | 256 | m_min = QDateTime::fromMSecsSinceEpoch(0); |
|
257 | 257 | m_max = QDateTime::fromMSecsSinceEpoch(0); |
|
258 |
m_format = " |
|
|
258 | m_format = "dd-MMM-yy\nh:mm"; | |
|
259 | 259 | } |
|
260 | 260 | |
|
261 | 261 | QDateTimeAxisPrivate::~QDateTimeAxisPrivate() |
General Comments 0
You need to be logged in to leave comments.
Login now