jqplot 1 month failing - javascript

For some reason jqplot is not rendering the label correctly and, ultimately, shoving all the line points at the end of the chart. Here is what it looks like...
Here is what it looks like:
Below is the JS including the plot point...
var _a212064_plot_properties;
$(document).ready(function ()
{
_a212064_plot_properties =
{
"legend" :
{
"show" : true
},
"series" : [
{
"label" : "Current Year"
},
{
"label" : "Previous Year"
}
],
"axes" :
{
"xaxis" :
{
"tickOptions" :
{
"formatString" : "%b"
},
"label" : "Date",
"min" : "07\/01\/2012 00:00:00",
"tickInterval" : "1 Month",
"renderer" : $.jqplot.DateAxisRenderer,
"properties" : "xaxis"
},
"yaxis" :
{
"tickRenderer" : $.jqplot.CanvasAxisTickRenderer,
"tickOptions" :
{
"angle" : -30,
"labelPosition" : "middle"
},
"labelRenderer" : $.jqplot.CanvasAxisLabelRenderer,
"labelOptions" :
{
"fontSize" : "13pt"
},
"label" : "Organic Visits",
"properties" : "yaxis"
}
},
"highlighter" :
{
"bringSeriesToFront" : true,
"tooltipLocation" : "n",
"tooltipOffset" : "0",
"formatString" : "Point <\/span>%s: %s<\/strong><\/div>"
},
"cursor" :
{
"show" : true,
"zoom" : true
}
}
$.jqplot.config.enablePlugins = true;
$.jqplot.config.defaultHeight = 300;
$.jqplot.config.defaultWidth = 400;
_a212064 = $.jqplot("a212064", [[[1341115200, 2330], [1343793600, 2768], [1346472000, 2462], [1349064000, 2331], [1351742400, 2198], [1354338000, 2258], [1357016400, 2763], [1359694800, 2399], [1362114000, 2643], [1364788800, 1550], [1367380800, 621], [1370059200, 356]], [[1341115200, 4654], [1343793600, 4105], [1346472000, 4347], [1349064000, 4163], [1351742400, 3849], [1354338000, 5579], [1357016400, 4908], [1359694800, 3690], [1362114000, 2314], [1364788800, 3173], [1367380800, 2608], [1370059200, 2330]]], _a212064_plot_properties);
}
);
Any ideas? Getting the dates into that label is the last thing I can't figure out.
Thanks!

you need to change the parameters for xaxis.
Here is the working copy of your code: Jsfiddle link
var _a212064_plot_properties;
$(document).ready(function ()
{
_a212064_plot_properties =
{
"legend" :
{
"show" : true
},
"series" : [
{
"label" : "Current Year"
},
{
"label" : "Previous Year"
}
],
"axes" :
{
"xaxis" :
{
"label" : "Date",
"renderer" : $.jqplot.DateAxisRenderer
},
"yaxis" :
{
"tickRenderer" : $.jqplot.CanvasAxisTickRenderer,
"tickOptions" :
{
"angle" : -30,
"labelPosition" : "middle"
},
"labelRenderer" : $.jqplot.CanvasAxisLabelRenderer,
"labelOptions" :
{
"fontSize" : "13pt"
},
"label" : "Organic Visits"
}
},
"highlighter" :
{
"bringSeriesToFront" : true,
"tooltipLocation" : "n",
"tooltipOffset" : "0",
"formatString" : "Point <\/span>%s: %s<\/strong><\/div>"
},
"cursor" :
{
"show" : true,
"zoom" : true
}
}
$.jqplot.config.enablePlugins = true;
$.jqplot.config.defaultHeight = 300;
$.jqplot.config.defaultWidth = 400;
_a212064 = $.jqplot("a212064", [[[1341115200, 2330], [1343793600, 2768], [1346472000, 2462], [1349064000, 2331], [1351742400, 2198], [1354338000, 2258], [1357016400, 2763], [1359694800, 2399], [1362114000, 2643], [1364788800, 1550], [1367380800, 621], [1370059200, 356]], [[1341115200, 4654], [1343793600, 4105], [1346472000, 4347], [1349064000, 4163], [1351742400, 3849], [1354338000, 5579], [1357016400, 4908], [1359694800, 3690], [1362114000, 2314], [1364788800, 3173], [1367380800, 2608], [1370059200, 2330]]], _a212064_plot_properties);
}
);

