score:1
Looks like your isRebuildingCanvas
logic might be inconsistent, or I don't just understand it.
Anyway, from the Chart.js perspective, you'd want to change the data and call chartInstance.update()
when pressing the button that changes the data.
Partial example:
const canvas = useRef(null);
const [chart, setChart] = useState();
const [timeFormat, setTimeFormat] = useState("24h");
useEffect(() => {
if (chart || !canvas.current) return;
const ctx = canvas.current.getContext("2d");
if (!ctx) return;
const config = {/*...*/};
setChart(new Chart(ctx, config));
}, [chart, canvas]);
useEffect(() => {
if (!chart) return;
chart.config.data.datasets[0].data = determineTimeFormat(timeFormat, day, week, year);
chart.update();
}, [chart, timeFormat]);
And a complete, very similar example: https://codesandbox.io/s/blissful-faraday-hzcq0
Source: stackoverflow.com
Related Query
- Line chart is not being displayed in Chart.js
- Time series line chart is not displayed
- show label in tooltip but not in x axis for chartjs line chart
- Angular-chart.js - Make line chart does not curve
- angular-chartjs line chart TypeError: t.merge is not a function
- Chart.js line chart is not displaying
- Time Series Line chart js in react not working
- Click event of stacked line chart not working
- Stacked line chart not displaying correctly when Xaxis is time
- Chart.js tooltip not showing on line chart
- annotation line not visible in scatter chart in chartjs
- Chart.js Date and Time Bar Chart Not Rendering - Line Works Though
- Want only line not area under it in chart js
- Do not draw line on condition in ChartJS line chart
- Legend not displaying on Line or Bar chart - React-Chartjs-2
- react chart js, title is not displayed
- Chart.js: chart not displayed from modules despite no errors - JS
- Chart content not getting displayed in ionic
- vertical grid line not taking full hight of the canvas in chart js 3.3.2
- Line Chart is not setting backgroundColor when created dynamically Chart.js
- ChartJS line chart x = y not rendering astraight line
- Using number/text input field to set the data values in ChartJs stops the chart from being displayed
- ChartJS autoskip:False not working on line chart
- X and Y axis labels not displaying on line chart (Chart.js)
- Data not displaying properly in Chart.js line chart
- Chartjs backgroundColor for line chart does not appear in Vue app
- angular 4 line chart data is not showing data from http get
- Chart.js line chart not showing point on top most value
- Primeng line chart not updating automatically,only update on window refresh
- Chart.js Line chart Option does not disable gridlines
More Query from same tag
- Click events on Pie Charts in Chart.js
- how to create a bar chart with php data variables
- How to set data values as labels in Chart.js with a Radar Chart
- ChartJS number shows up on top of number
- Chart.js not stretching width as per data
- Hovering over chart.js values in Meteor onRendered function causes chart axis shift
- Dynamically update values of a chartjs chart
- Sum array of objects value based on month - ReactJS
- ChartJS tooltip scrollbar to prevent data overflow?
- show multiple responsive chart in the same page using chart.js
- Tooltip flickering when hovered on chart
- Chart.js - Uncaught TypeError: Object.defineProperty called on non-object for multiple charts
- Data-labeling ChartJS, Removing Duplicates?
- code works fine on jsfiddle but one function is not working on website
- How to align elements using a ChartBar from Chart.js and Alerts from Bootstrap 4?
- I can't change the legend position in Laravel Charts & ChartJS
- PHP Date and Time, getting the 1st, 2nd, 3rd, and 4th week in a month
- Barchart show value to print
- Moving point to clicked point in ChartJS (radarchart)
- The scale on the axis doesn't automatically narrow
- Chart.js multiple dataset issue: hovering over n-th point "hovers" over every dataset's n-th point
- React setState() not updating state when button clicked
- impossible to remove scale from radar chart (chart.js)
- Ionic2: Use chartjs inside ion-segment
- Different labels needed for second line graph, chart js
- How to display axis borders only (no grid lines) in chartjs?
- Chart.js not show in my function (function used in ajax) jquery
- How to plot an equation using ChartJS?
- How to fill background colors on line-charts?
- How to increase size and family in a radar's Chartjs label