flot graph not working on ie11 - datetime

My flot graph is rendering fine on firefox and chrome, however on ie11 it does not render. the graph appears with no datapoints.
var options = {
"xaxis" : {
"mode" : "time",
"timeformat" : "%d/%m",
//"tickSize" : [1, "day"]
},
"yaxes" : [{
"position" : "left",
//"tickSize" : 1,
"min" : min,
"max" : 100
}, {
"position" : "right",
"min" : 0,
"max" : max
}
],
"series" : {
"lines" : {
"show" : true
},
curvedLines: {
apply: true,
}
},
"colors" : ["#00ff00"],
"legend" : {
"show" : false
},
"grid" : {
hoverable: true,
clickable: true
}//,
//animator: { start: 100, steps: 99, duration: 2000, direction: "left" }
};
var data_ajax = [{
"color" : "#A8B400",
"label" : "R1 Graph",
"lines" : {
"show" : true,
"lineWidth" : 1
},
"points" : {
"show" : false
},
"yaxis" : 1,
"data" : arr
}
];
$('#network-graph').empty();
plot = $.plot("#network-graph", data_ajax, options);
Problem I found was with the data_ajax variable. it contained objects with wrong format. The time format i had to use for IE11 fix is as follows
var to_seconds = moment(data[i].TIMESTAMP, 'YYYY-MM-DD hh:mm A').unix() * 1000;
I wasn't specifying a format previously. Is there a universal date time format I can use for all browsers?

Related

DevExtreme: Return Object from Spring Rest Api does not bind with dxDataGrid