Related

Find and remove nested level

I want to find and remove the value, where my id is "5cc6d9737760963ea07de411"
my data:
[
{
"products" : [ {
"id" : "5cc6d9737760963ea07de411",
"quantity" : 1,
"totalPrice" : 100,
},
{
"id" : "5cc6d9737760963ea07de412",
"quantity" : 2,
"totalPrice" : 200,
}
],
"isCompleted" : false,
"_id" : "5cc7e4096d7c2c1f03570a2f"
},
{
"products" : [{
"id" : "5cc6d9737760963ea07de414",
"quantity" : 1,
"totalPrice" : 100,
},
{
"id" : "5cc6d9737760963ea07de4133",
"quantity" : 2,
"totalPrice" : 200,
}
],
"isCompleted" : false,
"_id" : "5cc7e4096d7c2c1f03570a2f"
}
]
i tried:
Schema.findOneAndUpdate({"products.id": "5cc6d9737760963ea07de411"},
{ $pull: {"products.$.id": "5cc6d9737760963ea07de411" })
but it's not working.
Now you don't need to use .dot notation. Instead you need to use "absolute" object structures:
Schema.findOneAndUpdate(
{ "products.id": "5cc6d9737760963ea07de411" },
{ "$pull": { "products": { "id": "5cc6d9737760963ea07de411" }}}
)

$multiply only supports numeric types, not array

I am trying to use the $multiply operator in MongoDB.
STEP 1
db.message1064sd_00011_3744.aggregate([
{$project : {
"prices.00026" : 1,
priceReal : {
price : "$prices.00026",
}
}},
{ $match : { "priceReal.price" : {$gt : 30 } } },
{ $limit : 1 }
])
I am getting the results
{
"result" : [
{
"_id" : "54884_00011_001",
"prices" : {
"00026" : 34.43
},
"priceReal" : {
"price" : 34.43
}
}
],
"ok" : 1
}
STEP 2
But, when I use $multiply, I get
$multiply only supports numeric types, not array
db.message1064sd_00011_3744.aggregate([
{$project : {
"prices.00026" : 1,
priceReal : {
price : { $multiply : ["$prices.00026", 1 ] },
}
}},
{ $match : { "priceReal.price" : {$gt : 30 } } },
{ $limit : 1 }
])
Help me anybody
Example document which I can get from db.message1064sd_00011_3744.findOne()
{
"_id" : "25906_00011_001",
"Message_ID" : 25906,
"Subdivision_ID" : 3747,
"Sub_Class_ID" : 6300,
"Checked" : 1,
"Nomencl_ID" : "10000014597",
"manufacturer_ID" : "П1170",
"disableIfZero" : 0,
"Discontinued" : 0,
"New" : 0,
"Nomencl_Group_ID" : 28,
"Nalichie" : "Мало",
"sort" : 99,
"Warehouse_ID" : "00011",
"ParentWarehouse_ID" : "00011",
"Kachestvo" : "001",
"Svobod_Nalichie" : "10",
"Svobod_sort" : 10,
"character" : [],
"prices" : {
"00014" : 1.51,
"00015" : 1.45,
"00016" : 1.41,
"00017" : 1.38,
"00018" : 1.35,
"00019" : 1.33,
"00021" : 1.31,
"00022" : 1.29,
"00023" : 1.28,
"00024" : 1.27,
"00025" : 1.25,
"00026" : 1.24
},
"price" : {
"Curr_ID" : 840,
"ChangePriceTime" : "2017-01-22 19:18:21",
"PriceUpDown" : "up",
"callPrice" : 0,
"Price_Value_RODP" : 1.24,
"Price_Value_RUR" : 72.04000000000001
},
"sName" : "чип epson m2300{m2400{mx20 8k (elp, китай)",
"sNomencl_ID" : "10000014597",
"sNomencl_Articul_Proizvod" : "elp-ch-e2300-8k",
"sItemID" : "elp-ch-e2300-8k",
"EnglishName" : "cZ277",
"begin_vl" : 121,
"Hidden_URL" : "/netshop/cZ079/cZ270/cZ277/",
"Checked_Subdivision" : 1
}
In case you want to ensure that only data from a certain data type enters your result set, for example in an aggregate query, you can add the following filter to the match:
{$match: {
// ... your query
, "priceReal.price": { $type : "double" }
}

How to update document in Mongodb collection with a field value from another collection

I have two collections
1) Floorplan_backup.
The structure of the document looks like :-
{
"_id" : ObjectId("5877e18a88db272b578572bd"),
"floorplans" : [
{
"name" : "Campus Center - Atrium",
"uuid" : NumberLong(3),
"cameras" : []
},
{
"name" : "Campus Center - Bridge ",
"uuid" : NumberLong(4),
"cameras" : []
},
{
"name" : "Campus Center - Top",
"uuid" : NumberLong(5),
"cameras" : []
},
{
"name" : "Performance Dining Hall",
"uuid" : NumberLong(6),
"cameras" : []
},
{
"name" : "Main Kitchen",
"uuid" : NumberLong(7),
"cameras" : []
},
{
"name" : "OrgChart - Board of Trustees",
"uuid" : NumberLong(8),
"cameras" : []
},
{
"name" : "OrgChart - Academic Affairs",
"uuid" : NumberLong(9),
"cameras" : []
},
{
"name" : "OrgChart - Admissions",
"uuid" : NumberLong(10),
"cameras" : []
},
{
"name" : "OrgChart - Athletics",
"uuid" : NumberLong(11),
"cameras" : []
},
{
"name" : "OrgChart - Financial",
"uuid" : NumberLong(14),
"cameras" : []
},
{
"name" : "OrgChart - HR",
"uuid" : NumberLong(15),
"cameras" : []
},
{
"name" : "OrgChart - Institutional",
"uuid" : NumberLong(16),
"cameras" : []
},
{
"name" : "OrgChart - IT",
"uuid" : NumberLong(17),
"cameras" : []
},
{
"name" : "OrgChart - Student Success",
"uuid" : NumberLong(20),
"cameras" : []
},
{
"name" : "OrgChart - Student Life",
"uuid" : NumberLong(21),
"cameras" : []
}
],
"userid" : "user-56cb3c4c0c953470865336",
"firstviewhost" : undefined
}
2) Floorplan . The structure of the document
{
"_id" : ObjectId("589025b03422cafc09913363"),
"userid" : "user-56cb3c4c0c953470865336",
"firstviewhost" : "dean.vizsafe.com"
}
I would like to update the firstviewhost in Floorpla_backup with the value "dean.vizsafe.com" by matching the userid of both the collections.
The javascript code used is :-
db.floorplan_backup.find().forEach(function (doc1) {
var doc2 = db.floorplan.find({ userid: doc1.userid }, { firstviewhost: 1 });
if (doc2 != null) {
doc1.firstviewhost = doc2.firstviewhost;
db.floorplan_backup.save(doc1);
}
});
But is is not giving me the desired resultset . Could you let me know what is wrong with this?
doc2 is an array. Use findOne to get an object.
db.floorplan_backup.find().forEach(function (doc1) {
var doc2 = db.floorplan.findOne({ userid: doc1.userid }, { firstviewhost: 1 });
if (doc2 != null) {
doc1.firstviewhost = doc2.firstviewhost;
db.floorplan_backup.save(doc1);
}
});
find returns you a cursor, instead use findOne.
db.floorplan_backup.find().forEach(function (doc1) {
var doc2 = db.floorplan.findOne({ userid: doc1.userid }, { firstviewhost: 1 });
if (doc2 != null) {
doc1.firstviewhost = doc2.firstviewhost;
db.floorplan_backup.save(doc1);
}
});

