Skip to content
This repository was archived by the owner on Mar 30, 2024. It is now read-only.

Commit 6f965d6

Browse files
committed
Custom Graphs
1 parent e2816ff commit 6f965d6

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

README.md

+32-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
- Show charts made with ChartJS
1010
- Account Management
1111
- Each user gets an account, also called group
12-
- This account can have
12+
- This account can have multiple devices
1313
- Device Management
14+
- Add, edit and delete devices
1415

1516
## Install on server
1617
This is a docker project, so it you will need docker to run it.
@@ -67,4 +68,33 @@ One may use any device of an account.
6768
2. Fill in `Server URL, Account Name, Device Name, Device Token` between `APIClient( ... );` as stated in the file
6869
3. One may change the `$destPath`, it has to be any empty directory (or it will be created).
6970
4. Run `php ./imexport/export.php`
70-
5. The data for all devices will show up in `$destPath`
71+
5. The data for all devices will show up in `$destPath`
72+
73+
## Custom Graphs
74+
It is possible to create custom graph-views for the stats view.
75+
76+
### Create your own stats function
77+
> See an example e.g. [PieCategory](https://github.com/KIMB-technologies/TaskTimeTerminateServer/blob/master/php/load/graphs/PieCategory.js)
78+
79+
When the user selects a graph and clicks on *Display Graph* the corresponding JS-file is loaded and the the function `createGraph(data, canvas)`
80+
of this file will be executed. In a file like [PieCategory](https://github.com/KIMB-technologies/TaskTimeTerminateServer/blob/master/php/load/graphs/PieCategory.js)
81+
such function like `createGraph(data, canvas)` can be defined.
82+
83+
Each function gets two parameters `data` which is an array containing objects with datasets.
84+
The object `canvas` is a connector to the canvas on the page, where the chart should show up.
85+
It can be directly used with `new Chart(canvas, chartData)`.
86+
87+
The function *must* return the created `Chart` object, cause the stats page need access to it.
88+
So a typical wokflow will use `data` to generate a object `chartData` for ChartJS and
89+
end with `return new Chart(canvas, chartData);`.
90+
91+
For information how to create charts see https://www.chartjs.org/ (also jQuery is loaded in the DOM as `$`).
92+
93+
### Upload to server
94+
All JS file creating charts (and containing exactly one `createGraph`) have to be placed in the folder
95+
`/php-code/load/graphs/` inside the docker-container. Using docker-compose one might add
96+
`./charts/:/php-code/load/graphs/` to the `volumes` section of the `docker-compose.yml` and
97+
add all file to `./charts/`.
98+
99+
All JS file should be named like this `<GraphName>.js`. Of course it it recommended to
100+
use only `A-Za-z-9` for the `GraphName`.

0 commit comments

Comments
 (0)