Apply Tooltip to diffrent datasets or pass an array to tooltip in Chart.js? - chart.js

I am trying to show multi line graph for showing profit/loss . I am able to plot graph.
var niftyProfit = [];
var niftyProfitChartData = [];
var sum = 0;
data.forEach(function(obj) {
niftyProfit.push(obj.profit);
});
for (var i in niftyProfit) {
sum = sum + niftyProfit[i];
niftyProfitChartData.push(sum);
}
obj.profit is the p/l column data. I want to populate the value, which I did in for loop for eg. consider profit = [4,2,-3,-5], then my final array to populate in chart would become [4,6,3,-2]. I ploted data on chart which is array niftyProfitChartData , now In tooltip on hover its showing data from niftyProfitChartData .But I want to show data from niftyProfit array in tooltip . Here is Fiddle Link of what i tried till now .
http://jsfiddle.net/zkrh7/159/

Related

GEE try to get LST time series data

I try to get Daily LST data from Google Earth Engine.
Here is my code;
// Import image collection
var modis = ee.ImageCollection('MODIS/061/MOD11A1');
// A start date is defined and the end date is determined by advancing 1 year from the start date.
var start = ee.Date('2012-01-01');
var dateRange = ee.DateRange(start, start.advance(1, 'year'));
// Filter the LST collection to include only images from time frame and select day time temperature band
var modLSTday = modis.filterDate(dateRange).select('LST_Day_1km')
.map(function(image){return image.clip(studyArea)});
// Scale to Kelvin and convert to Celsius, set image acquisition time.
var modC = modLSTday.map(function(image) {
return image
.multiply(0.02)
.subtract(273.15)
.copyProperties(image, ['system:time_start']);
});
//Convert data to bands
var daily = modC.toBands();
//Creating sample points in the given geometry(study area; assets or simple rectangle)
var Sample_points = daily.sampleRegions({
collection: studyArea,
scale: 500,
geometries: true
});
//Getting LST values from sample points
var collection_with_latlon = Sample_points.map(function (feature) {
var coordinates = feature.geometry().transform('epsg:4326').coordinates();
return feature.set('lon', coordinates.get(0), 'lat', coordinates.get(1));
});
My problem is daily variable is not create sample points and does not get LST values. I used the same code for NDVI data, it works perfectly but in LST data it is not working.
when I use the;
var Sample_points = daily.select(2).sampleRegions({
collection: studyArea,
scale: 500,
geometries: true
});
SampleRegions works and gets LST values to the csv table in my drive. But it works for just one image. I need to get 366 images (a year) data.
Please give me some help...

Google Sheets Apps Script - How to add an Arrayformula and multiple associated IF functions within a script (Without showing the formula within UI)

