ExtJS 4 group by one column in store, total another - javascript

I have a store of data representing bank deposits. The data looks something like this:
{ account : 'a', amount : 5 },
{ account : 'a', amount : 15 },
{ account : 'b', amount : 7 },
{ account : 'b', amount : 3 },
{ account : 'c', amount : 12 },
I would like to display this data in a grid that groups by account and totals amount. I do not want to display the original data. Just the grouped data.
Account Total Amount
a 20
b 10
c 12
If this were a sql database the query would be along these lines:
select account, sum( amount ) from tbl group by account;
is this possible in extjs without doing it manually? I cannot seem to get it to work.
I have called this method on my store:
store.group('account');
And my column in my grid panel that should display the total looks like this:
{
:text => 'Total Amount',
:dataIndex => 'amount',
:summaryType => 'sum',
},
I know the group is doing something because I can change the order from ASC to DESC and the grid displays it differently. But for now the grid just displays all of the rows with no grouping.
Thanks for the help.

I am afraid that Ext JS doesn't have support for displaying data exactly as you want.
You can use Ext.grid.feature.GroupingSummary feature
documentation: http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.grid.feature.GroupingSummary
Or you can get grouped data from grouped store by
store.getGroups()
and process them manually.
documentation: http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.data.Store-method-getGroups

Related

get a range of numbers from sql column of type varchar

I have a postgres server running with one column (say marks) of type VARCHAR(255), but is supposed to have numbers, like if i do a select *.. query , i will get ['100','50','21','14'...] etc.
i would like to run a range query on it, like user passes [10,30] and gets ['21','14'] as result. I think this would require casting at the time of running the BETWEEN query, but i cannot get it to work properly.
I am using sequalize.js which is generating the following query:
SELECT "id"
FROM "token_attributes" AS "token_attributes"
WHERE "token_attributes"."attributesDirectoryId" = 3
AND CAST('token_attributes.attributeValue' AS INTEGER) BETWEEN 10 AND 30;
on server also this query seems to fail. the sequalize query that is being created is :
{
where: {
attributesDirectoryId: 3,
attributeValue: Where { attribute: [Cast], comparator: '=', logic: [Object] }
},
attributes: [ 'id' ]
}
i have used the following code to create the where condition (cast and where were imported from sequelize):
let whereFilter ={}
let value = where(cast(`${tableName}.attributeValue`, 'integer'), {[Op.between]: rangeAsInt})
whereFilter['attributeValue'] = value
so this is basically calling table.findAll({where:whereFilter}) I am not sure how to either make sequelize create a correct sql api or what the actual correct SQL api would be. can anyone help?
found the issue, i missed the sequilize.col function :
let whereFilter ={}
let value = where(cast(col(`${tableName}.attributeValue`), 'integer'), {[Op.between]: rangeAsInt})
whereFilter['attributeValue'] = value
and the query would be :
SELECT "id"
FROM "token_attributes" AS "token_attributes"
WHERE "token_attributes"."attributesDirectoryId" = 3
AND CAST("token_attributes"."attributeValue" AS INTEGER) BETWEEN 10 AND 30;

Verify input on change in dynamic list Vue

Based on a drop down that has a value in the 1-10 range I am displaying N Rows (N = value of dropdown)
Each row acts as an object because it has 3 properties: x,y,z. All the rows I generate are stored in an array so the final format of the data is:
data:{
rows: [
{x:0,y:0,z:value},
.......
]
}
I have to verify that for each row the value of x,y,z doesn't pass 100 and if it does display an error.
I've tried doing it with a function that parses the array on each input change but besides the fact that it seem very inefficient it sometimes doesn't work.
How can I handle this validation on dynamically generated inputs ?
Thank you in advance!
Make a watcher that observes the array changes :
data:{
rows: [
{x:0,y:0,z:value},
.......
]
},
watch:{
rows:{
handler(val){
let check=this.rows.every(row=>Object.values(row).every(v=>v<100))
if(!check){
//error
}
},
deep:true
}
}

javascript multidimensional objects

