Json data parsing error for flot graph - json

datapie = [
{"label": "Running", "data": [19.5], "color":"#e1ab0b"},
{"label": "Stopped", "data": [4.5], "color":"#fe0000"},
{"label": "Terminated", "data": [36.6], "color":'#93b40f"}
];
Getting an error
TypeError: d is undefined
Please help!!
data is called using ajax

The data doesn't look to be in the correct format. It should look like this:
datapie = [
{label: "Running", data: 19.5, color: '#e1ab0b'},
{label: "Stopped", data: 4.5, color: '#fe0000'},
{label: "Terminated", data: 36.6, color: '#93b40f'}
];
Tutorial - http://digitalunion.osu.edu/2011/12/21/make-graphs-and-charts-with-jquery-using-flot-js-%E2%80%94-a-brief-tutorial/
Fiddle - http://jsfiddle.net/Rnusy/5/

Related

How to create nested object in MongoDB schema, nested object and array MEAN stack

I'm trying to design a nested MongoDB schema.
Currently, I have this schema and it's working:
var CompanySchema = new mongoose.Schema({
name: String,
rate: number
date: Date
})
But I wanna expend it to get:
var CompanySchema = new mongoose.Schema({
name: String,
currency: {
mxn: Number,
php: Number,
},
source: [String],
deliveryMethod: [String],
date: Date
})
For source, I want to get an array of inputs ex. ["bank", "debit card", "agent"]
and almost samething for deliverymethod.
But either my input is wrong or my schema, because the value for source saves as one long string, not a separated value.
Also, I think the way I designed the currency to have more currency rate is correct but I don't know how my input json should suppose to be.
I tried it in postman:
{
"name": "google",
"currency": {
"mxn": 20,
"php": 30
}
}
and this is the result i got:
{
"status": 201,
"data": {
"__v": 0,
"name": "google",
"date": "2017-12-06T22:38:45.896Z",
"_id": "5a2871752e3b7343dc388549",
"deliveryMethod": [
null
],
"source": [
null
]
},
"message": "Succesfully Created Company"
}
1- if my currency nested schema is correct how should be my post json file be?
2- how can I get source and deliveryMethod as an array of string?
The JSON in the request body should look like this:
{
"name": "google",
"currency": {
"mxn": 20,
"php": 30
},
"source": ["source1", "source 2", "source 3"],
"deliveryMethod": ["delMetd 1", "delMetd 2", "delMetd 3"],
"date": "2015-11-27T23:00:00Z"
}
I copy/pasted your code and tried with Postman. The response I got back was:
{
"__v": 0,
"name": "google",
"date": "2015-11-27T23:00:00.000Z",
"_id": "5a2915295c5f714f7cb25d90",
"deliveryMethod": [
"delMetd 1",
"delMetd 2",
"delMetd 3"
],
"source": [
"source1",
"source 2",
"source 3"
],
"currency": {
"mxn": 20,
"php": 30
}
}
If I connect to the database with the mongo shell and run db.companies.find().pretty() I get this result:
{
"_id" : ObjectId("5a2915295c5f714f7cb25d90"),
"name" : "google",
"date" : ISODate("2015-11-27T23:00:00Z"),
"deliveryMethod" : [
"delMetd 1",
"delMetd 2",
"delMetd 3"
],
"source" : [
"source1",
"source 2",
"source 3"
],
"currency" : {
"mxn" : 20,
"php" : 30
},
"__v" : 0
}
Your schema is fine. You can try dropping the collection (db.companies.drop()) if you can't get it to work. Start with a fresh one if you don't have any important data in it.

How to combine columns in spark as a JSON in Scala

I have a variable which is constructed as follows extracting data using Spark SQL:
{
"resourceType" : "Test1",
"count" : 10,
"entry": [{
"id": "112",
"gender": "female",
"birthDate": 1213999
}, {
"id": "urn:uuid:002e27cf-3cae-4393-89c5-1b78050d9428",
"resourceType": "Encounter"
}]
}
I want the output in the following format:
{
"resourceType" : "Test1",
"count" : 10,
"entry" :[
"resource" :{
"id": "112",
"gender": "female",
"birthDate": 1213999
},
"resource" :{
"id": "urn:uuid:002e27cf-3cae-4393-89c5-1b78050d9428",
"resourceType": "Encounter"
}]
}
I am basically new to Scala :), would need help in this.
EDIT: Adding the scala code to create the JSON:
val bundle = endresult.groupBy("id").agg(count("*") as "total",collect_list("resource") as "entry").
withColumn("resourceType", lit("Bundle")).
drop("id").
select(to_json(struct("resourceType","entry"))).
map(row => row.getString(0).
replace("\"entry\":[\"{", "\"entry\":[{").
replace("}\"]}","}]}"). // Should be at the end of the string ONLY (we might switch to regex instead
replace("}\",\"{","},{")
replace("\\\"", "\"")
)

