Skip to content

Commit

Permalink
fix: chart.js plugin initialization (#23570)
Browse files Browse the repository at this point in the history
  • Loading branch information
skoob13 authored Jul 9, 2024
1 parent 67e3bca commit 53ac25b
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import '../../../../../scenes/insights/InsightTooltip/InsightTooltip.scss'
import { LemonTable } from '@posthog/lemon-ui'
import { ChartData, ChartType, Color, GridLineOptions, TickOptions, TooltipModel } from 'chart.js'
import annotationPlugin, { AnnotationPluginOptions, LineAnnotationOptions } from 'chartjs-plugin-annotation'
import ChartDataLabels from 'chartjs-plugin-datalabels'
import dataLabelsPlugin from 'chartjs-plugin-datalabels'
import clsx from 'clsx'
import { useValues } from 'kea'
import { Chart, ChartItem, ChartOptions } from 'lib/Chart'
Expand All @@ -21,6 +21,8 @@ import { ChartDisplayType, GraphType } from '~/types'
import { dataVisualizationLogic } from '../../dataVisualizationLogic'
import { displayLogic } from '../../displayLogic'

Chart.register(annotationPlugin)

export const LineGraph = (): JSX.Element => {
const canvasRef = useRef<HTMLCanvasElement | null>(null)
const { isDarkModeOn } = useValues(themeLogic)
Expand Down Expand Up @@ -258,12 +260,11 @@ export const LineGraph = (): JSX.Element => {
},
}

Chart.register(annotationPlugin)
const newChart = new Chart(canvasRef.current?.getContext('2d') as ChartItem, {
type: isBarChart ? GraphType.Bar : GraphType.Line,
data,
options,
plugins: [ChartDataLabels],
plugins: [dataLabelsPlugin],
})
return () => newChart.destroy()
}, [xData, yData, visualizationType, goalLines])
Expand Down

0 comments on commit 53ac25b

Please sign in to comment.