I have the following requirements that needs to be build in javascript objects/array. Can anyone help me with a sample?
Requirements
Start with invoices number. Key: invoice, Value: INV001, INV002, INV003...
Each invoice number contain 1 or more receipt number. 1 receipt number may belongs to 1 or more invoices number. Key: receipt, Value: RCP001, RCP002, RCP003...
Each receipt number contain 1 or more payment method. Key: payment, Value: cash, cc, ibg, chq...
Each payment method contain only 1 amount. Key: amount, Value: 5, 10, 1000, 9999...
JavaScript doesn't inherently support multidimensional arrays.
Instead, You need to create an array of arrays. IE
Start with your 3 primary arrays:
var invoiceArr = ["invoice1", "invoice2", "invoice3"];
var receiptArr = ["receipt1", "receipt2", "receipt3"];
var paymentArr = ["payment1", "payment2", "payment3"];
Add them to a main array:
var mainArray = [invoiceArr, receiptArr, paymentArr];
Are you able to follow the below code or do you need further instructions?
var solution = {
invoice: [{"INV1" : { receipt : ["RCP1" : { payment : ["cash" , "cc"]
} , "RCP2"]
}},
{"INV2" : { receipt : ["RCP1", "RCP2"]
}}
],
}

dgrid not showing all rows in the store

I have a data array with 165 elements, and I am showing them in an OnDemandGrid, sorted by a date field. However, when the grid shows up, only the last 140 elements in the data array are shown (i.e., the elements with the 140 most recent dates). Still, if I click the date header to reverse the sort, the first 140 elements show (i.e., the elements with the 140 oldest dates). So my guess is that somehow the mechanism of lazy loading is not working, still I don't get why only the last portion of the array is shown instead of the first. I am not using pagination, nor I set other options related to the size. Any suggestion?
The grid is added to a div which is already in the page:
<div id="navList" class="dgrid-autoheight"></div>
Here's the code for the grid, below you can find the data array:
function fillNavList(data) {
var columns =
[
{
field : "date",
label : L["date"]
},
{
field : "value",
label : L["value"]
},
{
field : "dateModification",
label : L["dateModification"]
},
{
field : "status",
label : L["status"]
},
{
field : "valueRefId",
label : L["valueRefId"]
}
];
require(
[
"dojo/on",
"dstore/Memory",
"dstore/Filter",
"dgrid/OnDemandGrid",
"dojo/_base/declare"
], function(on, Memory, Filter, OnDemandGrid, declare) {
var store = new Memory({
data : data
});
var navList = new (declare(
[
OnDemandGrid
]))({
columns : columns,
sort: "date",
collection : store,
addUiClasses : false
}, "navList");
});
}
And here's the data:
[{"date":"2000-01-31","value":96.02,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-02-28","value":100,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-03-29","value":92.48,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-04-30","value":93.91,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-05-31","value":100.25,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-06-28","value":107.65,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-07-31","value":114.06,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-08-30","value":120.26,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-09-30","value":126.43,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-10-31","value":116.66,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-11-29","value":110.73,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-12-31","value":119.37,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-01-31","value":135.13,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-02-28","value":144.88,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-03-31","value":126.29,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-04-30","value":128.12,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-05-30","value":137.91,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-06-30","value":127.41,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-07-31","value":119.34,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-08-29","value":119.42,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-09-30","value":127.37,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-10-31","value":146.88,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-11-28","value":146.48,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-12-31","value":154.32,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-01-30","value":160.79,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-02-27","value":174.37,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-03-31","value":178.51,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-04-30","value":157.99,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-05-31","value":146.95,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-06-30","value":145.87,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-07-30","value":145.27,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-08-31","value":136.25,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-09-30","value":146.82,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-10-29","value":147.94,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-11-30","value":162.19,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-12-31","value":154.17,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-01-31","value":147.57,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-02-28","value":148.36,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-03-31","value":151.77,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-04-29","value":137.69,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-05-31","value":132.07,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-06-30","value":139.09,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-07-27","value":148.3,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-08-31","value":152.43,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-09-30","value":173.12,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-10-31","value":163.36,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-11-30","value":188.31,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-12-30","value":204.03,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-01-31","value":226.65,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-02-28","value":220.54,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-03-31","value":249.33,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-04-28","value":277.9,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-05-31","value":266.03,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-06-30","value":249.8,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-07-31","value":236.82,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-08-31","value":241.44,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-09-29","value":243.85,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-10-06","value":243,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-10-31","value":243.54,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-11-30","value":244.9,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-12-29","value":248.81,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-01-31","value":250.2,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-02-28","value":237.24,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-03-30","value":216.31,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-04-30","value":221.92,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-05-31","value":232.35,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-06-29","value":243.63,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-07-31","value":202.47,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-08-31","value":163.19,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-09-28","value":169.58,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-10-31","value":192.84,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-11-30","value":176.27,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-12-31","value":191.2,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-01-31","value":232.59,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-02-29","value":299.72,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-03-31","value":275.87,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-04-30","value":252.21,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-05-30","value":265.71,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-06-30","value":288.32,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-07-31","value":234.16,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-08-29","value":218.41,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-09-30","value":243.7,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-10-31","value":354.57,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-11-28","value":379.28,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-12-31","value":399.38,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-01-30","value":405.77,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-02-27","value":405.65,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-03-31","value":392.02,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-04-30","value":370.42,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-05-29","value":365.6,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-06-30","value":340.71,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-07-31","value":338.9,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-08-31","value":375.67,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-09-30","value":380.63,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-10-30","value":350.71,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-11-30","value":388.24,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-12-31","value":375.85,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-01-29","value":361.39,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-02-26","value":335.54,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-03-10","value":318.26,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-03-31","value":318.16,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-04-30","value":324.68,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-05-28","value":296.24,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-05-31","value":296.21,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-06-30","value":297.78,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-07-30","value":261.96,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-08-31","value":300.18,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-09-30","value":349.59,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-10-29","value":427.49,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-11-30","value":404.6,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-12-31","value":506.97,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-01-31","value":517.49,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-02-28","value":567.69,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-03-31","value":541.83,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-04-29","value":574.72,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-05-31","value":506.78,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-06-30","value":469.21,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-07-29","value":521.53,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-08-31","value":529.83,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-09-30","value":507.55,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-10-31","value":435.8,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-11-30","value":488.27,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-12-30","value":480.31,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-01-31","value":462.31,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-02-29","value":465.92,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-03-30","value":490.21,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-04-30","value":484.9,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-05-31","value":480.55,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-06-29","value":393.47,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-07-31","value":438.26,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-08-31","value":410.83,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-09-28","value":375.59,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-10-31","value":319.01,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-11-30","value":315.91,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-12-31","value":318.33,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-01-31","value":351.63,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-02-28","value":377.62,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-03-29","value":412.7,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-04-30","value":452.87,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-05-31","value":453.45,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-06-28","value":439.18,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-07-31","value":421.47,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-08-30","value":375.51,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-09-30","value":385.31,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-10-31","value":413.41,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-11-29","value":461.28,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-12-31","value":455.58,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-01-31","value":448.93,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-02-28","value":455.05,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-03-31","value":476.19,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-04-30","value":488.89,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-05-30","value":467.05,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-06-30","value":478.1,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-07-31","value":488.85,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-08-29","value":534.46,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-09-30","value":629.01,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-10-31","value":618.48,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-11-28","value":699.19,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-12-31","value":762.46,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2015-01-30","value":815.27,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2015-02-27","value":811.23,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2015-03-31","value":842.4,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2015-04-30","value":775.2,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2015-05-29","value":807.2,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2015-06-30","value":758.21,"dateModification":"2015-07-31","status":"Final","valueRefId":0}]
Thanks in advance
Found it! Turns out my data elements did not have an id attribute, and this is somehow messing up the grid's ability to render the rows. I found a pointer to the solution in https://github.com/SitePen/dstore/blob/master/docs/Stores.md where it says:
The data should be an array of objects, and all the objects are considered to be existing objects and must have identities
After adding a unique identifier to my data, everything works ok.

