Looping collection to jquery in laravel
I have static chart with jquery and i want to use dynamic data in it but it returns SyntaxError: unexpected token: ':'
code
Static
Morris.Area({
element: 'dashboard-area-1',
data: [
{ y: '2014-10-10', a: 17,b: 19, c: 10},
{ y: '2014-10-11', a: 19,b: 21, c: 11},
{ y: '2014-10-12', a: 22,b: 25, c: 33},
{ y: '2014-10-13', a: 20,b: 22, c: 55},
{ y: '2014-10-14', a: 21,b: 24, c: 89},
{ y: '2014-10-15', a: 34,b: 37, c: 34},
{ y: '2014-10-16', a: 43,b: 45, c: 65}
],
xkey: 'y',
ykeys: ['a','b', 'c'],
labels: ['Page', 'Visitors','Page Views'],
resize: true,
hideHover: true,
xLabels: 'day',
gridTextSize: '10px',
lineColors: ['#1caf9a','#33414E', '#2344d3'],
gridLineColor: '#E5E5E5'
});
Dynamic
var analysdata = "{{$analyticsData}}";
Morris.Area({
element: 'dashboard-area-1',
data: [
$.each( analysdata, function( key, value ) {
y: '2014-10-10', a: value.pageTitle,b: value.visitors, c: value.pageViews,
});
],
xkey: 'y',
ykeys: ['a','b', 'c'],
labels: ['Page', 'Visitors','Page Views'],
resize: true,
hideHover: true,
xLabels: 'day',
gridTextSize: '10px',
lineColors: ['#1caf9a','#33414E', '#2344d3'],
gridLineColor: '#E5E5E5'
});
error comes from:
y: '2014-10-10', a: value.pageTitle,b: value.visitors, c: value.pageViews,
what did i do wrong?
jquery laravel charts morris.js
add a comment |
I have static chart with jquery and i want to use dynamic data in it but it returns SyntaxError: unexpected token: ':'
code
Static
Morris.Area({
element: 'dashboard-area-1',
data: [
{ y: '2014-10-10', a: 17,b: 19, c: 10},
{ y: '2014-10-11', a: 19,b: 21, c: 11},
{ y: '2014-10-12', a: 22,b: 25, c: 33},
{ y: '2014-10-13', a: 20,b: 22, c: 55},
{ y: '2014-10-14', a: 21,b: 24, c: 89},
{ y: '2014-10-15', a: 34,b: 37, c: 34},
{ y: '2014-10-16', a: 43,b: 45, c: 65}
],
xkey: 'y',
ykeys: ['a','b', 'c'],
labels: ['Page', 'Visitors','Page Views'],
resize: true,
hideHover: true,
xLabels: 'day',
gridTextSize: '10px',
lineColors: ['#1caf9a','#33414E', '#2344d3'],
gridLineColor: '#E5E5E5'
});
Dynamic
var analysdata = "{{$analyticsData}}";
Morris.Area({
element: 'dashboard-area-1',
data: [
$.each( analysdata, function( key, value ) {
y: '2014-10-10', a: value.pageTitle,b: value.visitors, c: value.pageViews,
});
],
xkey: 'y',
ykeys: ['a','b', 'c'],
labels: ['Page', 'Visitors','Page Views'],
resize: true,
hideHover: true,
xLabels: 'day',
gridTextSize: '10px',
lineColors: ['#1caf9a','#33414E', '#2344d3'],
gridLineColor: '#E5E5E5'
});
error comes from:
y: '2014-10-10', a: value.pageTitle,b: value.visitors, c: value.pageViews,
what did i do wrong?
jquery laravel charts morris.js
add a comment |
I have static chart with jquery and i want to use dynamic data in it but it returns SyntaxError: unexpected token: ':'
code
Static
Morris.Area({
element: 'dashboard-area-1',
data: [
{ y: '2014-10-10', a: 17,b: 19, c: 10},
{ y: '2014-10-11', a: 19,b: 21, c: 11},
{ y: '2014-10-12', a: 22,b: 25, c: 33},
{ y: '2014-10-13', a: 20,b: 22, c: 55},
{ y: '2014-10-14', a: 21,b: 24, c: 89},
{ y: '2014-10-15', a: 34,b: 37, c: 34},
{ y: '2014-10-16', a: 43,b: 45, c: 65}
],
xkey: 'y',
ykeys: ['a','b', 'c'],
labels: ['Page', 'Visitors','Page Views'],
resize: true,
hideHover: true,
xLabels: 'day',
gridTextSize: '10px',
lineColors: ['#1caf9a','#33414E', '#2344d3'],
gridLineColor: '#E5E5E5'
});
Dynamic
var analysdata = "{{$analyticsData}}";
Morris.Area({
element: 'dashboard-area-1',
data: [
$.each( analysdata, function( key, value ) {
y: '2014-10-10', a: value.pageTitle,b: value.visitors, c: value.pageViews,
});
],
xkey: 'y',
ykeys: ['a','b', 'c'],
labels: ['Page', 'Visitors','Page Views'],
resize: true,
hideHover: true,
xLabels: 'day',
gridTextSize: '10px',
lineColors: ['#1caf9a','#33414E', '#2344d3'],
gridLineColor: '#E5E5E5'
});
error comes from:
y: '2014-10-10', a: value.pageTitle,b: value.visitors, c: value.pageViews,
what did i do wrong?
jquery laravel charts morris.js
I have static chart with jquery and i want to use dynamic data in it but it returns SyntaxError: unexpected token: ':'
code
Static
Morris.Area({
element: 'dashboard-area-1',
data: [
{ y: '2014-10-10', a: 17,b: 19, c: 10},
{ y: '2014-10-11', a: 19,b: 21, c: 11},
{ y: '2014-10-12', a: 22,b: 25, c: 33},
{ y: '2014-10-13', a: 20,b: 22, c: 55},
{ y: '2014-10-14', a: 21,b: 24, c: 89},
{ y: '2014-10-15', a: 34,b: 37, c: 34},
{ y: '2014-10-16', a: 43,b: 45, c: 65}
],
xkey: 'y',
ykeys: ['a','b', 'c'],
labels: ['Page', 'Visitors','Page Views'],
resize: true,
hideHover: true,
xLabels: 'day',
gridTextSize: '10px',
lineColors: ['#1caf9a','#33414E', '#2344d3'],
gridLineColor: '#E5E5E5'
});
Dynamic
var analysdata = "{{$analyticsData}}";
Morris.Area({
element: 'dashboard-area-1',
data: [
$.each( analysdata, function( key, value ) {
y: '2014-10-10', a: value.pageTitle,b: value.visitors, c: value.pageViews,
});
],
xkey: 'y',
ykeys: ['a','b', 'c'],
labels: ['Page', 'Visitors','Page Views'],
resize: true,
hideHover: true,
xLabels: 'day',
gridTextSize: '10px',
lineColors: ['#1caf9a','#33414E', '#2344d3'],
gridLineColor: '#E5E5E5'
});
error comes from:
y: '2014-10-10', a: value.pageTitle,b: value.visitors, c: value.pageViews,
what did i do wrong?
jquery laravel charts morris.js
jquery laravel charts morris.js
asked yesterday
mafortismafortis
1,031735
1,031735
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
In your controller, you need this:
return view( 'your_view_name',[
'analyticsData'=> json_encode($analyticsData, JSON_UNESCAPED_SLASHES );
]);
Then, try this:
var analysdata = {!! $analyticsData !!};
const theData = ;
$.each( analysdata, function( key, value ) {
theData.push({
y: '2014-10-10', a: value.pageTitle,b: value.visitors, c: value.pageViews
});
});
Morris.Area({
element: 'dashboard-area-1',
data: theData,
xkey: 'y',
ykeys: ['a','b', 'c'],
labels: ['Page', 'Visitors','Page Views'],
resize: true,
hideHover: true,
xLabels: 'day',
gridTextSize: '10px',
lineColors: ['#1caf9a','#33414E', '#2344d3'],
gridLineColor: '#E5E5E5'
});
givingTypeError: right-hand side of 'in' should be an object, got string
– mafortis
yesterday
There's no 'in' in that code though
– markmoxx
yesterday
it refers to$.each( analysdata, function( key, value ) {
– mafortis
yesterday
Ah, I thought"{{$analyticsData}}"
was just a placeholder your your analytics object - it's just set to a string? Where does the data actually come from?
– markmoxx
yesterday
1
Have you checked the chat, and seen my updated answer?
– markmoxx
yesterday
|
show 5 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2f54251784%2flooping-collection-to-jquery-in-laravel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
In your controller, you need this:
return view( 'your_view_name',[
'analyticsData'=> json_encode($analyticsData, JSON_UNESCAPED_SLASHES );
]);
Then, try this:
var analysdata = {!! $analyticsData !!};
const theData = ;
$.each( analysdata, function( key, value ) {
theData.push({
y: '2014-10-10', a: value.pageTitle,b: value.visitors, c: value.pageViews
});
});
Morris.Area({
element: 'dashboard-area-1',
data: theData,
xkey: 'y',
ykeys: ['a','b', 'c'],
labels: ['Page', 'Visitors','Page Views'],
resize: true,
hideHover: true,
xLabels: 'day',
gridTextSize: '10px',
lineColors: ['#1caf9a','#33414E', '#2344d3'],
gridLineColor: '#E5E5E5'
});
givingTypeError: right-hand side of 'in' should be an object, got string
– mafortis
yesterday
There's no 'in' in that code though
– markmoxx
yesterday
it refers to$.each( analysdata, function( key, value ) {
– mafortis
yesterday
Ah, I thought"{{$analyticsData}}"
was just a placeholder your your analytics object - it's just set to a string? Where does the data actually come from?
– markmoxx
yesterday
1
Have you checked the chat, and seen my updated answer?
– markmoxx
yesterday
|
show 5 more comments
In your controller, you need this:
return view( 'your_view_name',[
'analyticsData'=> json_encode($analyticsData, JSON_UNESCAPED_SLASHES );
]);
Then, try this:
var analysdata = {!! $analyticsData !!};
const theData = ;
$.each( analysdata, function( key, value ) {
theData.push({
y: '2014-10-10', a: value.pageTitle,b: value.visitors, c: value.pageViews
});
});
Morris.Area({
element: 'dashboard-area-1',
data: theData,
xkey: 'y',
ykeys: ['a','b', 'c'],
labels: ['Page', 'Visitors','Page Views'],
resize: true,
hideHover: true,
xLabels: 'day',
gridTextSize: '10px',
lineColors: ['#1caf9a','#33414E', '#2344d3'],
gridLineColor: '#E5E5E5'
});
givingTypeError: right-hand side of 'in' should be an object, got string
– mafortis
yesterday
There's no 'in' in that code though
– markmoxx
yesterday
it refers to$.each( analysdata, function( key, value ) {
– mafortis
yesterday
Ah, I thought"{{$analyticsData}}"
was just a placeholder your your analytics object - it's just set to a string? Where does the data actually come from?
– markmoxx
yesterday
1
Have you checked the chat, and seen my updated answer?
– markmoxx
yesterday
|
show 5 more comments
In your controller, you need this:
return view( 'your_view_name',[
'analyticsData'=> json_encode($analyticsData, JSON_UNESCAPED_SLASHES );
]);
Then, try this:
var analysdata = {!! $analyticsData !!};
const theData = ;
$.each( analysdata, function( key, value ) {
theData.push({
y: '2014-10-10', a: value.pageTitle,b: value.visitors, c: value.pageViews
});
});
Morris.Area({
element: 'dashboard-area-1',
data: theData,
xkey: 'y',
ykeys: ['a','b', 'c'],
labels: ['Page', 'Visitors','Page Views'],
resize: true,
hideHover: true,
xLabels: 'day',
gridTextSize: '10px',
lineColors: ['#1caf9a','#33414E', '#2344d3'],
gridLineColor: '#E5E5E5'
});
In your controller, you need this:
return view( 'your_view_name',[
'analyticsData'=> json_encode($analyticsData, JSON_UNESCAPED_SLASHES );
]);
Then, try this:
var analysdata = {!! $analyticsData !!};
const theData = ;
$.each( analysdata, function( key, value ) {
theData.push({
y: '2014-10-10', a: value.pageTitle,b: value.visitors, c: value.pageViews
});
});
Morris.Area({
element: 'dashboard-area-1',
data: theData,
xkey: 'y',
ykeys: ['a','b', 'c'],
labels: ['Page', 'Visitors','Page Views'],
resize: true,
hideHover: true,
xLabels: 'day',
gridTextSize: '10px',
lineColors: ['#1caf9a','#33414E', '#2344d3'],
gridLineColor: '#E5E5E5'
});
edited yesterday
answered yesterday
markmoxxmarkmoxx
1,043515
1,043515
givingTypeError: right-hand side of 'in' should be an object, got string
– mafortis
yesterday
There's no 'in' in that code though
– markmoxx
yesterday
it refers to$.each( analysdata, function( key, value ) {
– mafortis
yesterday
Ah, I thought"{{$analyticsData}}"
was just a placeholder your your analytics object - it's just set to a string? Where does the data actually come from?
– markmoxx
yesterday
1
Have you checked the chat, and seen my updated answer?
– markmoxx
yesterday
|
show 5 more comments
givingTypeError: right-hand side of 'in' should be an object, got string
– mafortis
yesterday
There's no 'in' in that code though
– markmoxx
yesterday
it refers to$.each( analysdata, function( key, value ) {
– mafortis
yesterday
Ah, I thought"{{$analyticsData}}"
was just a placeholder your your analytics object - it's just set to a string? Where does the data actually come from?
– markmoxx
yesterday
1
Have you checked the chat, and seen my updated answer?
– markmoxx
yesterday
giving
TypeError: right-hand side of 'in' should be an object, got string
– mafortis
yesterday
giving
TypeError: right-hand side of 'in' should be an object, got string
– mafortis
yesterday
There's no 'in' in that code though
– markmoxx
yesterday
There's no 'in' in that code though
– markmoxx
yesterday
it refers to
$.each( analysdata, function( key, value ) {
– mafortis
yesterday
it refers to
$.each( analysdata, function( key, value ) {
– mafortis
yesterday
Ah, I thought
"{{$analyticsData}}"
was just a placeholder your your analytics object - it's just set to a string? Where does the data actually come from?– markmoxx
yesterday
Ah, I thought
"{{$analyticsData}}"
was just a placeholder your your analytics object - it's just set to a string? Where does the data actually come from?– markmoxx
yesterday
1
1
Have you checked the chat, and seen my updated answer?
– markmoxx
yesterday
Have you checked the chat, and seen my updated answer?
– markmoxx
yesterday
|
show 5 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f54251784%2flooping-collection-to-jquery-in-laravel%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