diff options
| author | Haishan <[email protected]> | 2022-05-08 18:37:08 +0800 |
|---|---|---|
| committer | Haishan <[email protected]> | 2022-05-08 23:30:24 +0800 |
| commit | e8f927bfd3faa6234674fa256010f0e2f53339e0 (patch) | |
| tree | 64246333af7cd800053078404cc5777c88f1414d /src/hooks/useLineChart.ts | |
| parent | 3458ef250de9b26bcff4522479708ca9fa5a553c (diff) | |
Upgrade chart.js
Diffstat (limited to 'src/hooks/useLineChart.ts')
| -rw-r--r-- | src/hooks/useLineChart.ts | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/src/hooks/useLineChart.ts b/src/hooks/useLineChart.ts index 2757ee1..a3205aa 100644 --- a/src/hooks/useLineChart.ts +++ b/src/hooks/useLineChart.ts @@ -1,28 +1,24 @@ +import type { ChartConfiguration } from 'chart.js'; import React from 'react'; import { commonChartOptions } from 'src/misc/chart'; const { useEffect } = React; -const options = commonChartOptions; export default function useLineChart( - Chart, - elementId, - data, - subscription, + chart: typeof import('chart.js').Chart, + elementId: string, + data: ChartConfiguration['data'], + subscription: any, extraChartOptions = {} ) { useEffect(() => { - const ctx = document.getElementById(elementId).getContext('2d'); - const c = new Chart(ctx, { - type: 'line', - data, - options: { ...options, ...extraChartOptions }, - }); - const unsubscribe = - subscription && subscription.subscribe(() => c.update()); + const ctx = (document.getElementById(elementId) as HTMLCanvasElement).getContext('2d'); + const options = { ...commonChartOptions, ...extraChartOptions }; + const c = new chart(ctx, { type: 'line', data, options }); + const unsubscribe = subscription && subscription.subscribe(() => c.update()); return () => { unsubscribe && unsubscribe(); c.destroy(); }; - }, [Chart, elementId, data, subscription, extraChartOptions]); + }, [chart, elementId, data, subscription, extraChartOptions]); } |