Ruby on Rails: How to generate an array from records to display in Highcharts?

I need to display a dataset as a Highcharts column chart. I don't know how to pass the data to the Javascript method of Highcharts to display my Business Process score regarding the day.
The dataset is built in my BusinessProcess controller:
#business_process_history = DmMeasure.where("period_id between ? and ? and ODQ_object_id = ?", first_period_id, current_period_id, "BP-#{#business_process.id}").select("period_day, score").order("period_id")
This gives the expected 2 fields, 10 records result and would perfectly display in a HTML table.
UPDATE :
The suggestion by Tobago gives the expected array of arrays,
[["20140820", #<BigDecimal:54655c8,'0.997E2',18(45)>], ...]
but the issue is not solved.
Here is the function call including suggestion from Tobago:
<script>
$(function () {
$('#measures').highcharts({
chart: {type: 'column'},
title: {text: 'Data quality trend'},
xAxis: {
title: {text: 'Time'}
},
yAxis: {
title: {text: 'Score'}
},
series: [{
data: <%= #business_process_history.map { |bp| [bp.period_day, bp.score] } %>
}]
});
});
</script>
this script produces nothing in the measures DIV, while a hardcoded list of values does generate a graph.
I tried several ways to do it, but still I can't manage.
Can you help me on this ?
Thanks a lot,
Best regards,
Fred
Try:
#business_process_history.map { |bp| [bp.period_day, bp.score] }
Thanks to Tobago's suggestion, the final solution is:
#business_process_history.map { |bp| [bp.period_day, bp.score.to_f] }
1 - The map method with the block generates the correct array of arrays
2 - The to_f method applied to score field makes sure the data type meets Highcharts expectations.
Thanks Tobago !
Fred

Categories

Resources