I want to create a line graph like below fiddle,
http://jsfiddle.net/wRDXt/2/
Here the date is used as new Date(2013, 17, 1).
I have json contents as follows,
[{
"_id": "bb68d8a2-8778-4c85-8616-ed1e96a61ea6",
"FLAG": "public",
"STATUS": "active",
"DESCRIPTION": "df",
"DATE_TIME": "04-10-2016 16:39:39",
"TOKEN": "bge2jb",
"LAST_UPDATED": "Tue Oct 04 16:39:39 IST 2016"
},
{
"_id": "556ae8ad-7291-4303-a9e4-618a82694600",
"FLAG": "public",
"STATUS": "active",
"DESCRIPTION": "d",
"DATE_TIME": "04-10-2016 16:52:20",
"TOKEN": "16l4jal",
"LAST_UPDATED": "Tue Oct 04 16:52:20 IST 2016"
},
{
"_id": "98db36ba-392d-4df2-ac6c-820eaf582a11",
"FLAG": "public",
"STATUS": "active",
"DESCRIPTION": "uyk",
"DATE_TIME": "07-10-2016 12:13:10",
"TOKEN": "dfl5ja",
"LAST_UPDATED": "Fri Oct 07 12:13:10 IST 2016"
}]
My date format, which came from api call is like 07-10-2016 12:13:10 or Fri Oct 07 12:13:10 IST 2016.
If I pass this date, I am getting following error in console,
Uncaught TypeError: minDate.getDate is not a function
How do I pass my date to this and get the graph.
My fiddle is http://jsfiddle.net/wRDXt/190/
The date in your dataset is not a date-object, but a string. Therefore it does not have a getDate()-function and you get the error you get.
To fix this, right after you have declared your dataset, loop through all entries in the dataset and redefine date by parsing the date-string:
dataset.forEach(function(d) {
d.date = d3.time.format("%d-%m-%Y %H:%M:%S").parse(d.date);
});
See fiddle: http://jsfiddle.net/wRDXt/204/
Reference for d3.time.format
Related
How to know if the objects exist in postman like below, i want to check all the parameters. if all of them are returned properly
[
{
"id": "MnnRVEifcngi2",
"givenName": "Witting and Sons",
"logo": "http://lorempixel.com/640/480/business",
"createdAt": "Fri Jan 05 2018 07:54:09 GMT+0000 (UTC)",
"updatedAt": "Tue Oct 23 2018 22:25:54 GMT+0000 (UTC)",
"tags": [
"Web",
"Paradigm"
]
},
{
"id": "E7z9UujhROF2L",
"givenName": "Block Group",
"logo": "http://lorempixel.com/640/480/business",
"createdAt": "Mon Feb 05 2018 11:50:00 GMT+0000 (UTC)",
"updatedAt": "Wed Oct 24 2018 13:29:35 GMT+0000 (UTC)",
"tags": [
"Brand",
"Web"
]
},
{
"id": "MzbqnzFImpbkf",
"givenName": "Dickinson - Ziemann",
"logo": "http://lorempixel.com/640/480/business",
"createdAt": "Fri Feb 02 2018 07:00:32 GMT+0000 (UTC)",
"updatedAt": "Tue Oct 23 2018 18:11:30 GMT+0000 (UTC)",
"tags": [
"Applications"
]
},
{
"id": "3-vqC_QG5Up8r",
"givenName": "Lindgren - Mitchell",
"logo": "http://lorempixel.com/640/480/business",
"createdAt": "Sun May 06 2018 07:24:02 GMT+0000 (UTC)",
"updatedAt": "Wed Oct 24 2018 10:10:23 GMT+0000 (UTC)",
"tags": [
"Branding",
"Mobility",
"Functionality"
]
},
{
"id": "8dUhM_0j5vloD",
"givenName": "Schmitt LLC",
"logo": "http://lorempixel.com/640/480/business",
"createdAt": "Wed Sep 12 2018 01:16:49 GMT+0000 (UTC)",
"updatedAt": "Wed Oct 24 2018 03:40:15 GMT+0000 (UTC)",
"tags": [
"Accounts",
"Data"
]
},
{
"id": "zl_43QRBDWBnW",
"givenName": "Barton - Bauch",
"logo": "http://lorempixel.com/640/480/business",
"createdAt": "Tue Dec 05 2017 14:12:00 GMT+0000 (UTC)",
"updatedAt": "Tue Oct 23 2018 19:36:52 GMT+0000 (UTC)",
"tags": [
"Response",
"Accountability",
"Identity"
]
},
{
"id": "kxgqxbXBS53_2",
"givenName": "Lind Inc",
"logo": "http://lorempixel.com/640/480/business",
"createdAt": "Tue May 22 2018 16:37:33 GMT+0000 (UTC)",
"updatedAt": "Wed Oct 24 2018 06:35:53 GMT+0000 (UTC)",
"tags": [
"Communications",
"Brand"
]
},
{
"id": "xWAIuoDY5icIl",
"givenName": "Gutkowski - Hickle",
"logo": "http://lorempixel.com/640/480/business",
"createdAt": "Tue Jun 19 2018 21:29:59 GMT+0000 (UTC)",
"updatedAt": "Wed Oct 24 2018 14:02:39 GMT+0000 (UTC)",
"tags": [
"Metrics",
"Infrastructure",
"Accounts"
]
}
]
This is what i am trying but getting an error:
const jsonData = pm.response.json();
pm.test('Has data', function() {
pm.expect(jsonData).to.have.property('id');
});
I want to verify - id, givenName, logo, createdAt, UpdatedAt, tags and all are present and want to make a global function so in other tests I can just call it once
To fix your error, try to loop through your array of object i.e jsonData like below. By the way I didn't play with postman global function creation. Hope this link will help you on how to make/use it as global How to Write Global Functions in Postman
pm.test('Has data', () => {
jsonData.forEach(row => {
pm.expect(row).to.have.property('id');
pm.expect(row).to.have.property('givenName');
pm.expect(row).to.have.property('logo');
pm.expect(row).to.have.property('createdAt');
pm.expect(row).to.have.property('updatedAt');
pm.expect(row).to.have.property('tags');
})
});
For checking all parameters in response you should consider using built-in tv4.validate, which stands for Tiny Validator (for v4 JSON Schema) - it validates simple values and complex objects against provided schema.
In your particular case you would do something like this:
const jsonData = pm.response.json();
const schema = {
items: {
type: "object",
properties: {
id: {type: "string"},
givenName: {type: "string"},
logo: {type: "string"},
createdAt: {type: "string"},
updatedAt: {type: "string"},
tags: {type: "array"}
},
required:["id","givenName","logo", "createdAt", "updatedAt", "tags"]
}
};
pm.test('Schema is valid', () => pm.expect(tv4.validate(jsonData, schema)).to.be.true);
More examples of how to use tv4 can be found in its repo.
I have RethinkDB with data/table let say "news" with huge number of data row :
[
{
"author": "author1",
"category_id": "business",
"country": "id",
"created_at": "Wed Aug 15 2018 09:26:52 GMT+07:00",
"description": "description",
"id": "74c25662-7f94-47ef-8a7e-5091924819a9"
},
{
"author": "author2",
"category_id": "business",
"country": "id",
"created_at": "Wed Aug 15 2018 09:26:52 GMT+07:00",
"description": "description2",
"id": "74c25662-7f94-47ef-8a7e-5091924819a9"
},
{
"author": "author3",
"category_id": "sport",
"country": "id",
"created_at": "Wed Aug 15 2018 09:26:52 GMT+07:00",
"description": "description3",
"id": "74c25662-7f94-47ef-8a7e-5091924819a9"
},
{
"author": "author3",
"category_id": "business",
"country": "id",
"created_at": "Wed Aug 15 2018 09:26:52 GMT+07:00",
"description": "description4",
"id": "74c25662-7f94-47ef-8a7e-5091924819a9"
}
.....
]
I need to create index for category_id and created_at (timestamp) and query for certain category and filter by day now (certain date) only. I want to optimize and speed up for query result
I can do it in javascript by filter like this for category_id business and day 15 :
r.table("news").filter({category_id: 'business'}).filter(
r.row("created_at").day().eq(15)
)
But how I can create index for category_id and created_at and query it by certain day of created_at.
r.table("news").indexCreate( ???
thanks
Should be something like this:
r.table('news').indexCreate('businessAndDate', function (doc) {
return doc('category_id').add(doc('created_at').day().coerceTo('string'));
});
Then you can:
r.table('news').getAll('business15', {index: 'businessAndDate'})
You may want to insert a separator between the data (like 'business-15'), and use more than just the day (otherwise, why bother having a full timestamp?), that's up to you and how many .add you're willing to write. ;)
According to the reference, this is called an arbitrary index.
This question already has answers here:
Find object by id in an array of JavaScript objects
(36 answers)
Closed 4 years ago.
This is my JSON object and I need to check for a particular id and get the date
[
{
"id": "9b3b835b",
"date": "Tue Mar 27 10:23:18 UTC 2018"
},
{
"id": "57eab193",
"date": "Thu Mar 29 14:45:23 UTC 2018"
},
{
"id": "440f0cd9",
"date": "Thu Mar 29 15:12:00 UTC 2018"
},
]
yourVariable = [{
"id": "9b3b835b",
"date": "Tue Mar 27 10:23:18 UTC 2018"
},
{
"id": "57eab193",
"date": "Thu Mar 29 14:45:23 UTC 2018"
},
{
"id": "440f0cd9",
"date": "Thu Mar 29 15:12:00 UTC 2018"
},
];
for (keys in yourVariable) {
// supposing id your are looking for is 57eab193
if (yourVariable[keys].id == '57eab193') {
console.log(yourVariable[keys].date)
}
}
You can use the function find to get a specific according to a condition.
This alternative uses the logical operator || just to avoid access error over an undefined value.
var array = [{
"id": "9b3b835b",
"date": "Tue Mar 27 10:23:18 UTC 2018"
},
{
"id": "57eab193",
"date": "Thu Mar 29 14:45:23 UTC 2018"
},
{
"id": "440f0cd9",
"date": "Thu Mar 29 15:12:00 UTC 2018"
},
];
var date = (array.find(o => o.id === "440f0cd9") || {}).date;
console.log(date);
date = (array.find(o => o.id === "ele") || {}).date;
console.log(date);
I have a json object as follows.
[{
"id": "1",
"username": "vishnu",
"FromDate": "Thu Apr 21 2016 10:56:45 GMT+0530 (India Standard Time)",
"selectedProject": "createwhimsy",
"task": "fixing bugs",
"time": "1"
}, {
"id": "2",
"username": "vishnu",
"FromDate": "Wed Mar 02 2016 10:56:45 GMT+0530 (India Standard Time)",
"selectedProject": "createwhimsy",
"task": "working on ui of creatwhimsy home page",
"time": "2"
}, {
"id": "3",
"username": "vishnu",
"FromDate": "Wed Mar 02 2016 10:56:45 GMT+0530 (India Standard Time)",
"selectedProject": "bigiron",
"task": "working on api",
"time": "5"
}, {
"id": "4",
"username": "vishnu",
"FromDate": "Sat Jul 30 2016 12:03:20 GMT+0530 (India Standard Time",
"selectedProject": "timetracker",
"task": "working on ui of creatwhimsy home page and admin side home page",
"time": "1"
}, {
"id": "5",
"username": "vishnu",
"FromDate": "Wed Jan 02 2016 10:56:45 GMT+0530 (India Standard Time)",
"selectedProject": "createwhimsy",
"task": "fixing bugs",
"time": "1"
}]
Let the object name be Data. I want to make a new object fro Data, but it should only contain "selectedProject" and "time".
How to do that in angularjs?
You can iterate and create a new object with desire data. For this you can use javascript push() function.
what you need to do is
$scope.log = [];
angular.forEach($scope.names, function(value, key){
$scope.log.push({"selectedProject":value.selectedProject,"time":value.time});
});
Here is JS fiddle: http://jsfiddle.net/kyaqzgo6/4/
A sample code for you:
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.names = [{
"id": "1",
"username": "vishnu",
"FromDate": "Thu Apr 21 2016 10:56:45 GMT+0530 (India Standard Time)",
"selectedProject": "createwhimsy",
"task": "fixing bugs",
"time": "1"
}, {
"id": "2",
"username": "vishnu",
"FromDate": "Wed Mar 02 2016 10:56:45 GMT+0530 (India Standard Time)",
"selectedProject": "createwhimsy",
"task": "working on ui of creatwhimsy home page",
"time": "2"
}, {
"id": "3",
"username": "vishnu",
"FromDate": "Wed Mar 02 2016 10:56:45 GMT+0530 (India Standard Time)",
"selectedProject": "bigiron",
"task": "working on api",
"time": "5"
}, {
"id": "4",
"username": "vishnu",
"FromDate": "Sat Jul 30 2016 12:03:20 GMT+0530 (India Standard Time",
"selectedProject": "timetracker",
"task": "working on ui of creatwhimsy home page and admin side home page",
"time": "1"
}, {
"id": "5",
"username": "vishnu",
"FromDate": "Wed Jan 02 2016 10:56:45 GMT+0530 (India Standard Time)",
"selectedProject": "createwhimsy",
"task": "fixing bugs",
"time": "1"
}];
$scope.log = [];
angular.forEach($scope.names, function(value, key){
$scope.log.push({"selectedProject":value.selectedProject,"time":value.time});
});
console.log($scope.log);
});
</script>
Try something like this:
function SomeFunction() {
function getdata(callback, url) {
var obj= {};
$http.get(url).success(function(response) {
if (response.jsonname[0].length > 0) {
for (var i = 0; i < response.jsonname[0].length; i++) {
obj= {
selectedProject:response.jsonname[0][i].selectedProject,
time:response.jsonname[0][i].time
}
}
} else {
}
}).error(function() {
//something
}).then(function() {
callback(obj);
});;
}
return {
getdata: getdata
}
}
I need to access temperature and append it to my page If these are all objects then I suppose I cant use an index since the order doesnt matter, which is throwing me off.
{
"response": {
"version": "0.1",
"termsofService": "http://www.wunderground.com/weather/api/d/terms.html",
"features": {
"conditions": 1
}
},
"current_observation": {
"image": {
"url": "http://icons-ak.wxug.com/graphics/wu2/logo_130x80.png",
"title": "Weather Underground",
"link": "http://www.wunderground.com"
},
"display_location": {
"full": "Toms River, NJ",
"city": "Toms River"
},
"observation_location": {
"full": "Stonehedge, Toms River, New Jersey",
"city": "Stonehedge, Toms River",
"state": "New Jersey",
"country": "US"
},
"estimated": {},
"station_id": "KNJTOMSR5",
"observation_time": "Last Updated on April 11, 10:56 PM EDT",
"observation_time_rfc822": "Fri, 11 Apr 2014 22:56:39 -0400",
"observation_epoch": "1397271399",
"local_time_rfc822": "Fri, 11 Apr 2014 22:56:40 -0400",
"local_epoch": "1397271400",
"local_tz_short": "EDT",
"local_tz_long": "America/New_York",
"local_tz_offset": "-0400",
"weather": "Clear",
**"temperature_string": "59.6 F (15.3 C)"**
}
}
My javascript right now is plainly this since I havent figured out how to access this item yet
$(function() {
$("#getzip").submit(function() {
var zip_data =$(this).serialize();
$.getJSON("get_weather.php",null, function(data); {
I need to append this to the dom of my page, I think it shouldlook something like this?
(#output).append(data.temperature_string);
To get json object into javascript.
Use like this.
In Php
$json ='{"temperature":"36 c"}';
In Javascript
$.post("get_weather.php",null, function(data){
var temperature = data.temperature; // here you'll get temperature from json into variable
console.log(temperature);
},"json");
That's all
console.log(data["temperature_string"]) should access to that data.