Chart.js only works when page is refreshed

Does anyone know why my custom element with charts.js only shows a graph after the page has been refreshed?
I am following this example: https://www.wix.com/corvid/example/chart.js-custom-element