Skip to content

Commit 80fd45c

Browse files
authored
Merge pull request #31 from mnutt/chartjs4
Support chartjs 4
2 parents 21ead4e + 93c53df commit 80fd45c

15 files changed

+272
-330
lines changed

β€ŽREADME.mdβ€Ž

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010

1111
#### Dependencies:
1212

13-
- requires [chart.js](https://www.chartjs.org) 2.7 or later.
14-
- requires [moment.js](https://momentjs.com/) 2.0 or later.
13+
- requires [chart.js](https://www.chartjs.org) 4.0 or later.
14+
- requires a chart.js date provider to be registered, one of:
15+
- [chartjs-adapter-date-fns](https://github.com/chartjs/chartjs-adapter-date-fns)
16+
- [chartjs-adapter-moment](https://github.com/chartjs/chartjs-adapter-moment)
17+
- [chartjs-adapter-luxon](https://github.com/chartjs/chartjs-adapter-luxon)
18+
- if unsure, chartjs-adapter-date-fns is a good pick
1519
- requires [prometheus-query](https://github.com/samber/prometheus-query-js) 3.0 or later.
1620

1721
#### Demonstration:
@@ -25,10 +29,11 @@ I would be happy to add links to charts using this library. Feel free to reach m
2529
- Loads time-series from Prometheus into Chart.js.
2630
- **Similar to Grafana**, but ported to Chart.js for public-facing web applications.
2731
- **UMD compatible**, you can use it with any module loader
28-
- Supports **line chart only** (for now!)
32+
- Supports **line chart and bar chart only** (for now!)
2933
- Graph **auto-refresh**
3034
- Date interval can be **absolute** or **relative** to `now`
3135
- Multiple Prometheus queries into the same chart
36+
- Stacked series
3237
- Custom backend requests (useful for multitenant apps)
3338
- Hooks available (styling, labeling, data presentation...)
3439
- Custom chart messages for errors or empty Prometheus responses
@@ -51,13 +56,13 @@ npm install chartjs-plugin-datasource-prometheus --save
5156
Via CDN:
5257

5358
```html
54-
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
55-
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/Chart.min.js"></script>
59+
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.2.1/dist/Chart.min.js"></script>
60+
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"></script>
5661

5762
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datasource-prometheus/dist/chartjs-plugin-datasource-prometheus.umd.min.js"></script>
5863
```
5964

60-
πŸ’‘ Note that chartjs-plugin-datasource-prometheus must be loaded after Chart.js and Moment.js.
65+
πŸ’‘ Note that chartjs-plugin-datasource-prometheus must be loaded after Chart.js and the date-fns adapter
6166

6267
## πŸ’‘ Quick start
6368

@@ -137,6 +142,7 @@ var myChart = new Chart(ctx, {
137142
| **tension** | no | Bezier curve tension of the line. Set to 0 to draw straightlines. This option is ignored if monotone cubic interpolation is used | `0.4` |
138143
| **cubicInterpolationMode** | no | "default" or "monotone" | `"default"` |
139144
| **stepped** | no | false, true, "before", "middle" or "after" | `false` |
145+
| **stacked** | no | Whether values are stacked or not | false |
140146
| **fill** | no | Fills the area under the line | `false` |
141147
| **borderWidth** | no | Should I explain this field? | `3` |
142148
| **backgroundColor** | no | Should I explain this field? | See library source code |

β€Ždist/axes.d.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference types="chart.js" />
1+
import { Chart } from "chart.js/auto";
22
import { ChartDatasourcePrometheusPluginOptions } from "./options";
33
export declare function setTimeAxesOptions(chart: Chart): void;
44
export declare function fillGaps(chart: Chart, start: Date, end: Date, step: number, options: ChartDatasourcePrometheusPluginOptions): void;

β€Ždist/chartjs-plugin-datasource-prometheus.cjs.jsβ€Ž

Lines changed: 38 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Ždist/chartjs-plugin-datasource-prometheus.cjs.js.mapβ€Ž

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
Β (0)