Could any one help me how could I bind data object with DevExtreme's dxDataGrid using customstore.
My DTO is like:
[
data: {...},
totalCount: 100,
summary: [10,20,30]
]
But when i bind the data with dxDataGrid it just bind data but not totalCount.
I have found a solution for my problem.
[remoteOperations]="true"
I need remoteOperations = true to bind the totalCount along with data fetched from the server.
You don't need to send a totalCount, you have to use the summary section istead, look at this sample
$("#gridContainer").dxDataGrid({
dataSource: orders,
keyExpr: "ID",
showBorders: true,
selection: {
mode: "single"
},
columns: [{
dataField: "OrderNumber",
width: 130,
caption: "Invoice Number"
}, {
dataField: "OrderDate",
dataType: "date",
width: 160
},
"Employee", {
caption: "City",
dataField: "CustomerStoreCity"
}, {
caption: "State",
dataField: "CustomerStoreState"
}, {
dataField: "SaleAmount",
alignment: "right",
format: "currency"
}
],
summary: {
totalItems: [{
column: "OrderNumber",
summaryType: "count"
}]
}
});
Data Source
var orders = [{
"ID" : 1,
"OrderNumber" : 35703,
"OrderDate" : "2014-04-10",
"SaleAmount" : 11800,
"Terms" : "15 Days",
"TotalAmount" : 12175,
"CustomerStoreState" : "California",
"CustomerStoreCity" : "Los Angeles",
"Employee" : "Harv Mudd"
}, {
"ID" : 4,
"OrderNumber" : 35711,
"OrderDate" : "2014-01-12",
"SaleAmount" : 16050,
"Terms" : "15 Days",
"TotalAmount" : 16550,
"CustomerStoreState" : "California",
"CustomerStoreCity" : "San Jose",
"Employee" : "Jim Packard"
}....
]
For custom summaries you can use this
summary: {
totalItems: [{
name: "SelectedRowsSummary",
showInColumn: "SaleAmount",
displayFormat: "Sum: {0}",
valueFormat: "currency",
summaryType: "custom"
}
],
calculateCustomSummary: function (options) {
if (options.name === "SelectedRowsSummary") {
if (options.summaryProcess === "start") {
options.totalValue = 0;
}
if (options.summaryProcess === "calculate") {
if (options.component.isRowSelected(options.value.ID)) {
options.totalValue = options.totalValue + options.value.SaleAmount;
}
}
}
}
}
In the section if (options.summaryProcess === "calculate") { you can put your custom calc logic, in this case your total count.

Highcharts: displaying datetime like categories

I'm trying to achieve something like this: example.
I want to display labels for xAxis like in categories: in Month day-day format. Is it possible to achieve it with 'datetime' type?
This is my xAxis configuration:
{
"type" : "datetime",
"crosshair" : false,
"visible" : true,
"labels" : {
"enabled" : true,
"padding" : 10
},
"minTickInterval" : 86400000,
"tickLength" : 10,
"min" : 1507759200000,
"max" : 1523311199999
}
You can try setting xAxis.labels.x offset when xAxis.showLastLabel is disabled:
var chart = Highcharts.chart('container', {
chart: {
width: 700
},
xAxis: {
type: 'datetime',
labels: {
x: 150
},
showLastLabel: false
},
series: [{
data: [
[Date.UTC(2018, 0), 1],
[Date.UTC(2018, 1), 2],
[Date.UTC(2018, 2), 2]
]
}]
});
Live demo: http://jsfiddle.net/BlackLabel/0bk79bpz/
API references:
https://api.highcharts.com/highcharts/xAxis.labels.x
https://api.highcharts.com/highcharts/xAxis.showLastLabel

How to count orders with positions unwind in MongoDB aggregation?

I have a collection with order headers and positions (as array) and I need an query which should give me:
quantity of customers
quantity of orders
summed up order value
all grouped by date and order type. I already got this covered by two queries (see below), but I want to have it in one.
The main problem to me is that I need to count the orders but with positions unwinded.
E.g.: Below would be a possible result of the combined query with the test data below:
/* 1 */
{
"_id" : {
"typ" : "WERBUNG",
"date" : "2017-07-08"
},
"orderQuantity" : 1.0,
"value" : 1000,
"customerQuantity" : 1
}
/* 2 */
{
"_id" : {
"typ" : "WERBUNG",
"date" : "2017-07-07"
},
"orderQuantity" : 2.0,
"value" : 100,
"customerQuantity" : 1
}
/* 3 */
{
"_id" : {
"typ" : "ANDERE",
"date" : "2017-07-08"
},
"orderQuantity" : 4.0,
"value" : 1500,
"customerQuantity" : 4
}
/* 4 */
{
"_id" : {
"typ" : "ANDERE",
"date" : "2017-07-07"
},
"orderQuantity" : 1.0,
"value" : 90,
"customerQuantity" : 1
}
... this would mean:
On 7-7 there where 3 orders (WERBUNG 2, ANDERE 1) for only 1 customer (WERBUNG 1, ANDERE 1 - will be counted twice here, bit this would be okay)
On 8-7 there where 5 orders (WERBUNG 1, ANDERE 4) for 5 customers (WERBUNG 4, ANDERE 1)
I have an idea that SortBy would help here, however we still use 3.2 - so no access to this stage (and some other usefull options as well...).
Cheers!
--
Some information which might help:
// Here are the sample orders:
/*1*/
{
"_id" : ObjectId("596075d5be8fc415341c7d43"),
"header" : {
"kundennummer" : "820130",
"auftragsdatum" : 0,
"bestellangaben" : "BLOCK1",
"information1" : "blocktest",
"erstellungsdatum" : 1499493785.25906,
"vorgabeauftragsnummer" : 87475000,
},
"ordertype" : "BLOCK1",
"customernnummer" : "820130",
"ordernumber" : 87475000,
"positions" : [
"artikelnummer" : 1985900,
"menge" : 1,
"bruttopreis" : 1000,
"_id" : ObjectId("596075d5be8fc415341c7d45")
}
],
"date" : "2017-07-08",
"type" : "WERBUNG"
}
/*2*/
{
"_id" : ObjectId("59608f64be8fc415341c7d46"),
"header" : {
"kundennummer" : "944867",
"auftragsdatum" : 0,
"bestellangaben" : "",
"information1" : "blocktest",
"erstellungsdatum" : 1499500356.10022,
"vorgabeauftragsnummer" : 87475001,
},
"ordertype" : "",
"customernnummer" : "944867",
"ordernumber" : 87475001,
"positions" : [
{
"artikelnummer" : 4029300,
"menge" : 1,
"bruttopreis" : 100,
"_id" : ObjectId("59608f64be8fc415341c7d5c")
}
],
"date" : "2017-07-08",
"type" : "ANDERE"
}
/*3*/
{
"_id" : ObjectId("5960925ebe8fc415341c7d5d"),
"header" : {
"kundennummer" : "981927",
"auftragsdatum" : 0,
"bestellangaben" : "",
"information1" : "blocktest",
"erstellungsdatum" : 1499501036.34265,
"vorgabeauftragsnummer" : 87475002,
},
"ordertype" : "",
"customernnummer" : "981927",
"ordernumber" : 87475002,
"positions" : [
},
"artikelnummer" : 4557300,
"menge" : 2,
"bruttopreis" : 100,
"_id" : ObjectId("5960925ebe8fc415341c7d74")
}
],
"date" : "2017-07-08",
"type" : "ANDERE"
}
/*4*/
{
"_id" : ObjectId("5960925ebe8fc415341c7d75"),
"header" : {
"kundennummer" : "981927",
"auftragsdatum" : 0,
"bestellangaben" : "BLOCK2",
"information1" : "blocktest",
"erstellungsdatum" : 1499414714,
"vorgabeauftragsnummer" : 87475003,
},
"ordertype" : "BLOCK2",
"customernnummer" : "981927",
"ordernumber" : 87475003,
"positions" : [
{ "artikelnummer" : 7081200,
"menge" : 3,
"bruttopreis" : 10,
"_id" : ObjectId("5960925ebe8fc415341c7d8f")
}
],
"date" : "2017-07-07",
"type" : "WERBUNG"
}
/*5*/
{
"_id" : ObjectId("596093ebbe8fc415341c7d90"),
"header" : {
"kundennummer" : "962422",
"auftragsdatum" : 0,
"bestellangaben" : "",
"information1" : "blocktest",
"erstellungsdatum" : 1499501507.75201,
"vorgabeauftragsnummer" : 87475004,
},
"ordertype" : "",
"customernnummer" : "962422",
"ordernumber" : 87475004,
"positions" : [
"artikelnummer" : 3545900,
"menge" : 4,
"bruttopreis" : 100,
"_id" : ObjectId("596093ebbe8fc415341c7d95")
}
],
"date" : "2017-07-08",
"type" : "ANDERE"
}
/*6*/
{
"_id" : ObjectId("596098e9be8fc415341c7ddf"),
"header" : {
"kundennummer" : "981927",
"auftragsdatum" : 0,
"bestellangaben" : "BLOCK3",
"information1" : "blocktest",
"erstellungsdatum" : 1499415886,
"vorgabeauftragsnummer" : 87475007,
},
"ordertype" : "BLOCK3",
"customernnummer" : "981927",
"ordernumber" : 87475007,
"positions" : [
{
"artikelnummer" : 1006199,
"menge" : 7,
"bruttopreis" : 10,
"_id" : ObjectId("596098e9be8fc415341c7de6")
}
],
"date" : "2017-07-07",
"type" : "WERBUNG"
}
/*7*/
{
"_id" : ObjectId("59609a47be8fc415341c7de7"),
"header" : {
"kundennummer" : "981225",
"auftragsdatum" : 0,
"bestellangaben" : "",
"information1" : "blocktest",
"erstellungsdatum" : 1499503113.21714,
},
"ordertype" : "",
"customernnummer" : "981225",
"ordernumber" : 87475008,
"positions" : [
{
"_id": ObjectId("59609a47be8fc415341c7e0d")
"artikelnummer" : 2308400,
"menge" : 8,
"bruttopreis" : 100,
}
],
"date" : "2017-07-08",
"type" : "ANDERE"
}
/*8*/
{
"_id" : ObjectId("59609a47be8fc415341c7e0e"),
"header" : {
"vorgabeauftragsnummer" : 87475009,
"erstellungsdatum" : 1499416697,
"information1" : "blocktest",
"bestellangaben" : "",
"auftragsdatum" : 0,
"kundennummer" : "981927",
},
"ordertype" : "",
"customernnummer" : "981927",
"ordernumber" : 87475009,
"positions" : [
"_id" : ObjectId("59609a47be8fc415341c7e57"),
"bruttopreis" : 10,
"menge" : 9,
"artikelnummer" : 8017000
}
],
"date" : "2017-07-07",
"type" : "ANDERE"
}
// Query 1: Quantity of customers and order value by order type (WERBUNG, ANDERE) and day
db.getCollection('orders').aggregate([
{$unwind:"$positions"},
{$project: {
"_id": 1,
customer: "$header.customernnummer",
date: {$}ToString: {format: "%d-%m-%Y", }: {"$add":[ new }(0), {"$multiply": [1000, "$header.erstellungsdate"]}]} }},
edate: "$header.erstellungsdate",
ordertype: "$header.ordertype",
type: {$cond: { if: {$ne: ["$header.ordertype" ,""]} , then: "WERBUNG", else: "ANDERE" }},
value: {$multiply: ["$positions.price","$positions.quantity"]},
}
},
{$group: {
_id: {type: "$type", tag: "$date",customer: "$customer" },
type: {$first: "$type"},
date: {$first: "$date"},
wert: {$sum: "$value" }
}
},
{$project:{
_id : 0,
customer: "$customer",
type: "$type",
date: "$date",
wert: "$wert"
}
}
,{$group: {
_id: {typ: "$type", date: "$date"}, customerQuantity:{$sum:1},
value: {$sum: "$wert"}
}
},
{$sort:{
typ: 1, date: -1
}
}
]}
// Query 2: Order quantity by type, date
...
{$project: {
block: {$cond: { if: {$ne: ["$auftragskopf.bestellangaben" ,""]} , then: "WERBUNG", else: "ANDERE" }},
datum: {$dateToString: {format: "%d-%m-%Y", date: {"$add":[ new Date(0), {"$multiply": [1000, "$auftragskopf.erstellungsdatum"]}]} }},
}
},
{$group:{
_id: {block: "$block", datum: "$datum"},
auftragsanzahl:{$sum:1},
}
},
I'm not sure about how your data looks like, but I understand from this line
type: {$cond: { if: {$ne: ["$header.ordertype" ,""]} , then: "WERBUNG", else: "ANDERE" }}
that if your $header.ordertype is WERBUNG then you want your order type to be WERBUNG otherwise its ANDERE. With that in mind here is my solution.
db.getCollection('orders').aggregate([
{
$project: {
"_id": 1,
header: 1,
positions: 1,
date: {
$dateToString: {
format: "%Y-%m-%d",
date: {
"$add": [new Date(0), {
"$multiply": [1000, "$header.date"]
}]
}
}
},
type: {
$cond: {
if: {
$eq: ["$header.ordertype", "WERBUNG"]
},
then: "WERBUNG",
else: "ANDERE"
}
}
}
},
{
$group: {
_id: {
type: "$type",
date: "$date"
},
werbungCount: {
$sum: {
$cond: [{
$eq: ['$type', 'WERBUNG']
}, 1, 0]
}
},
andereCount: {
$sum: {
$cond: [{
$eq: ['$type', 'ANDERE']
}, 1, 0]
}
},
customer: {
$first: "$header.customernnummer"
},
date: {
$first: "$date"
},
type: {
$first: "$type"
},
positions: {
$first: "$positions"
}
}
},
{
$unwind: "$positions"
},
{
$project: {
"_id": 1,
customer: "$customer",
date: 1,
ordertype: "$header.ordertype",
type: "$type",
value: {
$multiply: ["$positions.price", "$positions.quantity"]
},
price: "$positions.price",
quantity: "$positions.quantity",
orderQuantity: {
$cond: {
if: {
$eq: ["$type", "WERBUNG"]
},
then: "$werbungCount",
else: "$andereCount"
}
},
}
},
{
$group: {
_id: {
type: "$type",
tag: "$date",
customer: "$customer"
},
type: {
$first: "$type"
},
date: {
$first: "$date"
},
wert: {
$sum: "$value"
},
orderQuantity: {
$first: "$orderQuantity"
}
}
},
{
$group: {
_id: {
typ: "$type",
date: "$date"
},
orderQuantity: {
$first: "$orderQuantity"
},
value: {
$sum: "$wert"
}
}
},
{
$sort: {
typ: 1,
date: -1
}
}
])
I use the first $project to "normalize" the date. So an order placed at 1499415886: Friday, July 7, 2017 8:24:46 AM and 1499415990: Friday, July 7, 2017 8:26:30 AM will both be counted since they are on the same date (cause I could also tell from what you wrote that the time doesn't matter to you, only the date)
In the $group after the $project you just count the documents that have the "ordertype" WERBUNG and set them to the field werbungCount, otherwise if they are empty set them to the field andereCount. The pipeline after the $project and the $group is like you did it. I just corrected some mistakes and changed the name of the fields in some spots. Also added the orderQuantity field with a condition on the second $project.
Hope that works!

Mongolite and aggregation with $lookup on ObjectId vs character

Working with mongolite v0.9.1 (R) and MongoDB v3.4, I'd like to join two collections, the first one, the parent containing an ObjectId, the second one, the children containing the string value of the parents' ObjectId.
This is the basic syntax :
conParent$aggregate('[
{ "$lookup":
{ "from":"Children",
"localField": "_id",
"foreignField": "parent_id",
"as": "children"
}
}
]')
$lookup seems to take only field name, I've tried this, producing syntaxic errors :
.../...
"foreignField": "{'$oid':'parent_id'}"
.../...
So is there a way to deal with that ?
In the other way, I tried to save the parent's ObjectId in the children in ObjectId format with no luck (I still get a string in MongoDB) :
result <- transform(
computeFunction,
parent_id = sprintf('{"$oid":"%s"}',parent$"_id"))
resultCon <- conout$insert(as.data.frame(result))
Is it possible to store an Id as ObjectId in mongolite?
Note : I'm doing bulk inserts so I can't deal with JSON string manipulations.
Any idea ?
Edit:
Here is an example of the collections i am using :
The Parent collection :
{
"_id" : ObjectId("586f7e8b837abeabb778d2fd"),
"name" : "Root1",
"date" : "2017-01-01",
"value" : 1.0,
"value1" : 10.0,
"value2" : 100.0
},
{
"_id" : ObjectId("586f7ea4837abeabb778d30a"),
"name" : "Root1",
"date" : "2017-01-02",
"value" : 2.0,
"value1" : 20.0,
"value2" : 200.0
}
The Children collection :
{
"_id" : ObjectId("586f7edf837abeabb778d319"),
"name" : "Item1",
"value" : 1.1,
"date" : "2017-01-01",
"parent_id" : "586f7e8b837abeabb778d2fd"
}
{
"_id" : ObjectId("586f7efa837abeabb778d324"),
"name" : "Item2",
"value1" : 11.111111111,
"value2" : 12.222222222,
"date" : "2017-01-01",
"parent_id" : "586f7e8b837abeabb778d2fd"
}
{
"_id" : ObjectId("586f7f15837abeabb778d328"),
"name" : "Item1",
"value" : 2.2,
"date" : "2017-01-02",
"parent_id" : "586f7ea4837abeabb778d30a"
}
{
"_id" : ObjectId("586f7f2b837abeabb778d32e"),
"name" : "Item2",
"value1" : 21.111111111,
"value2" : 22.222222222,
"date" : "2017-01-02",
"parent_id" : "586f7ea4837abeabb778d30a"
}
Could you try :
"foreignField": "_id"
Starting from mongo's website example :
library(mongolite)
library(jsonlite)
a = '[{ "_id" : 1, "item" : 1, "price" : 12, "quantity" : 2 },
{ "_id" : 2, "item" : 2, "price" : 20, "quantity" : 1 },
{ "_id" : 3 }]'
b= '[{ "_id" : 1, "sku" : "abc", "description": "product 1", "instock" : 120 },
{ "_id" : 2, "sku" : "def", "description": "product 2", "instock" : 80 },
{ "_id" : 3, "sku" : "ijk", "description": "product 3", "instock" : 60 },
{ "_id" : 4, "sku" : "jkl", "description": "product 4", "instock" : 70 },
{ "_id" : 5, "sku": null, "description": "Incomplete" },
{ "_id" : 6 }]'
mongo_orders <- mongo(db = "mydb", collection = "orders")
mongo_orders$insert(fromJSON(a))
mongo_inventory <- mongo(db = "mydb", collection = "inventory")
mongo_inventory$insert(fromJSON(b))
df <- mongo_orders$aggregate('[
{
"$lookup":
{
"from": "inventory",
"localField": "item",
"foreignField": "_id",
"as": "inventory_docs"
}
}
]')
str(df)
It works as well when both are set to _id
"localField": "_id",
"foreignField": "_id",
Well I must say that's not possible at all !
Mongilite retrieve _id as character and do not contain any ObjectId implementation.
So...

Realm. Get subset of inner element based on outer one

There is a structure:
{ "groups": [
{ "gid" : 1,
"elements" : [
{ "eid" : 1 },
{ "eid" : 2 }
]
},
{ "gid" : 2,
"elements" : [
{ "eid" : 11 },
{ "eid" : 22 }
]
}
{ "gid" : 3,
"elements" : [
{ "eid" : 21 },
{ "eid" : 32 }
]
}
]
}
I understand how to get all groups:
RealmResults<Group> all = realm.where(Group.class).findAll();
Also I could get all elements or all elements in a group.
But how could I query all element from groups that have id > 1?
RealmResults<Group> allFilteredGroups = realm.where(Group.class).greaterThan("gid", 1).findAll();
Is it possible to retrive all elements from all allFilteredGroups by one query, smth like
realm.where(Element.class).equalsTo(???, allFilteredGroups).findall() ?
I'm not quite sure what you mean by "to retrieve all elements". allFilteredGroups has all the Group objects. As they are linked to the Elements objects, you can easily iterate through them:
for(Group group : allFilteredGroups) {
for(Element element : group.getElement()) {
Log.d("TEST", "eid = " + element.eid);
}
}
There is currently no easy way to flatten the last and have all the Element objects in a single RealmResults.

Resources