Reputation: 602
I am having error from JQuery code that returns error: Uncaught SyntaxError: Unexpected identifier
This is not working for me:
var Script = function () {
$(function () {
Morris.Area({
element: 'hero-area',
data: [
{period: 'January', Total Deposit: 19000, Total Fee Payments: -744.3, Total Settlement Payout: 24900, Total Contracts: 1825},
{period: 'February', Total Deposit: 11000, Total Fee Payments: -189.9, Total Settlement Payout: 6400, Total Contracts: 429},
{period: 'March', Total Deposit: 14000, Total Fee Payments: -206.1, Total Settlement Payout: 3955, Total Contracts: 743}],
xkey: 'period',
ykeys: ['Total Deposit', 'Total Fee Payments', 'Total Settlement Payout', 'Total Contracts'],
labels: ['Total Deposit', 'Total Fee Payments', 'Total Settlement Payout', 'Total Contracts'],
hideHover: 'auto',
lineWidth: 1,
pointSize: 5,
lineColors: ['#4CD964', '#007AFF', '#FFCC00'],
fillOpacity: 0.5,
smooth: true
});
});
}();
Error comes in this line:
{period: 'January', Total Deposit: 19000, Total Fee Payments: -744.3, Total Settlement Payout: 24900, Total Contracts: 1825},
While this below code is working fine.
var Script = function () {
$(function () {
Morris.Area({
element: 'hero-area',
data: [
{period: '2010 Q1', iphone: 2666, ipad: null, itouch: 2647},
{period: '2010 Q2', iphone: 2778, ipad: 2294, itouch: 2441},
{period: '2010 Q3', iphone: 4912, ipad: 1969, itouch: 2501},
{period: '2010 Q4', iphone: 3767, ipad: 3597, itouch: 5689},
{period: '2011 Q1', iphone: 6810, ipad: 1914, itouch: 2293},
{period: '2011 Q2', iphone: 5670, ipad: 4293, itouch: 1881},
{period: '2011 Q3', iphone: 4820, ipad: 3795, itouch: 1588},
{period: '2011 Q4', iphone: 15073, ipad: 5967, itouch: 5175},
{period: '2012 Q1', iphone: 10687, ipad: 4460, itouch: 2028},
{period: '2012 Q2', iphone: 8432, ipad: 5713, itouch: 1791}
],
xkey: 'period',
ykeys: ['iphone', 'ipad', 'itouch'],
labels: ['iPhone', 'iPad', 'iPod Touch'],
hideHover: 'auto',
lineWidth: 1,
pointSize: 5,
lineColors: ['#4CD964', '#007AFF', '#FFCC00'],
fillOpacity: 0.5,
smooth: true
});
});
}();
Upvotes: 0
Views: 677
Reputation: 413976
You're trying to use property names with spaces in them. You can do that, but the names have to be quoted:
{period: 'January', 'Total Deposit': 19000, 'Total Fee Payments': -744.3, 'Total Settlement Payout': 24900, 'Total Contracts': 1825},
To refer to such property names, you'll have to use the [ ]
operator instead of .
:
var someObject = // one of your objects with those names
var settlement = someObject['Total Settlement Payout'];
It doesn't matter whether you use single- or double-quote characters.
Upvotes: 3