How to input nested json to jquery tokeninput?

I use jquery tokeninput.
A flatted json is no problem to be searched. but howto input nested object.
my code:
var flat_obj = [{id: 7, name: "Ruby"}, {id: 11, name: "Python"}];
var nested_obj = [{ "name": "main", "id": "2", "Parent": "0", "children": [{ "name": "submain", "id": "3", "Parent": "2"}] }];
$("#search-input-local").tokenInput(nested_obj, { });
TokenInput doesn't handle nested JSON, you will need to format the JSON correctly before you pass it to the plugin.
There are a number of libraries to flatten JSON, or take a look at this question here.

Highcharts - Passing in Color with JSON

Currently, I'm using a back end process to create a JSON file for a 3d bar chart with HighCharts.
[{
"name": "Town",
"data": ["NorthCentral","NorthEast","SouthCentral","SouthEast","West"]
}, {
"name": "Population",
"data": [99.47,82,89,82,82]
}]
What I would like know is - can you pass in colors with each data point? for example:
[{
"name": "Town",
"data": ["NorthCentral","NorthEast","SouthCentral","SouthEast","West"]
}, {
"name": "Population",
"data": [{color: 'red',99.47},82,89,82,82]
}]
I have tried already with no luck. This might not be supported but I thought I would ask.
Try something like
data: [{
name: 'Point 1',
color: '#00FF00',
y: 0
}, {
name: 'Point 2',
color: '#FF00FF',
y: 5
}]
A sample with line chart

How to map json data coming from an REST-API to ember.js model?

I'm new to EmberJS and try to connect my EmberJS-frontend to an API via the RESTAdapter. I'm using ember-1.0.0-rc.6 and ember-data-latest (Version: v0.13-59-ge999edb).
From the API I get the following JSON code:
{
"page": 1,
"limit": 5,
"total": 4,
"results": [
{
"id": 1,
"title": "something3",
"description": "asd3"
},
{
"id": 2,
"title": "something3",
"description": "asd3"
},
{
"id": 3,
"title": "something2",
"description": "asd2"
},
{
"id": 4,
"title": "something",
"description": "asd"
}
]
}
My RESTAdapter looks like the following:
App.Store = DS.Store.extend({
revision: 13,
adapter: DS.RESTAdapter.extend({
url:"http://localhost/api/app_dev.php"
})
});
My model looks like this at the moment:
App.Modelname = DS.Model.extend({
title: DS.attr('string')
});
With this I get the following error in the browser console:
Assertion failed: Your server returned a hash with the key page but you have no mapping for it
MY question is how to connect the json output from the api to my ember model without changing the api on the server?
Thanks in advance for your support !
If your model is like this:
App.Modelname = DS.Model.extend({
title: DS.attr('string')
});
Then the RESTAdapter expects a JSON format like this:
{
"modelNames": [
{
"id": 1,
"title": "something3",
"description": "asd3"
},
{
"id": 2,
"title": "something3",
"description": "asd3"
},
{
"id": 3,
"title": "something2",
"description": "asd2"
},
{
"id": 4,
"title": "something",
"description": "asd"
}
]
}
You can of course tweak some of this behavior by configuring some aspects of the JSONSerializer and the RESTAdapter, IMO to have full control I would suggest to create your own adapter by overriding the vital functions like find, findAll etc. and go with plain $.ajax(...). Otherwise you would need to make your backend obey the JSON format ember-data expects.
Hope it helps, at least to take a decision.