How select data with given condition

I have following data.
{
"name" : "Maria",
"facebook" : [
{
"data" : "fb.com",
"privacy" : true
}
],
"twitter" : [
{
"data" : "twitter.com",
"privacy" : false
}
],
"google" : [
{
"data" : "google.com",
"privacy" : true
}
],
"phno" : [
{
"data" : "+1-1289741824124",
"privacy" : true
}
]
}
I want to return only data having privacy is equal to true. How do I do it ?
I tried but it returns all data having privacy is equal to false also. How do I query the data ?
Please post MongoDB query not Javascript code.
Thanks!
edit
having structure like this:
{
"_id" : ObjectId("575e4c8731dcfb59af388e1d"),
"name" : "Maria",
"providers" : [
{
"type" : "facebook",
"data" : "fb.com",
"privacy" : true
},
{
"type" : "twitter",
"data" : "twitter.com",
"privacy" : false
},
{
"type" : "google",
"data" : "google.com",
"privacy" : true
},
{
"type" : "phno",
"data" : "+1-1289741824124",
"privacy" : true
}
]
}
with query like this:
db.maria.aggregate([{
$project : {
_id : 1,
name : 1,
"providers" : {
$filter : {
input : "$providers",
as : "p",
cond : {
$eq : ["$$p.privacy", true]
}
}
}
}
}
])
])
we are gaining dynamic output, and we don't need to take care about provider name as this is covered by generic structure
{
"providers" : [
{
"type" : "facebook",
"data" : "fb.com",
"privacy" : true
},
{
"type" : "google",
"data" : "google.com",
"privacy" : true
},
{
"type" : "phno",
"data" : "+1-1289741824124",
"privacy" : true
}
],
"name" : "Maria"
}
end of edit
The way you could get this is using aggregation framework.
As we have an array for each field, we need to unwind it first, then we can use $project to set field value or simply null. As this looks like a simple query, it could give a bit of trouble. The way we can improve that is change a document structure, to have an array of providers and simple providerType field.
Aggregation stages below:
db.maria.find()
var unwindFb = {
$unwind : "$facebook"
}
var unwindtw = {
$unwind : "$twitter"
}
var unwindgo = {
$unwind : "$google"
}
var unwindph = {
$unwind : "$phno"
}
var project = {
$project : {
_id : 1,
name : 1, // list other fields here
facebook : {
$cond : {
if : {
$gte : ["$facebook.privacy", true]
},
then : [{
data : "$facebook.data",
privacy : "$facebook.privacy"
}
],
else : null
}
},
twitter : {
$cond : {
if : {
$gte : ["$twitter.privacy", true]
},
then : [{
data : "$twitter.data",
privacy : "$twitter.privacy"
}
],
else : null
}
},
google : {
$cond : {
if : {
$gte : ["$google.privacy", true]
},
then : [{
data : "$google.data",
privacy : "$google.privacy"
}
],
else : null
}
},
phno : {
$cond : {
if : {
$gte : ["$phno.privacy", true]
},
then : [{
data : "$phno.data",
privacy : "$phno.privacy"
}
],
else : null
}
}
}
}
db.maria.aggregate([unwindFb, unwindtw, unwindgo, unwindph, project])
then output looks like this:
{
"_id" : ObjectId("575df49d31dcfb59af388e1a"),
"name" : "Maria",
"facebook" : [
{
"data" : "fb.com",
"privacy" : true
}
],
"twitter" : null,
"google" : [
{
"data" : "google.com",
"privacy" : true
}
],
"phno" : [
{
"data" : "+1-1289741824124",
"privacy" : true
}
]
}
you can use the below code to iterate the object and check for the privacy true
var list = {
"name" : "Maria",
"facebook" : [
{
"data" : "fb.com",
"privacy" : true
}
],
"twitter" : [
{
"data" : "twitter.com",
"privacy" : false
}
],
"google" : [
{
"data" : "google.com",
"privacy" : true
}
],
"phno" : [
{
"data" : "+1-1289741824124",
"privacy" : true
}
]
}
$.each(Object.keys(list), function(index,value){
if(list[value][0].privacy)
{
console.log(list[value][0]);
}
});
If you are open to use lodash ...this is how you can do it...
var tmp = {
...you json here
}
var res =[];//result array of filtered data
_.forIn(tmp, function (o) {
if (Array.isArray(o)) {
if (o[0].privacy === true) {
res.push(o);
}
}
});

