Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
Fixed chart rendering issue.
Mike Cao40c1ce40e29f
diff --git a/src/components/charts/BarChart.tsx b/src/components/charts/BarChart.tsxindex 09ff51548..5655d7439 100644--- a/src/components/charts/BarChart.tsx+++ b/src/components/charts/BarChart.tsx@@ -1,3 +1,4 @@+import { useMemo } from 'react';import { useTheme } from 'components/hooks';import Chart, { ChartProps } from 'components/charts/Chart';import { renderNumberLabels } from 'lib/charts';@@ -25,45 +26,47 @@ export function BarChart(props: BarChartProps) {stacked = false,} = props;- const options = {- scales: {- x: {- type: XAxisType,- stacked: true,- time: {- unit,+ const options = useMemo(() => {+ return {+ scales: {+ x: {+ type: XAxisType,+ stacked: true,+ time: {+ unit,+ },+ grid: {+ display: false,+ },+ border: {+ color: colors.chart.line,+ },+ ticks: {+ color: colors.chart.text,+ autoSkip: false,+ maxRotation: 0,+ callback: renderXLabel,+ },},- grid: {- display: false,- },- border: {- color: colors.chart.line,- },- ticks: {- color: colors.chart.text,- autoSkip: false,- maxRotation: 0,- callback: renderXLabel,+ y: {+ type: YAxisType,+ min: 0,+ beginAtZero: true,+ stacked,+ grid: {+ color: colors.chart.line,+ },+ border: {+ color: colors.chart.line,+ },+ ticks: {+ color: colors.chart.text,+ callback: renderYLabel || renderNumberLabels,+ },},},- y: {- type: YAxisType,- min: 0,- beginAtZero: true,- stacked,- grid: {- color: colors.chart.line,- },- border: {- color: colors.chart.line,- },- ticks: {- color: colors.chart.text,- callback: renderYLabel || renderNumberLabels,- },- },- },- };+ };+ }, [colors]);const handleTooltip = ({ tooltip }: { tooltip: any }) => {const { opacity } = tooltip;diff --git a/src/components/charts/Chart.tsx b/src/components/charts/Chart.tsxindex a01192e47..2ec40d078 100644--- a/src/components/charts/Chart.tsx+++ b/src/components/charts/Chart.tsx@@ -1,4 +1,4 @@-import { useState, useRef, useEffect, ReactNode } from 'react';+import { useState, useRef, useEffect, useMemo, ReactNode } from 'react';import { Loading } from 'react-basics';import classNames from 'classnames';import ChartJS, { LegendItem } from 'chart.js/auto';@@ -38,29 +38,31 @@ export function Chart({const chart = useRef(null);const [legendItems, setLegendItems] = useState([]);- const options = {- responsive: true,- maintainAspectRatio: false,- animation: {- duration: animationDuration,- resize: {- duration: 0,+ const options = useMemo(() => {+ return {+ responsive: true,+ maintainAspectRatio: false,+ animation: {+ duration: animationDuration,+ resize: {+ duration: 0,+ },+ active: {+ duration: 0,+ },},- active: {- duration: 0,+ plugins: {+ legend: {+ display: false,+ },+ tooltip: {+ enabled: false,+ external: onTooltip,+ },},- },- plugins: {- legend: {- display: false,- },- tooltip: {- enabled: false,- external: onTooltip,- },- },- ...chartOptions,- };+ ...chartOptions,+ };+ }, [chartOptions]);const createChart = (data: any) => {ChartJS.defaults.font.family = 'Inter';