I have a line graph drawing using data created like so:
for (var i = 1; i < 366; i++) {
visits += Math.round((Math.random() < 0.5 ? 1 : -1) * Math.random() * 10);
data.push({ date: new Date(2018, 0, i), value: visits });
}
The rest of the options set look like:
__this._chart.data = data;
var dateAxis = __this._chart.xAxes.push(new am4charts.DateAxis());
dateAxis.renderer.grid.template.location = 0;
dateAxis.renderer.axisFills.template.disabled = true;
dateAxis.renderer.ticks.template.disabled = true;
var valueAxis = __this._chart.yAxes.push(new am4charts.ValueAxis());
valueAxis.tooltip.disabled = true;
valueAxis.renderer.minWidth = 35;
valueAxis.renderer.axisFills.template.disabled = true;
valueAxis.renderer.ticks.template.disabled = true;
var series = __this._chart.series.push(new am4charts.LineSeries());
series.dataFields.dateX = "date";
series.dataFields.valueY = "value";
This draws a random line for the whole year and it works.
We dont want to show every day, we want to show monthly data. So I have data that when processed shows up in the form:
{
category: Mon Oct 31 2016 20:00:00 GMT-0400 (Eastern Daylight Time)
column-1: 50
}
Theres only 9 of them and they cover up to January 2019, so there would be huge gaps between the data points. the object name of category is different to date but I set the series' dateX = "category".
So my question is, can the line graph be used to do monthly data where there could be gaps in the data?
If so, how do I get it to work? I use the rest of the options the exact same as the test that is working, except for hte changed values of series' dateX and valueY.
Related
What I am trying to do is transfer rows depending on the value in column p starting at row number 7. If cell in column P has a value of " Order" then copy that row from column B to Q to a completely separate already made spreadsheet. I have the script written in the target sheet.
Currently my script does loop through the row and will console.log the data I need... My issue is I have tried multiple things to then write the data to the correct range and can't figure it out.. I need to write the data to starting at row7 columnB... could use a little help..
function transferMonth() {
// SETTING UP THE LAST MONTH SHEET TO PULL NON SOLD DATA FROM
const lastmonthSheetss = SpreadsheetApp.openById("ID OF SPREADSHEET").getSheetByName("CDJR");
const lastSourceRow = lastmonthSheetss.getLastRow();
const sourceRange = lastmonthSheetss.getRange(7, 2, lastSourceRow, 15);
const sourceData = sourceRange.getValues();
// SETTING UP THE SHEET WHERE WE WANT TO TRANSFER LAST MONTHS DATA TO
const targetsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("TestCopy");
const lastRow = targetsheet.getLastRow();
const lastCol = targetsheet.getLastColumn();
var sdata = [];
// KEY FOR ACCESSING THE DATA PULLED FROM LAST MONTHS SHEET
//console.log (sourceData[0]);
//console.log(sourceData[0][1]);
//console.log(sourceData[0][3]);
//console.log(sourceData[0][5])
//console.log(sourceData[0][14])
//console.log(sourceData[1][1]);
//console.log(sourceData[1][14]);
//SETTING UP PLACE TO STORE VALUES THAT NEED COPIED
for (i = 0; i < sourceData.length; i++) {
if (sourceData[i][14] === 'Order') {
sdata.push.apply(sdata, lastmonthSheetss.getRange(i + 7, 2, 1, 15).getValues());
sdata.push(i);
}
console.log(sdata)
}
targetsheet.getRange(7,2).setValues(sdata);
}
You can start with this.
Script:
function transferMonth() {
// SETTING UP THE LAST MONTH SHEET TO PULL NON SOLD DATA FROM
const lastmonthSheetss = SpreadsheetApp.openById("ID OF SPREADSHEET").getSheetByName("CDJR");
const lastSourceRow = lastmonthSheetss.getLastRow();
const sourceRange = lastmonthSheetss.getRange(7, 2, lastSourceRow, 15);
const sourceData = sourceRange.getValues();
// SETTING UP THE SHEET WHERE WE WANT TO TRANSFER LAST MONTHS DATA TO
const targetsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("TestCopy");
const lastRow = targetsheet.getLastRow();
// use filter to only get the data with 'Order' as the 15th column
var sdata = sourceData.filter(x => x[14] === 'Order');
// always write starting at B7
targetsheet.getRange(7, 2, sdata.length, sdata[0].length).setValues(sdata);
}
Sample Data:
Initial target sheet:
Output:
Note:
Your main issues were the wrong usage of setValues and the pushed index on the array, aside from that, your code should still be workable.
I have a need to get the offset (in hours) for any given time zone in Adobe ColdFusion. The idea is to pass in a time zone (America/Phoenix) and get back it's offset taking into account daylight savings.
Well after looking for what seemed forever, I realized CF doesn't have a way to do it. You need to delve into it's underbelly (JAVA) to get what you need. So, with a little help from a post by Ben Nadel on time zones, I figured it out and decided to pass on what I learned to a fellow dev traveler who may need it one day.
<cfscript>
/*
Author: Steve Holland (Avant Solutions Group)
Website: www.avantsolutionsgroup.com
License: https://opensource.org/licenses/MIT
*/
private struct function calcTZOffset(required string timeZoneID, boolean returnTimezones="false") {
// Init the timezome java class
var tz = createObject( "java", "java.util.TimeZone" );
// Get the timezone info
var tzInfo = tz.getTimeZone(
javaCast( "string", arguments.timeZoneID )
);
// Get the offset for the timezone
var tzOffset = tzInfo.getOffset(
javaCast("long", 0)
);
// Get the offset hours
var tzOffsetHours = tzOffset / 3600000;
//Check if the timezone is observing DST
var inDST = tzInfo.observesDaylightTime();
var tzOffsetHoursDST = inDST ? tzOffsetHours + 1 : tzOffsetHours;
//Return
var offset = {
inDST = inDST,
timeZone = arguments.timeZoneID,
offsetMillis = tzOffset,
offsetHours = tzOffsetHours,
dstOffsetHours = tzOffsetHoursDST,
timeZones = (arguments.returnTimezones)? tz.getAvailableIDs(): [] //Allow the user to return all the timezones (optional)
};
//writeOutput(tzOffset / 3600000);
return offset;
}
tzID = "America/Denver";
//tzID = "America/Phoenix";
//tzID = "America/Los_Angeles";
offset = calcTZOffset(tzID, false);
//Dump out the results
writeDump(var=offset);
</cfscript>
This should give you the UTC offset in hours. I know it works in Lucee but should in ACF also.
var timeZone = getTimeZoneInfo("America/Phoenix");
WriteDump(timeZone.utcHourOffset);
I am using amcharts line chart.
I have data for last 24 hours and its recorded for every seconds.
I am trying to group data in amcharts but it displays only 2 data points on chart.
1 data point is from yesterday and 1 from today.
Here is my code:
var multiLineChart = am4core.create(
"multilineChartdiv",
am4charts.XYChart
);
multiLineChart.paddingRight = 20;
multiLineChart.data = historicalData;
var dateAxis1 = multiLineChart.xAxes.push(new am4charts.DateAxis());
dateAxis1.renderer.grid.template.location = 0;
dateAxis1.minZoomCount = 1;
dateAxis1.renderer.minGridDistance = 60;
// dateAxis1.baseInterval = {
// timeUnit: "minute",
// count: 5,
// };
// this makes the data to be grouped
dateAxis1.groupData = true;
dateAxis1.groupCount = 500;
var valueAxis = multiLineChart.yAxes.push(new am4charts.ValueAxis());
var series1 = multiLineChart.series.push(new am4charts.LineSeries());
series1.dataFields.dateX = "date";
series1.dataFields.valueY = "heartRate";
series1.tooltipText = "{valueY}";
series1.tooltip.pointerOrientation = "vertical";
series1.tooltip.background.fillOpacity = 0.5;
multiLineChart.cursor = new am4charts.XYCursor();
multiLineChart.cursor.xAxis = dateAxis1;
var scrollbarX = new am4core.Scrollbar();
scrollbarX.marginBottom = 20;
multiLineChart.scrollbarX = scrollbarX;
I need to show data points for at least every 5 or 10 minutes.
If your timestamp is a string, make sure the inputDateFormat is set to match your date format as documented here as the default format is yyyy-MM-dd, truncating everything else to look like daily data, similar to your screenshot:
chart.dateFormatter.inputDateFormat = 'yyyy-MM-dd HH:mm:ss' //adjust as needed
Since your data is in seconds, it is also recommended to set the baseInterval accordingly to also ensure that your data is rendered correctly.
dateAxis1.baseInterval = {
timeUnit: "second",
count: 1,
};
The contents to the text layer are added from csv import. Some are short length and some are long, contain 2 words and take up 2 lines in the layer. What I need is after the content is added, the layer should be horizontally and vertically aligned to another layer. I want to do this alignment using a script.
var doc = app.activeDocument;
var grps = doc.layerSets;
var pnamegrp = grps.getByName('Group 1');
var childlyr = pnamegrp.layers.getByName('child');
childlyr.textItem.contents = pname; //come from a csv file
var parentlyr= pnamegrp.layers.getByName('ReferenceRectangle');
Align_HorizCenter_VerticalCenter_withreference( childlyr , parent);
function Align_HorizCenter_VerticalCenter_withreference( child, parent){
//need help to write this
}
I am using Photoshop cc 2015 and JavaScript jsx file scripting.
Just incase somebody is looking for a solution. Translate is the method to move layer. The number of pixels to be moved can be determined by the difference in the width between the target and reference layer.
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.INCHES;
var doc = app.activeDocument;
var grps = doc.layerSets;
var pnamegrp = grps.getByName('Group 1');
var pnamelyr= pnamegrp.layers.getByName('pname'); //target
var pnameREF = pnamegrp.layers.getByName('Rectangle 1'); //reference var LB = pnameREF.bounds;
var RWidth = (LB[2].value) - (LB[0].value);
var RHeight = (LB[3].value) - (LB[1].value);
pnamelyr.textItem.contents = pnamearr[i];
LB = pnamelyr.bounds;
TWidth = (LB[2].value) - (LB[0].value);
THeight = (LB[3].value) - (LB[1].value);
var OffsetX = (RWidth - TWidth)/2;
var OffsetY = (RHeight - THeight)/2;
pnameTGT.translate(OffsetX,OffsetY); //move layer by offset pixels from the current position
I can sort (descending) my displayed results by a selected value using this code:
PivotField field = pivotTable.RowFields[0];
field.IsAutoSort = true;
field.IsAscendSort = false;
field.AutoSortField = 1;
This is what I see (Total Purchases displayed are indeed shown from most to least):
Or, I can only display Description ranges whose "Percentage of Total" value is at least 1% with this code:
private void HideItemsWithFewerThan1PercentOfSales()
{
int FIRST_TOTAL_PRICE_ROW = 8;
int ROWS_BETWEEN_PERCENTAGES = 4;
var pivot = pivotTableSheet.PivotTables[0];
var dataBodyRange = pivot.DataBodyRange;
int currentRowBeingExamined = FIRST_TOTAL_PRICE_ROW;
int rowsUsed = dataBodyRange.EndRow;
pivot.RefreshData();
pivot.CalculateData();
// Get grand total of purchases for all items and months, and calculate what 1% of that is
Cell totalTotalPurchasesCell = pivotTableSheet.Cells[rowsUsed - 2, _grandTotalsColumnPivotTable + 1];
double totalTotalPurchases = Convert.ToDouble(totalTotalPurchasesCell.Value);
var onePercentOfTotalPurchases = totalTotalPurchases / 100;
// Loop through PivotTable data, hiding where percentage < 0.01 (1%)
while (currentRowBeingExamined < rowsUsed)
{
Cell priceCell = pivotTableSheet.Cells[currentRowBeingExamined, _grandTotalsColumnPivotTable + 1];
String priceStr = priceCell.Value.ToString();
Double price = Convert.ToDouble(priceStr);
if (price < onePercentOfTotalPurchases)
{
pivotTableSheet.Cells.HideRows(currentRowBeingExamined - 1, ROWS_BETWEEN_PERCENTAGES);
}
currentRowBeingExamined = currentRowBeingExamined + ROWS_BETWEEN_PERCENTAGES;
}
}
...like so:
...but I can't get them both to work at the same time. So I can either hide the Descriptions with less than 1% of the percntage OR I can sort by Total Purchases descending, but I'm not able to accomplish both at the same time. My code to try to accomplish both is as follows:
. . .
pivotTable.AddFieldToArea(PivotFieldType.Row, DESCRIPTION_COLUMN);
pivotTable.RowHeaderCaption = "Description";
// Dragging the second field to the column area.
pivotTable.AddFieldToArea(PivotFieldType.Column, MONTHYR_COLUMN);
pivotTable.ColumnHeaderCaption = "Months";
// Dragging the third field to the data area.
pivotTable.AddFieldToArea(PivotFieldType.Data, TOTALQTY_COLUMN);
pivotTable.DataFields[0].DisplayName = "Total Packages";
pivotTable.AddFieldToArea(PivotFieldType.Data, TOTALPRICE_COLUMN);
pivotTable.DataFields[1].DisplayName = "Total Purchases";
. . .
// Sort by "Total Purchases" descending
PivotField field = pivotTable.RowFields[0];
field.IsAutoSort = true;
field.IsAscendSort = false;
field.AutoSortField = 1; // This is the "Total Purchases" field
pivotTable.PivotTableStyleType = PivotTableStyleType.PivotTableStyleLight16;
pivotTable.RefreshDataFlag = true;
pivotTable.RefreshData();
pivotTable.CalculateData();
pivotTable.RefreshDataFlag = false;
List<String> contractItemDescs = GetContractItemDescriptions();
ColorizeContractItemBlocks(contractItemDescs);
HideItemsWithFewerThan1PercentOfSales();
FreezePanePivotTable(HEADER_ROW, 2);
FormatPivotTableNumbers();
ConfigureForPrinting(pivotTableSheet.Cells.Rows.Count);
It's as if the sorting order is not being respected when HideItemsWithFewerThan1PercentOfSales() is called - the row numbers that method "sees" is not the row numbers according to the sorting that has been established.
How can I get both the sorting AND the hiding to work?
NOTE: Calling HideItemsWithFewerThan1PercentOfSales(); prior to the sorting code does NOT work - it still shows/hides some of the wrong things.
Please check the reply in this thread in Aspose.Cells forum.
Note: I am working as Developer Evangelist at Aspose