Chart.js not working - Uncaught RefernceError:
up vote
0
down vote
favorite
I am trying to display in chart form some data on time series data using chart.js. The data is fetched from psql, converted to json, and sent as an argument to js function to render a chart.
The data is received properly in js but there are errors 'Uncaught RefernceError' about the js function call in HTML.
EDIT
It's raising these errors:
Uncaught RefernceError: dspChrt is not defined @ line
dspChrt(WData);
</script>
</body>
</html>
Here is my code:
JS
<script>
var Device_Data;
var rssi, batt;
var rssiArray = ;
var battArray = ;
var N = 12;
for (i = 0; i < N; i++) {
rssiArray.push(0);
battArray.push(0); }
function dspChrt(Device_Data) {
console.log(Device_Data[0].rssi);
console.log(Device_Data[1].battery_voltage_mv);
rssi = Device_Data[0].rssi;
batt = Device_Data[1].battery_voltage_mv;
rssiArray.shift();
rssiArray.push(rssi);
battArray.shift();
battArray.push(batt);
var ctx = document.getElementById('myChart').getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: [new Date()],
datasets: [{
label: 'rssi',
data: rssiArray,
backgroundColor: "rgba(153,255,51,0.4)"
}, {
label: 'Battery_Voltage',
data: battArray,
backgroundColor: "rgba(255,153,0,0.4)"
}]
}
options: {
scales: {
xAxes: [{
type: 'time',
time: {
unit: 'hour',
}
}]
}
}
});
}
//var myVar = setInterval(dspChrt, 60000);
</script>
HTML/PHP
<?php
require("Connection.php");
$stmt = $conn->prepare("Select date_time, battery_voltage_mv FROM measuring_device_statuses LIMIT 24");
$stmt->execute();
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
$WData = $stmt->fetchAll();
/*
echo "<pre>".print_r($WData, true)."</pre>";
die();
*/
?>
<script>
var WData = <?php print_r(json_encode($WData));?>;
//console.log(WData);
dspChrt(WData);
</script>
</body>
</html>
javascript php html chart.js psql
add a comment |
up vote
0
down vote
favorite
I am trying to display in chart form some data on time series data using chart.js. The data is fetched from psql, converted to json, and sent as an argument to js function to render a chart.
The data is received properly in js but there are errors 'Uncaught RefernceError' about the js function call in HTML.
EDIT
It's raising these errors:
Uncaught RefernceError: dspChrt is not defined @ line
dspChrt(WData);
</script>
</body>
</html>
Here is my code:
JS
<script>
var Device_Data;
var rssi, batt;
var rssiArray = ;
var battArray = ;
var N = 12;
for (i = 0; i < N; i++) {
rssiArray.push(0);
battArray.push(0); }
function dspChrt(Device_Data) {
console.log(Device_Data[0].rssi);
console.log(Device_Data[1].battery_voltage_mv);
rssi = Device_Data[0].rssi;
batt = Device_Data[1].battery_voltage_mv;
rssiArray.shift();
rssiArray.push(rssi);
battArray.shift();
battArray.push(batt);
var ctx = document.getElementById('myChart').getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: [new Date()],
datasets: [{
label: 'rssi',
data: rssiArray,
backgroundColor: "rgba(153,255,51,0.4)"
}, {
label: 'Battery_Voltage',
data: battArray,
backgroundColor: "rgba(255,153,0,0.4)"
}]
}
options: {
scales: {
xAxes: [{
type: 'time',
time: {
unit: 'hour',
}
}]
}
}
});
}
//var myVar = setInterval(dspChrt, 60000);
</script>
HTML/PHP
<?php
require("Connection.php");
$stmt = $conn->prepare("Select date_time, battery_voltage_mv FROM measuring_device_statuses LIMIT 24");
$stmt->execute();
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
$WData = $stmt->fetchAll();
/*
echo "<pre>".print_r($WData, true)."</pre>";
die();
*/
?>
<script>
var WData = <?php print_r(json_encode($WData));?>;
//console.log(WData);
dspChrt(WData);
</script>
</body>
</html>
javascript php html chart.js psql
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to display in chart form some data on time series data using chart.js. The data is fetched from psql, converted to json, and sent as an argument to js function to render a chart.
The data is received properly in js but there are errors 'Uncaught RefernceError' about the js function call in HTML.
EDIT
It's raising these errors:
Uncaught RefernceError: dspChrt is not defined @ line
dspChrt(WData);
</script>
</body>
</html>
Here is my code:
JS
<script>
var Device_Data;
var rssi, batt;
var rssiArray = ;
var battArray = ;
var N = 12;
for (i = 0; i < N; i++) {
rssiArray.push(0);
battArray.push(0); }
function dspChrt(Device_Data) {
console.log(Device_Data[0].rssi);
console.log(Device_Data[1].battery_voltage_mv);
rssi = Device_Data[0].rssi;
batt = Device_Data[1].battery_voltage_mv;
rssiArray.shift();
rssiArray.push(rssi);
battArray.shift();
battArray.push(batt);
var ctx = document.getElementById('myChart').getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: [new Date()],
datasets: [{
label: 'rssi',
data: rssiArray,
backgroundColor: "rgba(153,255,51,0.4)"
}, {
label: 'Battery_Voltage',
data: battArray,
backgroundColor: "rgba(255,153,0,0.4)"
}]
}
options: {
scales: {
xAxes: [{
type: 'time',
time: {
unit: 'hour',
}
}]
}
}
});
}
//var myVar = setInterval(dspChrt, 60000);
</script>
HTML/PHP
<?php
require("Connection.php");
$stmt = $conn->prepare("Select date_time, battery_voltage_mv FROM measuring_device_statuses LIMIT 24");
$stmt->execute();
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
$WData = $stmt->fetchAll();
/*
echo "<pre>".print_r($WData, true)."</pre>";
die();
*/
?>
<script>
var WData = <?php print_r(json_encode($WData));?>;
//console.log(WData);
dspChrt(WData);
</script>
</body>
</html>
javascript php html chart.js psql
I am trying to display in chart form some data on time series data using chart.js. The data is fetched from psql, converted to json, and sent as an argument to js function to render a chart.
The data is received properly in js but there are errors 'Uncaught RefernceError' about the js function call in HTML.
EDIT
It's raising these errors:
Uncaught RefernceError: dspChrt is not defined @ line
dspChrt(WData);
</script>
</body>
</html>
Here is my code:
JS
<script>
var Device_Data;
var rssi, batt;
var rssiArray = ;
var battArray = ;
var N = 12;
for (i = 0; i < N; i++) {
rssiArray.push(0);
battArray.push(0); }
function dspChrt(Device_Data) {
console.log(Device_Data[0].rssi);
console.log(Device_Data[1].battery_voltage_mv);
rssi = Device_Data[0].rssi;
batt = Device_Data[1].battery_voltage_mv;
rssiArray.shift();
rssiArray.push(rssi);
battArray.shift();
battArray.push(batt);
var ctx = document.getElementById('myChart').getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: [new Date()],
datasets: [{
label: 'rssi',
data: rssiArray,
backgroundColor: "rgba(153,255,51,0.4)"
}, {
label: 'Battery_Voltage',
data: battArray,
backgroundColor: "rgba(255,153,0,0.4)"
}]
}
options: {
scales: {
xAxes: [{
type: 'time',
time: {
unit: 'hour',
}
}]
}
}
});
}
//var myVar = setInterval(dspChrt, 60000);
</script>
HTML/PHP
<?php
require("Connection.php");
$stmt = $conn->prepare("Select date_time, battery_voltage_mv FROM measuring_device_statuses LIMIT 24");
$stmt->execute();
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
$WData = $stmt->fetchAll();
/*
echo "<pre>".print_r($WData, true)."</pre>";
die();
*/
?>
<script>
var WData = <?php print_r(json_encode($WData));?>;
//console.log(WData);
dspChrt(WData);
</script>
</body>
</html>
javascript php html chart.js psql
javascript php html chart.js psql
edited Nov 8 at 15:58
asked Nov 7 at 15:46
XCeptable
56941433
56941433
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
When I looked at your code, I found labels
were configured, however your timestamp format will never match those labels. As a result, showing 0 makes sense.
Not sure what do you want. Maybe something like this?
Take a look at the script they coded, you will find out they didn't configure labels
.
If I were you, I might use scatter plot with showLines=true
instead.
Thank you very much chouhy ! Yes, something like that in the link I want. The time I want to appear in label horizontal & other parameters over time then in the graph. If the code for the link available, will help a lot. Can you please help edit my code for time to appear in label like in the link. I have basically 15 minutes interval.
– XCeptable
Nov 8 at 9:36
Ctrl+Shift+i and you can find the script of that link in <body>.
– chouhy
Nov 8 at 10:29
I edited the code but it's still complaining about syntax where I put 'options'.
– XCeptable
Nov 8 at 15:59
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
When I looked at your code, I found labels
were configured, however your timestamp format will never match those labels. As a result, showing 0 makes sense.
Not sure what do you want. Maybe something like this?
Take a look at the script they coded, you will find out they didn't configure labels
.
If I were you, I might use scatter plot with showLines=true
instead.
Thank you very much chouhy ! Yes, something like that in the link I want. The time I want to appear in label horizontal & other parameters over time then in the graph. If the code for the link available, will help a lot. Can you please help edit my code for time to appear in label like in the link. I have basically 15 minutes interval.
– XCeptable
Nov 8 at 9:36
Ctrl+Shift+i and you can find the script of that link in <body>.
– chouhy
Nov 8 at 10:29
I edited the code but it's still complaining about syntax where I put 'options'.
– XCeptable
Nov 8 at 15:59
add a comment |
up vote
0
down vote
When I looked at your code, I found labels
were configured, however your timestamp format will never match those labels. As a result, showing 0 makes sense.
Not sure what do you want. Maybe something like this?
Take a look at the script they coded, you will find out they didn't configure labels
.
If I were you, I might use scatter plot with showLines=true
instead.
Thank you very much chouhy ! Yes, something like that in the link I want. The time I want to appear in label horizontal & other parameters over time then in the graph. If the code for the link available, will help a lot. Can you please help edit my code for time to appear in label like in the link. I have basically 15 minutes interval.
– XCeptable
Nov 8 at 9:36
Ctrl+Shift+i and you can find the script of that link in <body>.
– chouhy
Nov 8 at 10:29
I edited the code but it's still complaining about syntax where I put 'options'.
– XCeptable
Nov 8 at 15:59
add a comment |
up vote
0
down vote
up vote
0
down vote
When I looked at your code, I found labels
were configured, however your timestamp format will never match those labels. As a result, showing 0 makes sense.
Not sure what do you want. Maybe something like this?
Take a look at the script they coded, you will find out they didn't configure labels
.
If I were you, I might use scatter plot with showLines=true
instead.
When I looked at your code, I found labels
were configured, however your timestamp format will never match those labels. As a result, showing 0 makes sense.
Not sure what do you want. Maybe something like this?
Take a look at the script they coded, you will find out they didn't configure labels
.
If I were you, I might use scatter plot with showLines=true
instead.
answered Nov 8 at 6:41
chouhy
1
1
Thank you very much chouhy ! Yes, something like that in the link I want. The time I want to appear in label horizontal & other parameters over time then in the graph. If the code for the link available, will help a lot. Can you please help edit my code for time to appear in label like in the link. I have basically 15 minutes interval.
– XCeptable
Nov 8 at 9:36
Ctrl+Shift+i and you can find the script of that link in <body>.
– chouhy
Nov 8 at 10:29
I edited the code but it's still complaining about syntax where I put 'options'.
– XCeptable
Nov 8 at 15:59
add a comment |
Thank you very much chouhy ! Yes, something like that in the link I want. The time I want to appear in label horizontal & other parameters over time then in the graph. If the code for the link available, will help a lot. Can you please help edit my code for time to appear in label like in the link. I have basically 15 minutes interval.
– XCeptable
Nov 8 at 9:36
Ctrl+Shift+i and you can find the script of that link in <body>.
– chouhy
Nov 8 at 10:29
I edited the code but it's still complaining about syntax where I put 'options'.
– XCeptable
Nov 8 at 15:59
Thank you very much chouhy ! Yes, something like that in the link I want. The time I want to appear in label horizontal & other parameters over time then in the graph. If the code for the link available, will help a lot. Can you please help edit my code for time to appear in label like in the link. I have basically 15 minutes interval.
– XCeptable
Nov 8 at 9:36
Thank you very much chouhy ! Yes, something like that in the link I want. The time I want to appear in label horizontal & other parameters over time then in the graph. If the code for the link available, will help a lot. Can you please help edit my code for time to appear in label like in the link. I have basically 15 minutes interval.
– XCeptable
Nov 8 at 9:36
Ctrl+Shift+i and you can find the script of that link in <body>.
– chouhy
Nov 8 at 10:29
Ctrl+Shift+i and you can find the script of that link in <body>.
– chouhy
Nov 8 at 10:29
I edited the code but it's still complaining about syntax where I put 'options'.
– XCeptable
Nov 8 at 15:59
I edited the code but it's still complaining about syntax where I put 'options'.
– XCeptable
Nov 8 at 15:59
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53192904%2fchart-js-not-working-uncaught-refernceerror%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown