High charts Issue with stock bar chart multiple line series - highcharts

It's working fine when all data available but issue happens when we select range in bar at bottom in angular 11
I don't know why this issue generated?
Code in angular:-
var datas = [{
data: [
[1630175400000, 0],
[1630089000000, 0.47],
[1630002600000, -0.48],
[1629916200000, 0.38],
[1629829800000, 0.18],
[1629743400000, 0.91],
[1629657000000, 0.01],
[1629570600000, -0.2],
[1629484200000, 0.01],
[1629397800000, -0.66],
[1629311400000, 0.04],
[1629225000000, -0.63],
[1629138600000, 0.07],
[1629052200000, -0.02],
[1628965800000, 0],
[1628879400000, 0.24],
[1628793000000, -0.45],
[1628706600000, 0.21],
[1628620200000, -0.04],
[1628533800000, -0.34],
[1628447400000, -0.08],
[1628361000000, 0.03],
[1628274600000, -0.23],
[1628188200000, 0.29],
[1628101800000, -0.19],
[1628015400000, 0.2],
[1627929000000, -0.13],
[1627842600000, -0.06],
[1627756200000, 0.02],
[1627669800000, -0.36]
],
id: "base1",
name: "Avg. growth rate",
type: "line"
}, {
data: [
[1628533800000, 117.442863],
[1630175400000, 117.476804],
[1630089000000, 117.476804],
[1630002600000, 116.930384],
[1629916200000, 117.488726],
[1629829800000, 117.039701],
[1629743400000, 116.834498],
[1629657000000, 115.777653],
[1629570600000, 115.764878],
[1629484200000, 115.996878],
[1629397800000, 115.988679],
[1629311400000, 116.764601],
[1629225000000, 116.7125],
[1629138600000, 117.458283],
[1629052200000, 117.377938],
[1628965800000, 117.395677],
[1628879400000, 117.395677],
[1628793000000, 117.116852],
[1628706600000, 117.64148],
[1628620200000, 117.392843],
[1628533800000, 117.442863],
[1628447400000, 117.841829],
[1628361000000, 117.933245],
[1628274600000, 117.902974],
[1628188200000, 118.170114],
[1628101800000, 117.826993],
[1628015400000, 118.045463],
[1627929000000, 117.811225],
[1627842600000, 117.968985],
[1627756200000, 118.045426],
[1627669800000, 118.024255]
],
id: "base2"
name: "IN (GBP)"
type: "line"
}]
Thanks in advance.

Live example with the issue: http://jsfiddle.net/BlackLabel/zwsLxyac/
You have unsorted data which causes Highcharts error #15: https://assets.highcharts.com/errors/15/
You need to sort your data before it is passed to a chart:
datas.forEach((series, index) => {
series.data.sort((a, b) => a[0] - b[0]);
});
Live demo: http://jsfiddle.net/BlackLabel/0nuezd8b/
API Reference: https://api.highcharts.com/highstock/series.line.data

Related

Using data from the first response in the body of the second

I'm trying to combine requests from two services in one endpoint.
The first returns the list of users, like this:
{
"data": [
{ "id": 1, "name": "first", "photo": "employee_photos/key1.png" },
{ "id": 2, "name": "second", "photo": null },
{ "id": 3, "name": "third", "photo": "employee_photos/key3.png" }
]
}
The second is supposed to receive the POST request with the JSON listing photo keys to get the required version URLs.
Request:
{
"keys": [ "employee_photos/key1.png", "employee_photos/key3.png" ],
"versions": [ "small", "large" ]
}
I created a small Lua script to process the response of the first request and collect the list of keys. It looks like this:
function post_employees(request, employeesResponse)
local resp = employeesResponse.load()
local data = resp:data():get("data")
local photo_keys = {}
for i = 0, data:len() - 1, 1 do
local rec = data:get(i)
local id = rec:get("id")
local photo = rec:get("photo")
if photo then
table.insert(photo_keys, photo)
end
end
resp:data():set("photos", table.concat(photo_keys, ","))
end
But then... I can't find a way to use this list of keys in the second request. Is it even possible?

How to properly query Postgresql JSONB array of hashes on Ruby on Rails 6?

This is my column:
[
{ id: 1, value: 1, complete: true },
{ id: 2, value: 1, complete: false },
{ id: 3, value: 1, complete: true }
]
First, is there a "correct" way to work with a jsonb scheme? should I redesign to work with a single json instead of the array of hashes?
I have about 200 entries on the database, the column status has 200 of those itens.
How would I perform a query to get the count of true/false?
How can I query for ALL complete itens? I can query for the database rows in which the json has an item complete, but I can't query for all the itens, in all rows of the database that are complete.
Appreciate the help, thank you
Aha! I found it here:
https://levelup.gitconnected.com/how-to-query-a-json-array-of-objects-as-a-recordset-in-postgresql-a81acec9fbc5
Say your dataset is like this:
[{
"productid": "3",
"name": "Virtual Keyboard",
"price": "150.00"
}, {
"productid": "1",
"name": "Dell 123 Laptop Computer",
"price": "1300.00"
},
{
"productid": "8",
"name": "LG Ultrawide Monitor",
"price": "190.00"
}]
The proper way to count it, is like this:
select items.name, count(*) as num from
purchases,jsonb_to_recordset(purchases.items_purchased) as items(name text)
group by items.name
order by num Desc
Works like a charm and is extremely fast.
To do it in Rails, you need to use Model.find_by_sql(....) and indicate your select therem. I'm sure there are probably better ways to do it.

