I'm trying to create chart using rowsURL. Here is an example:
data:
rowsURL: "#{ build_chart_data_url(#obj) }",
firstRowAsNames: false,
enablePolling: true
It is OK when data returned from build_chart_data_url are something like this:
[
[some_time, 4],
[some_time, 6],
[some_time, 10],
...
]
But I need have, for example, two series. Time for two series are the same (interval of my points is different).
When I try to do something like this:
[ [1,2,3], [4,5,6] ]
My chart draws me two series but with the wrong time.
When I try to send something like this:
[
#series 1
[
[some_time, 4],
[some_time, 5]
],
#series 2
[
[some_time, 6],
[some_time, 7]
],
]
My Highchart draw nothing :(
Which data format I should send to use two series with rowsURL?
Related
I have table where I want to find difference in certain columns. I'm doing it with diff():
$inventoryitems1 = InventoryItem::where('inventory_id', $request->get('inventory1'))
->select('owner_id', 'location_id', 'asset_id')
->get();
$inventoryitems2 = InventoryItem::where('inventory_id', $request->get('inventory2'))
->select('owner_id', 'location_id', 'asset_id')
->get();
$difference = $inventoryitems2->diff($inventoryitems1);
And then i get empty array. But if I don't have select in my collection. It work, it shows all different rows. Is there anyother way to do this or this one is right but I'm not doing it the right way?
UPDATE
I have $inventoryitems1 collection that looks like this:
0: {asset_id: 2, owner_id: 2, location_id: 1}
1: {asset_id: 3, owner_id: 2, location_id: 1}
and $inventoryitems1 collection that looks like this:
0: {asset_id: 2, owner_id: 2, location_id: 1}
1: {asset_id: 3, owner_id: 6, location_id: 1}
I'm trying to find differences in those two collections, where we can see that owner_id is different in second collection. How can I only get those objects where there was some change (difference).
My issue is in my json I am expecting an array, but am getting an object.
Details:
I have an array of numbers:
$numbers = [1];
I select from relationship, the "drawn numbers":
$drawnNumbers = Ball::whereIn('number', $numbers)->where('game_id', $card->game->id)->get()->map(function($ball) {
return $ball->number;
})->toArray();
I do a ->toArray() here. I want to find the numbers in $numbers that do not occur in $drawnNumbers. I do so like this:
$numbersNotYetDrawn = array_diff($numbers, $drawnNumbers);
My method then return $numbersNotYetDrawn (my headers accept is application/json).
So now the issue. When $drawnNumbers is an empty array, then the printed json is a regular array like this:
[
1
]
However if the relationship returns $drawnNumbers to be an array with numbers, then json is printed as an object:
{
"0" => 1
}
Does anyone know why this is? Anyway to ensure that json is array?
Edit:
Here is my actual data:
$drawnNumbers = Ball::whereIn('number', $numbers)->where('game_id', $card->game->id)->get()->map(function($ball) {
return $ball->number;
})->toArray();
$undrawnNumbers = array_diff($numbers, $drawnNumbers);
// $undrawnNumbers = array_values(array_diff($numbers, $drawnNumbers)); // temp fix
Replace
$numbersNotYetDrawn = array_diff($numbers, $drawnNumbers);
with
$numbersNotYetDrawn = array_values(array_diff($numbers, $drawnNumbers));
to make sure element keys are reset and array is treated as a simple list and serialized to a JSON list - instead of being treated as an associative array and serialized to a JSON object.
I recently had this same problem and wondered the same thing.
I solved it by adding "array_values", but I was wondering how to reproduce it.
I found it that it is reproduced when array_diff removes an element from the array that isn't the last element. So:
>>> $x
=> [
1,
2,
3,
4,
5,
]
>>> array_diff($x, [5]);
=> [
1,
2,
3,
4,
]
>>> array_diff($x, [1]);
=> [
1 => 2,
2 => 3,
3 => 4,
4 => 5,
]
I can't explain to myself this
const something = new Rx.BehaviorSubject([1,2,4,4])
.distinct()
.do((s) => console.log(s))
.map(list => list.length)
.filter(length => length >=2)
.subscribe(total => console.log('total:', total));
this is what I get as output
[1, 2, 4, 4]
"total:"
4
I get confused because reviewing the docs on distinct I thought it would work for numbers. My use case is a data table widget sends me events and this array tracks which row they clicked and I want to detect once a double click occurred.
updated code
const something = new Rx.BehaviorSubject([]);
something.next([1]);
console.log(something.getValue());
something.next(something.getValue().concat(2));
something.next(something.getValue().concat(3));
something.next(something.getValue().concat(4));
something.next(something.getValue().concat(4));
something
.distinct()
.subscribe(val => console.log('value:', val));
output
"value:"
[1, 2, 3, 4, 4]
You're sending a value that happens to be an array. You would see the operation of distinct if you did
const something = new Rx.BehaviorSubject([]);
something .distinct() .subscribe(val => console.log('value:', val));
something.next(1); // --> value: 1
something.next(2); // --> value: 2
something.next(1); // no output (because of distinct)
something.next(3); // --> value: 3
My documents contain an array, for example;
{
"a": [ 2, 3 ],
"id": ...
}
I want to return only the documents for which a contains only the elements 2 and 3.
This is the simplest I've found yet;
r.table("t").filter(r.row('a').difference([2,3]).eq([]))
Is there a better way?
A nice way to write the same function would be to use .isEmpty instead of .eq([]).
r.table("t")
.filter(r.row('a').difference([2,3]).isEmpty())
This query is equivalent to the function you wrote.
That being said, your current query returns document where a has only 2 and/or 3. So, for example, a document with with a: [2] would get matched.
Example result set:
{
"a": [ 2 ] ,
"id": "f60f0e43-a542-499f-9481-11372cc386c8"
} {
"a": [ 2, 3 ] ,
"id": "c6ed9b4e-1399-47dd-a692-3db80df4143c"
}
That might be what you want, but if you only want documents where the a property is [2, 3] or [3, 2] exactly and contains no other elements, you might want to just use .eq:
r.table("t")
.filter(r.row('a').eq([2,3]).or( r.row('a').eq([3, 2]) ))
Example result:
{
"a": [ 2, 3 ] ,
"id": "c6ed9b4e-1399-47dd-a692-3db80df4143c"
}, {
"a": [ 3, 2 ] ,
"id": "cb2b5fb6-7601-43b4-a0fd-4b6b8eb83438"
}
I have two models Project and UrlList. A project :has_many url_list and a url_list :belongs_to project.
Now I have array for project id's all_projects = [1,2,5,8,16]. I want to retrieve all the records from url_list where project_id is one of those from all_projects array. How do I write code for it?
You can pass an array as value for an attribute to where method:
all_projects = [1, 2, 5, 8, 16]
url_lists = UrlList.where(:project_id => all_projects)
It'll generate SQL query like that:
SELECT `url_lists`.* FROM `url_lists` WHERE `project_id`.`user_id` IN (1, 2, 5, 8, 16)