Highcharts returning error #15 - javascript

I'm getting the following error:Highcharts error #15 I'm not quite sure I understand this error. I'm using Highcharts and making a $getJson() call to an API that returns data. The data returned looks like the following:
[ {
"timestamp" : 1503151200,
"price" : 4062.46,
"volume24h" : 123093.45
}, {
"timestamp" : 1503158400,
"price" : 3997.26,
"volume24h" : 120506.08
}, {
"timestamp" : 1503165600,
"price" : 4050.96,
"volume24h" : 114699.99
},
I have two functions that are looping and mapping the data. One for the 'timestamp' and 'price' and the other for the 'volume24'. The second function mapping the volume is causing error #15 and I'm not sure why. If I change the data coming from the API call then it won't be accurate. What am I doing wrong? Please see my complete code in the JsFiddle

You only need one function to loop through the data. Once I removed volumeData, put it's loop inside of mappedData and passed mappedData to the second data object in series, highCharts rendered as expected. This surprised me because the documentation example does it by passing two different objects.
series: [{
type: 'area',
name: `Bitcoin in USD`,
data: mappedData,
}, {
type: 'column',
data: mappedData,
yAxis: 1,
}]

Related

Query firebase to return if value more than number

I want to get data from Firebase.
This is more or less my data structure:
"Reports" : {
"N06Jrz5hx6Q9bcVDBBUrF3GKSTp2" : 2,
"eLLfNlWLkTcImTRqrYnU0nWuu9P2" : 2
},
"Users":{
"N06Jrz5hx6Q9bcVDBBUrF3GKSTp2" : {
"completedWorks" : {
...
},
"reports" : {
"-LHs0yxUXn-TQC7z_MJM" : {
"category" : "Niewyraźne zdjęcie",
"creatorID" : "z8DxcXyehgMhRyMqmf6q8LpCYfs1",
"reportedID" : "N06Jrz5hx6Q9bcVDBBUrF3GKSTp2",
"resolved" : false,
"text" : "heh",
"workID" : "-LHs-aZJkAhEf1RHVasg"
},
"-LHs1hzlL4roUJfMlvyA" : {
"category" : "Zdjęcie nie przedstawia zadania",
"creatorID" : "z8DxcXyehgMhRyMqmf6q8LpCYfs1",
"reportedID" : "N06Jrz5hx6Q9bcVDBBUrF3GKSTp2",
"resolved" : false,
"text" : "",
"workID" : "-LHs-aZJkAhEf1RHVasg"
}
},
"userType" : "company",
"verified" : true
},
}
So as you can see the number of reports is listed in the Reports part. How can I make Firebase return only the ids of the users where the report number is over or equal 3?
Something like this (this will not work, but I hope kind of shows what I was thinking about):
firebase.database().ref('Reports').orderBy(whatHere?).moreThen(2).on('value', snap => {
Is this even doable like this? If yes how could I do it? I want to grab the IDs of the users where reports are >= 3
You're looking for orderByValue():
firebase.database().ref('Reports').orderByValue().startAt(3).on('value', snapshot => {
snapshot.forEach(reportSnapshot => {
console.log(reportSnapshot.key);
})
})
Also check out the Firebase documentation on ordering data.
There are two options for doing that but not exactly the way you wants. You have to use javascript for further processing. One is to use limitToLast after using order by. which will give the last numbers from the result.
firebase.database().ref('Reports').orderBy(reportid).limitToLast(2).on('value', snap => {
Or use startAt and endAt to skip and fetch the result as offset which can provide the data between two reportId.
firebase.database().ref('Reports').orderBy(reportid).
.startAt(reportIdStart)
.endAt(reportIdLast)
.limitToLast(15)
According Firebase documentation:
Using startAt(), endAt(), and equalTo() allows you to choose arbitrary
starting and ending points for your queries
To filter data, you can combine any of the limit or range methods with an order-by method when constructing a query.
Unlike the order-by methods, you can combine multiple limit or range
functions. For example, you can combine the startAt() and endAt()
methods to limit the results to a specified range of values.
For more information go through documentation on filtering data

How can I access nested data in Firebase with React?

I am working on building a simple app with React and Firebase - a way to manage income and expenditure, and my Firebase is set up with the following structure:
"cashbook" : {
"expenditure" : {
"expenditure-1" : {
"amount" : "500",
"category" : "insurance",
"date" : "date",
"name" : "Life Insurance",
"type" : "recurring"
}
},
"income" : {
"salary" : {
"amount" : "500",
"category" : "salary",
"date" : "date",
"type" : "recurring"
}
}
}
I have React set up and working perfectly with just the expenditure, using Re-base:
componentDidMount: function() {
// Two way data binding
base.syncState('cashbook/expenditure', {
context: this,
state: 'expenditure'
});
},
I can then reference using: this.state.expenditure
However, when I try to expand the app to access the Income data, things go pear shaped. I amended the componentdidmount to:
componentDidMount: function() {
// Two way data binding
base.syncState('cashbook', {
context: this,
state: 'cashbook'
});
},
And try to access with this.state.cashbook.expenditure and this.state.cashbook.income, but no joy, I get the error: Uncaught TypeError: Cannot read property 'expenditure' of undefined.
Not quite sure what to try, any pointers would be divine brown.
Thanks in advance :)
Turns out I was being a moron :)
I just needed to use syncstate on cashbook instead of cashbook/expenditure and call this.state.cashbook.expenditure.

jQuery DataTables with Node.js

So i am trying to implement a pagination table with the datatables plugin, this is my first time using this plugin. I followed the documentation on the plugin and tried to get the values from the server through the use of Ajax, as per presented in the plugins documentation.
I seem to be getting the following error once i make the get request and i am unsure of why?
Error: Uncaught TypeError: Cannot read property 'length' of undefined
On client side i have the following code
viewReports = {
init: function(){
$('#paginatedData').DataTable({
"processing": true,
"serverSide": true,
"ajax": '/viewreports'
});
}
};
$(document).ready(viewReports.init);
In my server side i have the following
router.get('/viewreports', function(res, req){
async.parallel({
viewReports: function(callback){
restCall('/rest/bugbounty/latest/message/searchReport', 'POST', parameters, function(data){
callback(null, data);
});
}
}, function(err, result){
if(!err){
res.send(result.viewReports);
res.render('viewreports');
}
});
});
Returned JSON:
{ reportList: [ { reportID: 'EIBBP-448', eBayUserID: ' ', reportStatus: 'New', summary: 'BugBounty Report created by Raj', lastUpdatedDate: '2015-06-15 01:05', createdDate: '2015-06-15 01:05', paypalLoginID: 'raaj#paypal.com' } ], searchStatus: 'Success', eBayUserID: '', errorCode: '0', rowCount: '6', pageNumber: '1', paginationValue: '1', paypalLoginID: 'raaj#paypal.com' }
It would be great to know if there is anyone who has worked with node.js server side processing for datatables
You need to define dataSrc and columns.data - the following should work :
var table = $('#example').DataTable({
processing: true,
serverSide: true,
ajax: {
url: "/viewreports",
dataSrc: "reportList"
},
columns: [
{ data : "reportID" },
{ data : "eBayUserID" },
{ data : "reportStatus" },
{ data : "summary" },
{ data : "lastUpdatedDate" },
{ data : "createdDate" },
{ data : "paypalLoginID" }
]
});
on an empty table :
<table id="example"></table>
dataSrc to specify what the array holding row items is named (cause of "Cannot read property 'length' of undefined")
columns.data to map item properties to columns
You simply don't have to bother with the server side processing.
I used a simple way to trick dataTables initialization.
First, you will need to fetch the data you want to display in the table through your most preferred way, after you have confirm that data displays well, now head to where you initialize dataTables and make it so that it delays before initialization.
setTimeout(() => {
$('#yourtable').dataTable({
// datatables customization options
});
}, 100)
For example, in my case I gave it a delay of 100ms, and it works like a charm.

how to push a dictionary to a nested array with mongodb?

i have data that looks like this in my database
> db.whocs_up.find()
{ "_id" : ObjectId("52ce212cb17120063b9e3869"), "project" : "asnclkdacd", "users" : [ ] }
and i tried to add to the 'users' array like thus:
> db.whocs_up.update({'users.user': 'usex', 'project' : 'asnclkdacd' },{ '$addToSet': { 'users': {'user':'userx', 'lastactivity' :2387843543}}},true)
but i get the following error:
Cannot apply $addToSet modifier to non-array
same thing happens with push operator, what im i doing wrong?
im on 2.4.8
i tried to follow this example from here:
MongoDB - Update objects in a document's array (nested updating)
db.bar.update( {user_id : 123456, "items.item_name" : {$ne : "my_item_two" }} ,
{$addToSet : {"items" : {'item_name' : "my_item_two" , 'price' : 1 }} } ,
false ,
true)
the python tag is because i was working with python when i ran into this, but it does nto work on the mongo shell as you can see
EDIT ============================== GOT IT TO WORK
apparently if i modify the update from
db.whocs_up.update({'users.user': 'usex', 'project' : 'asnclkdacd' },{ '$addToSet': { 'users': {'user':'userx', 'lastactivity' :2387843543}}},true)
to this:
db.whocs_up.update({'project' : 'asnclkdacd' },{ '$addToSet': { 'users': {'user':'userx', 'lastactivity' :2387843543}}},true)
it works, but can anyone explain why the two do not achieve the same thing, in my understanding they should have referenced the same document and hence done the same thing,
What does the addition of 'users.user': 'userx' change in the update? does it refer to some inner document in the array rather than the document as a whole?
This is a known bug in MongoDB (SERVER-3946). Currently, an update with $push/$addToSet with a query on the same field does not work as expected.
In the general case, there are a couple of workarounds:
Restructure your update operation to not have to query on a field that is also to be updated using $push/$addToSet (as you have done above).
Use the $all operator in the query, supplying a single-value array containing the lookup value. e.g. instead of this:
db.foo.update({ x : "a" }, { $addToSet : { x : "b" } }, true)
do this:
db.foo.update({ x : { $all : ["a"] } }, { $addToSet : { x : "b" } } , true)
In your specific case, I think you need to re-evaluate the operation you're trying to do. The update operation you have above will add a new array entry for each unique (user, lastactivity) pair, which is probably not what you want. I assume you want a unique entry for each user.
Consider changing your schema so that you have one document per user:
{
_id : "userx",
project : "myproj",
lastactivity : 123,
...
}
The update operation then becomes something like:
db.users.update({ _id : "userx" }, { $set : { lastactivity : 456 } })
All users in a given project may still be looked up efficiently by adding a secondary index on project.
This schema also avoids the unbounded document growth of the above schema, which is better for performance.

ExtJS: return total rows/records in json store

I have a json store that returns values in json format. Now I need to get the number of rows/records in the json string but when I use store.getCount() function it returns 0, but the combobox is populated with rows, and when I use store.length I get undefined, probably because its not an array anymore, its returning from store, which is calling php script. Anyways, whats the best approach for this problem?
Try this out:
var myStore = Ext.extend(Ext.data.JsonStore, {
... config...,
count : 0,
listeners : {
load : function(){
this.count = this.getCount();
}
}
Ext.reg('myStore', myStore);
and then use inside panels:
items : [{
xtype : 'myStore',
id : 'myStoreId'
}]
Whenever you need to get the count then you can simply do this:
Ext.getCmp('myStoreId').count
Your Json response from server, can be something like this...
{
"total": 9999,
"success": true,
"users": [
{
"id": 1,
"name": "Foo",
"email": "foo#bar.com"
}
]
}
Then you can use reader: {
type : 'json',
root : 'users',
totalProperty : 'total',
successProperty: 'success'
} in your store object.
As from docs if your data source provided you can call getTotalCount to get dataset size.
If you use ajax proxy for the store, smth like
proxy : {
type : 'ajax',
url : 'YOUR URL',
reader : {
type : 'json',
root : 'NAME OF YOUR ROOT ELEMENT',
totalProperty : 'NAME OF YOUR TOTAL PROPERTY' // requiered for paging
}
}
and then load your store like
store.load();
There will be sent Ajax asynchronous request, so you should check count in callback like this
store.load({
callback : function(records, operation, success) {
console.log(this.getCount()); // count considering paging
console.log(this.getTotalCount()); // total size
// or even
console.log(records.length); // number of returned records = getCount()
}
});

Categories