LUA: add values in nested table

I have a performance issue in my application. I would like to gather some ideas on what I can do to improve it. The application is very easy: I need to add values inside a nested table to get the total an user wants to pay out of all the pending payments. The user chooses a number of payments and I calculate how much it is they will pay.
This is what I have:
jsonstr = "{ "name": "John",
"surname": "Doe",
"pending_payments": [
{
"month": "january",
"amount": 50,
},
{
"month": "february",
"amount": 40,
},
{
"month": "march",
"amount": 45,
},
]
}"
local lunajson = require 'lunajson'
local t = lunajson.decode(jsonstr)
local limit -- I get this from the user
local total = 0;
for i=1, limit, 1 do
total = total + t.pending_payments[i].amount;
end;
It works. At the end I get what I need. However, I notice that it takes ages to do the calculation. Each JSON has only twelve pending payments (one per month). It is taking between two to three seconds to come up with a result!. I tried in different machines and LUA 5.1, 5.2., 5.3. and the result is the same.
Can anyone please suggest how I can implement this better?
Thank you!
For this simple string, try the test code below, which extracts the amounts directly from the string, without a json parser:
jsonstr = [[{ "name": "John",
"surname": "Doe",
"pending_payments": [
{
"month": "january",
"amount": 50,
},
{
"month": "february",
"amount": 40,
},
{
"month": "march",
"amount": 45,
},
]
}]]
for limit=0,4 do
local total=0
local n=0
for a in jsonstr:gmatch('"amount":%s*(%d+),') do
n=n+1
if n>limit then break end
total=total+tonumber(a)
end
print(limit,total)
end
I found the delay had nothing to do with the calculation in LUA. It was related with a configurable delay in the retrieval of the limit variable.
I have nothing to share here related to the question asked since the problem was actually in an external element.
Thank #lfh for your replies.

Is it possible to select certain elements without iterating through the array?

I have an array of objects, each of which has the property :cow either set to false or true:
animals = [
{
id: 1,
cow: true
},
{
id: 2,
cow: true
},
{
id: 3,
cow: true
},
{
id: 4,
cow: false
},
{
id: 5,
cow: false
}
]
I need to select all members of the array that pass a condition without iterating through every element of the array.
Is it possible?
I tried:
notCows = animals.reject { |a| !a[:cow] }
notCows = animals[0, 1, 2]
which doesn't work.
No, this is impossible. In order to find all elements that satisfy a certain condition, you need to look at all elements to see whether they satisfy that condition. It is simply logically not possible to find all elements of a collection without iterating through all elements of the collection.
You were almost there, use Enumerable#select (which scans the all the member of the collection, by the way):
animals.select { |animal| animal[:cow] }
#=> [{:id=>1, :cow=>true}, {:id=>2, :cow=>true}, {:id=>3, :cow=>true}]
Or the opposite:
animals.select { |animal| !animal[:cow] }
#=> [{:id=>4, :cow=>false}, {:id=>5, :cow=>false}]
The returned results are still Ruby objects: Arrays of Hashes.
As alternative you can group by status (Enumerable#group_by):
animals.group_by { |a| a[:cow] }
#=> {true=>[{:id=>1, :cow=>true}, {:id=>2, :cow=>true}, {:id=>3, :cow=>true}], false=>[{:id=>4, :cow=>false}, {:id=>5, :cow=>false}]}

Highcharts, how to convert series array to hash with extra data?

I'm inheriting a chart that someone else has already written. I now want to add extra data to the series to be displayed in the tooltip.
The original code is setup with arrays or arrays to build the series data, like so:
$data['series'][$nextindex]['data'][] = array(strtotime($date) * 1000, $budgetSum);
When I dump the array the output is like so:
[
{
"name": "Adjusted Budget",
"color": "#7570B3",
"data": [
[
1486454400000,
0
],
[
1493622000000,
2200
],
[
1494226800000,
3700
],
....
I know to add extra data it needs to be formatted as a hash/object:
[
{x: 1486454400000, y: 0, myData: test1},
{x: 1493622000000, y: 2200, myData: test2},
{x: 1494226800000, y: 3700, myData: test3},
.....
]
I'm just not sure how to do the conversion...
I tried something like this (but it didn't work):
$myArr = array('x' => strtotime($date) * 1000, 'y' => $budgetSum, 'myData' => 'test1');
$data['series'][$nextindex]['data'][] = json_encode($myArr);
Nevermind, I was overthinking it.
I got it to work with:
$myArr = array('x' => strtotime($date) * 1000, 'y' => $budgetSum, 'myData' => 'test1');
$data['series'][$nextindex]['data'][] = $myArr;
No need for the json_encode()

Resources