I was wondering if someone is able to assist?
I'm trying to add an Arrayformula consisting of two IF functions, so I'm wanting to merge the following two formulas into one cell:
=ARRAYFORMULA(IF(D13:D104="","",(IF(K13:K104,K13:K104*20,"$0"))))
=ARRAYFORMULA(IF(D105:D="","",(IF(K105:K,K105:K*C4,"$0"))))
So the first section of the sheet needs to be multiplied by 20, and then the figure has changed and needs to be multiplied by 25 (which is cell C4)
Is it possible to merge these into one cell containing an Arrayformula+the two IF functions (or is there another/easier way for this)
Is it possible to add this into Google Apps Script so that it works in the backend (so not just a script that applies the formula into a cell - but doesn't show in the frontend or sheet)
More of a general question - When using Arrayformula with IF; and for example the output is specific text e.g. "Test Complete" associated to the range F2:F (checking if E2:E contains a particular phrase e.g. "Done") - for the empty cells in between (due to setting the False outcome as "") is it possible to somehow randomly add data into these blank cells without interrupting the formula? (so I have to option for automated text if the cell to the left states a particular term/word, but still have the option to manually add random data into blank cells)
Any assistance would be greatly appreciated
As for 1st and 2nd questions: it looks like a task for a custom function. Something like this:
function MULTI() {
var sheet = SpreadsheetApp.getActiveSheet();
var cell = sheet.getActiveCell();
var row = cell.getRow();
var value = sheet.getRange('K'+row).getValue();
return (row < 105) ? value * 20 : value * 25;
}
It gets a value from column K and multiplies it by 20 if the row less than 105 and by 25 for the rest of rows.
Here is the variant of the same formula that uses the cell 'C4':
function MULTIC4() {
var sheet = SpreadsheetApp.getActiveSheet();
var cell = sheet.getActiveCell();
var row = cell.getRow();
var value = sheet.getRange('K'+row).getValue();
var c4 = sheet.getRange('C4').getValue();
return (row < 105) ? value * 20 : value * c4;
}
And it can be done with the trigger onEdit():
function onEdit(e) {
var col = e.range.columnStart;
if (col != 11) return; // 11 = K
var sheet = e.source.getActiveSheet();
if (sheet.getName() != 'Sheet1') return;
var c4 = sheet.getRange('C4').getValue();
var row = e.range.rowStart;
var dest_cell = sheet.getRange('D'+row);
var value = sheet.getRange(row,col).getValue();
var result = (row < 105) ? value * 20 : value * c4;
dest_cell.setValue(result);
}
It recalculates automatically the value in the cell of column 'D' (current row) every time when you're changing value in the cell of column 'K'. On the sheet 'Sheet1'.

Is there a way to check over a column range for a certain data?

I have 2 workbooks,
Spreadsheet A has multiple sheets of the same form.
Spreadsheet B records contain cells from Spreadsheet A sheets into a single row per sheet (log).
The first column in Spreadsheet B contains hyperlinks of all sheets in Spreadsheet A. I need to check the hyperlinks column in Spread B as follows:
if hyperlink exist in column A,
check for the next sheet in Spreadsheet A index++
else
record the new data in a row after the last row,,,,
my code used to have clear() function to start submission from scratch to Spreadsheet B, but it's not efficient, execution time wise.
I am trying to manipulate my current code to check manually on existing records and i++/submit new row based on this logic.
you can ignore all missing lines of code because i have it working, i just need the logic of the idea of doing this, since I am not advanced in Apps Script. Thanks in advance for your help.
Spreadsheet A - Sheet1
Spreadsheet A - Sheet2
Spreadsheet B
I want the if statement to run on the Sheet link column in Workbook B.... in case of adding Sheet #3 to Workbook A (picture 1&2), upon submission, I want to check on Sheet links in Workbook B log (because it's unique) if it exists, i++.... if doesn't exist, add 3rd record in log.
for(var index = 2; index < WBA.length; index++)
{
var Sheet = "https://docs.google.com/spreadsheets/d/WBA ID/edit#gid=";
var SID = WBA[index].getSheetId();
var SheetID = Sheet + SID;
var Data = WBB.getDataRange().getValues();
for(var i = 0; i < Data.length; i++)
{
if(Data[i][1] == SheetID)
i++
else
{
var lastRow = WBB.getLastRow() + 1;
var Sheets_ID = new Array()
Sheets_ID.push( [WBA[index].getSheetId()] )
WBB.getRange(lastRow,1).setFormula('=hyperlink("https://docs.google.com/spreadsheets/d/WBA ID/edit#gid=' + Sheets_ID +'")');
var PN_Source = WBA[index].getRange(6,3,1,1).getValues(); //getRange(row number, column number, number of rows, number of columns)
var SC_Source = WBA[index].getRange(8,3,1,1).getValues();
Try this:
function checkForLink() {
var ssB=SpreadsheetApp.getActive();
var sh1=ssB.getActiveSheet();
var rg1=sh1.getRange(1,1,1,4);
var vA1=rg1.getValues()[0];
var hObj={};
vA1.forEach(function(el,i){if(el){hObj[el]=i;}});
var linkA=sh1.getRange(2,hObj['Sheet Link']+1,sh1.getLastRow(),1).getValues().map(function(r){return r[0];});
var ssA=SpreadsheetApp.openById('SSA ID');
var shts=ssA.getSheets();
shts.forEach(function(sh,i){
var vA=sh.getRange(1,1,2,sh.getLastColumn()).getValues();
var sObj={};
vA[0].forEach(function(e,i){sObj[e]=i;});
var shlink=Utilities.formatString('https://docs.google.com/spreadsheets/d/%s//edit#gid=%s',ssA.getId(),sh.getSheetId());
if(linkA.indexOf(shlink)==-1) {
sh1.appendRow([vA[1][sObj.date],vA[1][sObj.age],vA[1][sObj.name],shlink]);
}
});
}

how to make the last row in a UICollectionview to be sticky using swift 3

I used multi directional scrolling with a custom flow layout in a UICollectionView to create a numeric table.
The structure of the table should be like this. A numeric table which has the sum up value in the last row:
Now the first column and the first row of the table is static i.e sticky. I want the last row also to get Sticked at the bottom of the view. Kindly help me.
This is my current view of the table:
Thank You in advance.
if section == sectionCount-1 {
for item in 0...rowCount-1 {
let indexPath = IndexPath(item: item, section: section)
if let attrs = cellAttrsDictionary[indexPath] {
var frame = attrs.frame
if item == 0 {
// Assigning the size of the first column as 200
frame.size.width = 200
frame.origin.x = xOffset
}
// Configuration for the last row in the last cell.
// Subtracting the Cell height from the entire Collection View height and assigning it as the frame for the last row of the Table i.e precisely on Y position.
frame.origin.y = (collectionView?.frame.size.height)! + yOffset - CGFloat(CELL_HEIGHT)
attrs.frame = frame
}
}
}

Summing rows on a tabular form in apex 4.2 for validation

How can I sum fields on each row in a tabular form in APEX 4.2 to get a total for that row before I submit the page in order to do page validation?
For example if the first row has 6 in field a and 6 in field b the total for the first row should be 12 and on the second row if field b is 5 and field c is 5 the total for the second row should be 10.
So I want to get totals based on rows not column. Is that possible?
Yes, its possible. If you know javascript/jquery, you'll get along well with my solution. This is what you have to do:
get the name attribute(using inspect element of your browser) of the field you want to sum up. Names of fields in oracle apex usually goes like 'f01' or 'f02' and so on. Once you get the fields, create a javascript function or you can use this one if you like:
function sumUpRows(columnforsum,itemstobeadded){
var numofcols = arguments.length;
var numofrows = $("[name=" + arguments[0] + "]").length;
var summ = 0;
for(x=0;x<numofrows;x++){
for(i=1;i<numofcols;i++){
summ = summ + Number($("[name=" + arguments[i] + "]").eq(x).val());
}
$("[name=" + columnforsum + "]").eq(x).val(summ);
}
}
Put function above in "function and global variable declaration" part of your page. Then create a "before page submit" dynamic action. Set its action to "execute javascript" then put this line of code:
sumUpRows("nameoffieldwheresumwillbeassigned","nameofitem1","nameofitem2","nameofitem3");
Here's a sample :
sumUpRows("f04","f01","f02","f03");
For your question in the comment section, the answer is yes. To get the sum of a row automatically as you fill up the boxes on that row, you can use this function:
function sumUpRowsAsYouGo(whatelement){
var numofrows=$("[name=f01]").length;
var summ = 0;
for(i=0;i<numofrows;i++){
if($(whatelement).attr("id") == $("[name=" + $(whatelement).attr("name") + "]").eq(i).attr("id")){
for(a=1;a<(arguments.length-1);a++){
summ += Number($("[name="+ arguments[a] + "]").eq(i).val());
}
$("[name="+ arguments[arguments.length-1] + "]").eq(i).val(summ);
break;
}
}
}
you can use this function like this(put these lines in the "Execute on Page load" and "after refresh" dynamic action of your tabular form region):
$("[name=f01]").change(function(){
sumUpRowsAsYouGo(this,"f01","f02","f03","f04");
}
);
$("[name=f02]").change(function(){
sumUpRowsAsYouGo(this,"f01","f02","f03","f04");
}
);
$("[name=f03]").change(function(){
sumUpRowsAsYouGo(this,"f01","f02","f03","f04");
}
);