score:0
I had the same problem after removing the defer
attribute that @TDM talked about. I solved this simply by adding an DOMContentLoaded event listener.
document.addEventListener("DOMContentLoaded", function () {
new Chart(ctx, {...});
});
score:0
had this same problem however removing defer attribute made other elements not to work in my laravel application. So I allowed defer on the app.js script and used the bellow suggested by @jakub to get it loaded after the dom element.
document.addEventListener("DOMContentLoaded",
function () {
new Chart(...);
}
);
score:2
This may be the most frustrating (bug/feature/problem) I have ever come accross and got me stuck for a few days, but because my boss doesn't take no for an answer and I hate giving up, I finally managed to solve it. The answer thought me something about html and javascript I never knew:
The answer:
In the <head></head>
of your html file you need to change the way bootstrap call's it's app.js
from this:
<script src="{{ asset('js/app.js') }}" defer></script>
to this:
<script src="{{ asset('js/app.js') }}"></script>
Note the missing defer
tag.
The explanation:
You may be wondering, what does the defer
tag do? And to answer that I give you this small snippet:
<html>
<body>
<script src="https://www.w3schools.com/tags/demo_defer.js" defer></script>
<p id="p1">
Hello World!
</p>
</body>
</html>
It simply stops the browser from loading/running the script until the site has been completely parsed. In the above example the script we call contains the following code:
alert(document.getElementById("p1").firstChild.nodeValue);
Basically telling your browser to send an alert with the contents of whatever is inside the p tags. Without the defer
tag, the script would fail because it would be run before the p tags get parsed by the browser, and javascript can only work with what the browser already parsed.
As far as I found, removing the defer tag doesn't break anything in bootstrap, so I don't know why it even has a defer tag.
I'm also not quite sure why this would be a problem for chart.js, If anyone knows I would love to hear it.
Source: stackoverflow.com
Related Query
- Laravel - Bootstrap Javascript's conflict with Chart.js
- Chart.JS full-width, responsive doughnut chart with Bootstrap
- How to display chart using Chartjs with JSON data in Laravel
- what is wrong with my code ? java script chart position
- Generate PDF from HTML page made with Bootstrap and ChartJS in Laravel
- Laravel Chart JS change data with dropdown
- Show Donut / Pie Chart in bootstrap modal with legends
- Why chart is not working with Bootstrap Modal?
- How can I create a horizontal scrolling Chart.js line chart with a locked y axis?
- Chartjs random colors for each part of pie chart with data dynamically from database
- ChartJS New Lines '\n' in X axis Labels or Displaying More Information Around Chart or Tooltip with ChartJS V2
- How to prevent first/last bars from being cut off in a chart with time scale
- ChartJS - Draw chart with label by month, data by day
- Horizontal stacked bar chart with chart.js
- line chart with {x, y} point data displays only 2 values
- Vertical stacked bar chart with chart.js
- Display line chart with connected dots using chartJS
- Chartjs 2 - Stacked bar and unstacked line on same chart with same y axis
- Chart.js - line chart with two yAxis: "TypeError: yScale is undefined"
- How to fix chart Legends width-height with overflow scroll in ChartJS
- How to display Line Chart dataset point labels with Chart.js?
- laravel query builder with conditions
- chart js how to fill legend box with colour
- Bootstrap grid not working with canvas
- Chart.js Mixed Bar and Line chart with different scales
- chart.js Line chart with different background colors for each section
- How do I draw a vertical line on a horizontal bar chart with ChartJS?
- reactive chart with chart.js in meteor
- chartjs: How to plot multi-line chart with irregular intervals
- Problem for display a chart with Chart.js and Angular
More Query from same tag
- Use Google Spreadsheet as data source for Chart.js
- How to enable zoom plugin using Chart JS?
- how to label axis within radar chart with chart.js
- chart.js legend not working for pie chart
- How to add background color between two specific lines in Chartjs 3.1
- How to set 3 axis in google chart (V-Axis Left as Qty, V-Axis Right as Series Column and H-Axis as TimeOrder)?
- React chart : prevent chart's canvas scaling with height and width
- Is there way to get counts of every day of week by created_at in laravel php
- how to hide tick labels on chartjs/vue-chartjs
- Chart JS change pointBackgroundColor based on data value
- Add images inside bar chart in chart.js
- Cannot read property 'length' of undefined for ChartJS when I use it inside React
- How to change cursor style to pointer on hovering over points of the chart?
- Change position of Chart.js tick labels
- How to set the pointDot option on combo stacked bar-line chart
- Adding object data to data structure of chart.js chart does not show any data
- (MVC) Is this an efficient way of displaying chart data by date?
- How to parse data to graph in MVC
- Chart.js: Dynamic Changing of Chart Type (Line to Bar as Example)
- chart.js horzontalBar Stacked and Grouped - data not showing - a bug?
- Generate PDF from chart and table
- Chart js size and placement
- Change the color of the legend box and the color of the x grid lines in chart.js
- how to modify horizontal bar chart using chart js
- How to use chart.js to plot line chart with x axis as time stamp in seconds
- How to modify bar width in Chartjs 2 bar charts
- Convert FirestoreCollection into an array?
- Chartjs box plot with Y-axis negative values
- how to transform changing data to be visualized in a chart.js
- How can I create a horizontal scrolling Chart.js line chart with a locked y axis?