##// END OF EJS Templates
change function example in xylinechart example
Michal Klocek -
r14:a2a9320d5819
parent child
Show More
@@ -1,57 +1,57
1 #include <QApplication>
1 #include <QApplication>
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <qchartwidget.h>
3 #include <qchartwidget.h>
4 #include <qchart.h>
4 #include <qchart.h>
5 #include "chartview.h"
5 #include "chartview.h"
6 #include <cmath>
6 #include <cmath>
7
7
8 QCHART_USE_NAMESPACE
8 QCHART_USE_NAMESPACE
9
9
10 #define PI 3.14159265358979
10 #define PI 3.14159265358979
11
11
12 int main(int argc, char *argv[])
12 int main(int argc, char *argv[])
13 {
13 {
14 QApplication a(argc, argv);
14 QApplication a(argc, argv);
15
15
16 QMainWindow window;
16 QMainWindow window;
17
17
18 QXYSeries* series0 = new QXYSeries();
18 QXYSeries* series0 = new QXYSeries();
19 series0->setColor(Qt::blue);
19 series0->setColor(Qt::blue);
20 QXYSeries* series1 = new QXYSeries();
20 QXYSeries* series1 = new QXYSeries();
21 series1->setColor(Qt::red);
21 series1->setColor(Qt::red);
22 QXYSeries* series2 = new QXYSeries();
22 QXYSeries* series2 = new QXYSeries();
23 series2->setColor(Qt::gray);
23 series2->setColor(Qt::gray);
24 QXYSeries* series3 = new QXYSeries();
24 QXYSeries* series3 = new QXYSeries();
25 series3->setColor(Qt::green);
25 series3->setColor(Qt::green);
26
26
27 int numPoints = 100;
27 int numPoints = 100;
28
28
29 for (int x = 0; x < numPoints; ++x) {
29 for (int x = 0; x < numPoints; ++x) {
30 series0->add(x,0);
30 series0->add(x,0);
31 series1->add(x, uint(sin(PI/25*x)*100) % 100);
31 series1->add(x, abs(sin(PI/50*x)*100));
32 series2->add(x, uint(cos(PI/25*x)*100) % 100);
32 series2->add(x, abs(cos(PI/50*x)*100));
33 series3->add(x,100);
33 series3->add(x,100);
34 }
34 }
35
35
36 QList<QXYSeries*> dataset;
36 QList<QXYSeries*> dataset;
37
37
38 qDebug()<<"Series 1:" << *series1;
38 qDebug()<<"Series 1:" << *series1;
39 qDebug()<<"Series 2:" << *series2;
39 qDebug()<<"Series 2:" << *series2;
40
40
41 dataset << series0;
41 dataset << series0;
42 dataset << series1;
42 dataset << series1;
43 dataset << series2;
43 dataset << series2;
44 dataset << series3;
44 dataset << series3;
45
45
46 QChart* chart = QChart::createXYLineChart(dataset);
46 QChart* chart = QChart::createXYLineChart(dataset);
47 chart->setMargin(50);
47 chart->setMargin(50);
48 QChartWidget* chartWidget = new QChartWidget();
48 QChartWidget* chartWidget = new QChartWidget();
49 chartWidget->addChart(chart);
49 chartWidget->addChart(chart);
50
50
51 ChartView* view = new ChartView(chartWidget,&window);
51 ChartView* view = new ChartView(chartWidget,&window);
52 window.setCentralWidget(view);
52 window.setCentralWidget(view);
53 window.resize(400, 300);
53 window.resize(400, 300);
54 window.show();
54 window.show();
55
55
56 return a.exec();
56 return a.exec();
57 }
57 }
General Comments 0
You need to be logged in to leave comments. Login now