/
README.mv
58 lines (43 loc) · 1.79 KB
/
README.mv
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
# Simple, tiny & cute.js
A charting library for JavaScript.
_Please visit [http://josip.github.com/stc](http://josip.github.com/stc) for more details._
## Usage
To use STC, just initialise the class and call the `plot` method once you get a hold on the data.
var chart = new STC(canvasElement.getContext('2d'), {
w: width,
h: height
});
The data should be an array consisting of X and Y coordinates and an optional label (currently only shown when `point` chart is in use).
chart.plot([
[0, 0, '0'],
[0, 1, '1'],
[1, 0, '2'],
[1, 1, '3']
], {
type: 'area'
});
### Options
Class constructor takes the following options:
* `w`: width of the canvas element (required)
* `h`: height of the element (required)
* `padding`: padding from all the sides (defaults to 20)
* `axes` | `grid` | `background`: canvas gradient or a colour in which the axes/grid/background should be drawn. `false` if you don't want them.
### Using with QML
STC was primarily built for [qmlcanvas](http://qt.gitorious.org/qt-labs/qmlcanvas) and use on mobile phones. Using it with QML should be as simple as with HTML.
import "stc.qml.js" as STC
Canvas {
id: canvas
onPaint: {
var c = new STC.STC(getContext(), {
w: width,
h: height
});
fetchDataFromSQLiteDB(function (data) {
c.plot(d, {axes: false})
});
}
}
To enable interactivity on the graph, you can create a `MouseArea` over the canvas and combine two helper methods:
* `closestPtX([x, y])`: returns the point closes to the given (absolute) coordinates
* `ptToCoords([x, y])`: returns absolute coordinates (for use with QML) of the given point (relative)
Please note that saving the `STC` object into a QML property will not work because QML destroys object's prototype chain.