forked from fargies/qchart.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
QChart.qml
108 lines (88 loc) · 2.9 KB
/
QChart.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* QChart.qml ---
*
* Author: Julien Wintz
* Created: Thu Feb 13 20:59:40 2014 (+0100)
* Version:
* Last-Updated: jeu. mars 6 12:55:14 2014 (+0100)
* By: Julien Wintz
* Update #: 69
*/
/* Change Log:
*
*/
import QtQuick 2.0
import "QChart.js" as Charts
Canvas {
id: canvas;
// ///////////////////////////////////////////////////////////////
property var chart;
property var chartData;
property int chartType: 0;
property bool chartAnimated: true;
property alias chartAnimationEasing: chartAnimator.easing.type;
property alias chartAnimationDuration: chartAnimator.duration;
property int chartAnimationProgress: 0;
property var chartOptions: ({})
// /////////////////////////////////////////////////////////////////
// Callbacks
// /////////////////////////////////////////////////////////////////
onPaint: {
if(!chart) {
switch(chartType) {
case Charts.ChartType.BAR:
chart = new Charts.Chart(canvas, canvas.getContext("2d")).Bar(chartData, chartOptions);
break;
case Charts.ChartType.DOUGHNUT:
chart = new Charts.Chart(canvas, canvas.getContext("2d")).Doughnut(chartData, chartOptions);
break;
case Charts.ChartType.LINE:
chart = new Charts.Chart(canvas, canvas.getContext("2d")).Line(chartData, chartOptions);
break;
case Charts.ChartType.PIE:
chart = new Charts.Chart(canvas, canvas.getContext("2d")).Pie(chartData, chartOptions);
break;
case Charts.ChartType.POLAR:
chart = new Charts.Chart(canvas, canvas.getContext("2d")).PolarArea(chartData, chartOptions);
break;
case Charts.ChartType.RADAR:
chart = new Charts.Chart(canvas, canvas.getContext("2d")).Radar(chartData, chartOptions);
break;
default:
console.log('Chart type should be specified.');
}
chart.init();
if (chartAnimated)
chartAnimator.start();
else
chartAnimationProgress = 100;
}
chart.draw(chartAnimationProgress/100);
}
onHeightChanged: {
requestPaint();
}
onWidthChanged: {
requestPaint();
}
onChartAnimationProgressChanged: {
requestPaint();
}
// /////////////////////////////////////////////////////////////////
// Functions
// /////////////////////////////////////////////////////////////////
function repaint() {
chartAnimationProgress = 0;
chartAnimator.start();
}
// /////////////////////////////////////////////////////////////////
// Internals
// /////////////////////////////////////////////////////////////////
PropertyAnimation {
id: chartAnimator;
target: canvas;
property: "chartAnimationProgress";
to: 100;
duration: 500;
easing.type: Easing.InOutElastic;
}
}