score:6
Found the answer,
The Ajax results has to be parsed first.
resulting fix
var barChartData = JSON.parse(d);
score:0
It looks like you're using an object that doesn't exist, well at least I cant see it, datasets
. I can only see length
being called on this object, unless there's missing code?
I can see you assign d
to barChartData
var barChartData = d;
So, you might want to replace the instances of datasets
with barChartData
.
score:0
It's an old question but, I had this issue as well and in my case my data was length = 0. I solved this just adding a validation before calling the the graph:
if (barChartData.length > 0)
{
objChart = Morris.Bar({....
}
score:2
You may try putting the Chart.JS script tag and other custom JS scripts just before the end of **<**/body>
tag.
score:4
For other users who have this problem, make sure your container canvas element exists, when called upon.
score:4
running the following worked for me:
window.onload = function () {
}
score:15
The problem is that when your code executes, the canvas has not been created yet. You should wrap your code inside a function and assign that function to window.onload event. You can see the sample code below.
window.onload = function() {
var ctx = document.getElementById("myChart");
var lineChart = new Chart(ctx, {
type: 'line',
data: {
labels: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
datasets: [{
label: "2015",
data: [10, 8, 6, 5, 12, 8, 16, 17, 6, 7, 6, 10]
}]
}
})
}
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.js"></script>
</head>
<body>
<canvas id="myChart"></canvas>
</body>
</html>
Source: stackoverflow.com
Related Query
- Chart Js Cannot read property 'length' of undefined
- chartjs - multi axis line chart - cannot read property 'min' of undefined
- Angular / ng2-charts: Fetching json data in chart object showing: Cannot read property 'length' of undefined
- Uncaught TypeError: Cannot read property 'draw' of undefined : Angular chart js
- Chart JS Error : Uncaught TypeError: Cannot read property 'top' of undefined
- Uncaught TypeError: Cannot read property 'offsetWidth' of undefined - chart.js
- Chartjs cannot read property datasets of undefined
- TypeError: Cannot read property 'defaults' of undefined when using the react wrapper of chartjs
- Cannot read property 'labels' of undefined
- Chart.js Cannot read property 'fontSize' of undefined
- TypeError: Cannot read property 'legend' of undefined | Angular + ng2-charts
- ChartJS: Uncaught TypeError: Cannot read property 'call' of undefined
- Uncaught TypeError: Cannot read property 'draw' of undefined
- Ionic/Chart.js - Cannot read property 'nativeElement' of undefined
- Updating Chart.js with JSON, cannot read property 'length' of undefined
- chartjs & asp.net: Cannot read property 'labels' of undefined
- Cannot read property 'reactiveProp' of undefined in vue-chartjs
- react-chartjs integration error. Cannot read property 'xLabels' of undefined
- Chartjs + Vue.js - Cannot read property '_meta' of undefined
- chartjs; cannot read property '0' of undefined
- Chart.js Cannot read property 'apply' of undefined
- Cannot read property 'length' of undefined for ChartJS when I use it inside React
- react-chartjs error Cannot read property 'Chart' of undefined
- Uncaught TypeError: Cannot read property 'draw' of undefined for object scale
- ERROR TypeError: Cannot read property 'testMethod' of undefined
- Uncaught (in promise) TypeError: Cannot read property 'length' of undefined in chartjs with Vuejs
- Angular and CharJS - ERROR TypeError: Cannot read property '15' of undefined
- Uncaught TypeError: Cannot read property 'format' of undefined
- Cannot read properties of undefined with react-chartjs-2 and chart js problem
- Angular4 ng2-charts TypeError: Cannot read property 'length' of undefined
More Query from same tag
- chart.js v3 - data decimation not working with zoom plugin
- Is there a convenient way to print values to a JS chart from a CSV file without converting it?
- How to fix map is not function even there is already set data in the useState using React Hook
- How to make bootstrap 4 column height the same as row height
- Chartjs small offset on top
- Chartjs bar order adjustment after bar chart is drawn
- Is it possible to print a chart with vue-chartjs?
- How to add font family to Chart.js V3.7.0
- how I can get label name when user click on particular area in doughnut chart.js? I am not able to find the index of selected area for chart.js
- Chartjs bar chart blurry when height is set
- Angular 2 ng2-charts doughnut text in the middle?
- chart.js dynamically set values of suggestedMin and suggestedMax based on values of array
- Rotate left legend chartjs
- Chart.js not to be begin in Y-Axis
- How to do click the HTML button as if the user is clicking
- ChartJS using AJAX call to retrieve data isn't rendering visualization
- Chartjs does not show on pdf in yii2 despite showing in html view
- Chart JS title passed from Django - issue with apostrophe '
- Chart.js - Fill Text only appearing when hovering over one part of the doughnut
- Parse a JSON object to ChartJS
- Loop to create lines for graph chartjs
- The real time chart sometimes does not display when I switch the target
- How can I automatically wrap tooltip text content to multiple lines?
- Printing a list by clicking chart Chart js + react
- Chart js sum of grouped bars
- JSON Data in javascript
- How can I skip data/labels in a period of time in Chartjs?
- How to show values on top of bars in a PDF using chart.js and chartjs-node-canvas?
- How can I hide point label in chart Js?
- React js Unhandled Rejection (TypeError): t[l].data.map is not a function