|
1 | 1 | # TablePress Extension: Chart.js |
2 | | -Create a chart.js using the data in a TablePress table |
3 | 2 |
|
| 3 | +Create a [Chart.js](https://www.chartjs.org/) using [TablePress](https://tablepress.org/) as data source |
4 | 4 |
|
5 | | -## About |
6 | 5 |
|
7 | | -This plugin code and idea is a modification of [TablePress Extension: Chartist](https://github.com/soderlind/tablepress_chartist). |
| 6 | +## About |
8 | 7 |
|
9 | | -Using [Chart.js](https://www.chartjs.org/), this [TablePress](https://tablepress.org/) Extension creates a responsive chart based on the data in a TablePress table. |
| 8 | +This plugin code base and idea is a modification of [TablePress Extension: Chartist](https://github.com/soderlind/tablepress_chartist). |
10 | 9 |
|
11 | 10 |
|
12 | 11 | ## Usage |
13 | 12 |
|
14 | | -Add the Shortcode [tp-chartjs id=123 dimension=1 data=2,3/] to a post or page to create a chart from the TablePress table 123. |
| 13 | +Add the Shortcode `[tp-chartjs id=1 label=A data=B,C/]` to a post or page to create a chart from the TablePress ID '1' where labes are column `A`, and dataset points are columns `B` and `C`. |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +Result: |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +## Attributes |
| 23 | + |
| 24 | + - [`id={n}`](#att_id) TablePress ID reference |
| 25 | + - [`label={c,...}`](#att_label) Column Axis label (default: A) |
| 26 | + - [`data={n,...}`](#att_data) Column(s) datasets used to populate chart (default: B) |
| 27 | + - [`chart=[line|hbar]`](#att_chart) Chart type (default: line) |
| 28 | + - [`color`](#att_color) (default: blue,red,orange,yellow,green,purple,grey,black) |
| 29 | + - [`height={n}`](#att_height) Declare height of `canvas` HTML object |
| 30 | + - [`first={n}`](#att_first) Declare that only use the first `{n}` rows of data |
| 31 | + - [`last={n}`](#att_last) Declare that only use the last `{n}` rows of data |
| 32 | + |
| 33 | + |
| 34 | +### `id`<a id="att_id"></a> |
| 35 | + |
| 36 | +TablePress ID reference |
| 37 | + |
| 38 | +* **Example:** `[tp-chartjs id=1/]` |
| 39 | +* **Value:** Integer `id` |
| 40 | + |
| 41 | + |
| 42 | +### `label`<a id="att_label"></a> |
| 43 | + |
| 44 | +Column Axis label |
| 45 | + |
| 46 | +* **Example:** `[tp-chartjs id=1 label=A data=B,C/]` |
| 47 | +* **Value:** One character from [A-Z] |
| 48 | +* **Default:** `A` |
| 49 | + |
| 50 | + |
| 51 | +### `data`<a id="att_data"></a> |
| 52 | + |
| 53 | +Column(s) datasets used to populate chart |
| 54 | + |
| 55 | +* **Example:** `[tp-chartjs id=1 label=A data=B,C,D,E/]` |
| 56 | +* **Values:** One or more comma separated columns character [A-Z] |
| 57 | +* **Default:** `B` |
| 58 | + |
| 59 | + |
| 60 | +### `chart`<a id="att_chart"></a> |
| 61 | + |
| 62 | +Chart type used |
| 63 | + |
| 64 | +* **Example:** `[tp-chartjs id=1 label=A data=B,C chart=line/]` |
| 65 | +* **Values:** Select one of this |
| 66 | + * `line`: Line |
| 67 | + * `hbar`: Vertical Bar |
| 68 | +* **Default:** `line` |
15 | 69 |
|
16 | 70 |
|
| 71 | +### `color`<a id="att_color"></a> |
| 72 | + |
| 73 | +The colors you can use in populated lines or bars. |
| 74 | + |
| 75 | +* **Example:** `[tp-chartjs id=1 label=A data=B,C color=blue,red/]` |
| 76 | +* **Values:** One or more comma separated colors |
| 77 | + * `blue` |
| 78 | + * `red` |
| 79 | + * `orange` |
| 80 | + * `yellow` |
| 81 | + * `green` |
| 82 | + * `purple` |
| 83 | + * `grey` |
| 84 | + * `black` |
| 85 | +* **Default:** `blue,red,orange,yellow,green,purple,grey,black` |
| 86 | + |
| 87 | +On example column `B` draws `blue` and column `C` draws `red` |
| 88 | + |
| 89 | + |
| 90 | +### `height`<a id="att_height"></a> |
| 91 | + |
| 92 | +Declare height of `canvas` HTML object |
| 93 | + |
| 94 | +* **Example:** `[tp-chartjs id=1 label=A data=B,C height=300/]` |
| 95 | +* **Values:** Integer value transformed into pixels |
| 96 | +* **Default:** Automatic |
| 97 | + |
| 98 | +### `first`<a id="att_first"></a> |
| 99 | + |
| 100 | +Declare that only use the first `{n}` rows of data |
| 101 | + |
| 102 | +* **Example:** `[tp-chartjs id=1 label=A data=B,C first=10/]` |
| 103 | +* **Value:** Integer value offset |
| 104 | +* **Default:** All data |
| 105 | + |
| 106 | + |
| 107 | +### `last`<a id="att_last"></a> |
| 108 | + |
| 109 | +Declare that only use the last `{n}` rows of data |
| 110 | + |
| 111 | +* **Example:** `[tp-chartjs id=1 label=A data=B,C last=10/]` |
| 112 | +* **Values:** Integer value offset |
| 113 | +* **Default:** All data |
| 114 | + |
17 | 115 |
|
18 | 116 | ## Install |
19 | 117 |
|
| 118 | +Prerequisite: The [TablePress](https://tablepress.org/) plugin |
| 119 | + |
| 120 | + |
| 121 | +## Donate to Developer |
| 122 | + |
| 123 | +If you like my work, please donate to help me. |
20 | 124 |
|
21 | | -## Donations |
| 125 | +[](https://www.paypal.com/donate?hosted_button_id=ZXY9DM6PTWB8C) |
22 | 126 |
|
23 | | -[Buy me a Coffee](https://www.paypal.com/paypalme/developarts) |
| 127 | + |
| 128 | +## To Do |
| 129 | + |
| 130 | +- [ ] Chart Title |
| 131 | +- [ ] Vertical Bar chart support |
| 132 | +- [ ] Pie chart support |
| 133 | +- [ ] Time Series chart support |
| 134 | +- [ ] Stacked chart support |
24 | 135 |
|
25 | 136 |
|
26 | 137 | ## Changelog |
27 | 138 |
|
28 | | -* 0.1 Initial release |
| 139 | +### [0.2] - 2020-11-06 |
| 140 | + |
| 141 | +#### Added |
| 142 | +- Attribute `height` for the canvas object |
| 143 | +- Attribute `color={color1,color2,..n}` comma separator |
| 144 | +- Supported colors [blue,red,orange,yellow,green,purple,grey,black] |
| 145 | +- Attribute `first={n}` show only `{n}` first rows |
| 146 | +- Attribute `last={n}` show only `{n}` last rows |
| 147 | + |
| 148 | +#### Changed |
| 149 | +- Attribute `data` now accept A-Z to correspond TablePress columns |
| 150 | +- Attribute `dimension` to `label` attribute |
| 151 | +- `_maybe_string_to_number` RegExp |
| 152 | + |
| 153 | + |
| 154 | +### [0.1] - 2020-11-01 |
| 155 | +- Initial release |
29 | 156 |
|
30 | 157 |
|
31 | 158 | ## Credits |
|
0 commit comments