unable to fetch value from JSON array in javascript

I'm unable to fetch JSON value to check if the person is wearing glasses while taking photo, the value relies in four arrays: photos, tags, attributes and glasses, I want to check the value "value" is true or false. I use alert() to test if value fetched but nothing comes out. I don't know which part gets wrong
I use JavaScript to fetch the JSON value as follows:
var facesDet = $.getJSON( APIdetect, function() {
console.log( "success" );
console.log(facesDet);
})
.done(function (facesDet, tid) {
var VALUEIWANT = facesDet.photos[0].tags[0].attributes[0].gender[0].value;
});
The JSON value looks as follows:
{
"photos" : [
{
"url" : "http://tinyurl.com/673cksr",
"pid" : "F#0c95576847e9cd7123f1e304476b59ae_59ec9bb2ad15f",
"width" : 375,
"height" : 409,
"tags" : [
{
"tid" : "TEMP_F#0c95576847e9cd7123f1e304b1dcbe53_59ec9bb2ad15f_56.53_40.83_0_1",
"recognizable" : true,
"confirmed" : false,
"manual" : false,
"width" : 30.67,
"height" : 28.12,
"center" : { "x" : 56.53, "y" : 40.83},
"eye_left" : { "x" : 66.93, "y" : 33.99},
"eye_right" : { "x" : 51.73, "y" : 33.99},
"yaw" : -16,
"roll" : 0,
"pitch" : 0,
"attributes" : {
"face" : { "value" : "true", "confidence" : 82 },
"gender" : { "value" : "female", "confidence" : 80 },
"glasses":{"value" : "true", "confidence" : 100},
"dark_glasses":{"value" : "true", "confidence" : 72},
"smiling":{"value" : "false", "confidence" : 35}
}
}
]
}
],
"status" : "success",
"usage" : {
"used" : 1,
"remaining" : 99,
"limit" : 100,
"reset_time_text" : "Fri, 21 September 2012 12:57:19 +0000",
"reset_time" : 1348232239
}
}
You tryed to take value from gender like from array:
var VALUEIWANT = facesDet.photos[0].tags[0].attributes[0].gender[0].value;
But in your json its object, so you should use:
var VALUEIWANT = facesDet.photos[0].tags[0].attributes.gender.value;
Your access is wrong. You have an object, but you treat it like an array
var VALUEIWANT = facesDet.photos[0].tags[0].attributes[0].gender[0].value;
// ^^^ and ^^^
right access:
var VALUEIWANT = facesDet.photos[0].tags[0].attributes.gender.value;
data:
"attributes" : {
"face" : { "value" : "true", "confidence" : 82 },
"gender" : { "value" : "female", "confidence" : 80 },
"glasses":{"value" : "true", "confidence" : 100},
"dark_glasses":{"value" : "true", "confidence" : 72},
"smiling":{"value" : "false", "confidence" : 35}
}
try this one.
facesDet.photos[0].tags[0].attributes.gender.value
getJSON return a promise not the response, you need to use this code:
$.getJSON( APIdetect, function(facesDet) {
console.log( "success" );
console.log(facesDet);
})

Categories