Hi I'm fairly new to JavaScript and d3.js. I've created my chart and everything is running great on that end of things. However I'm trying to display some information in text in addtion to the graph which just shows montly sales total this year in comparison to the previous finacial year result.
The weird thing that I'm getting is that the text that is being displayed in the h2 is just showing [object Object] even though all the data is loading in fine when I've de-bugged it in firebug it shows this http://i.imgur.com/rOnZQXG.png (I cant embedd as I dont have a high enough rep)
which is the correct data
This is the code that I've used for the text -
d3.csv("OrderValueToday.csv", function(today) {
console.log(today);
var totalSales = today
svgLabel = d3.select("#label").append("h2")
.text(totalSales)
});
The CSV that I'm getting already has the total sales today so there is no summing done on my end this is already been done for me when I get the data. The CSV is formatting like so
Today
20000
and this is the same pretty much for all the data that I have. If you could help me out fix this problem that would be fantastic as this the final thing that get this project done. Cheers
By the looks of things you're passing in an array containing an object. You just need to access the Today value.
d3.csv("OrderValueToday.csv", function(obj) {
var text = 'Total sales today = ';
var totalSales = text + obj[0].Today;
svgLabel = d3.select("#label").append("h2")
.text(totalSales);
});
Related
A few days ago I got help from Stack Overflow to modify my then Apps Script code used to make calendar events from info on Google sheet, so as to tick a checkbox whenever an entry from the corresponding row is made and subsequently make new events only when the checkbox is unticked.
function addEvent() {
let webinarCalendar = CalendarApp.getCalendarById("blablablablablabla#gmail.com");
let calendarSheet = SpreadsheetApp.getActiveSheet();
let schedule = calendarSheet.getDataRange().getValues();
schedule.splice(0, 1);
const k = 16; // colIndex of checkbok col
const created = schedule.map(e => [e[k]]);
schedule.forEach(function(entry, i) {
if (entry[k] == true) { return; }
webinarCalendar.createEvent(entry[3], entry[14], entry[15], {description: entry[13]});
created[i][0] = true;
});
calendarSheet.getRange(2, k + 1, created.length, 1).setValues(created);
}
This current code worked just fine until 2 days ago when I updated 3 of the 4 cells with the required inputs to work on an array formula so that they get populated automatically whenever a new row entry is made.
The error on the app script console says :
Exception: The parameters (String,String,String,(class)) don't match the method signature for CalendarApp.Calendar.createEvent.
The parameters required for this createEvent() as per documentation are title(string), start time(string), finish time(string) and description(which is inside a javascript object I think and is also a string). To ensure that the datatype did not somehow get changed in the process of creating array formula, I cross checked the cells with an ISTEXT() and all of the inputs returned TRUE.
Second trial that I made was to change the splice() from (0,1) to (0,2) so that it ignores the first row which has the array formula written into the cells, which also did not fix the issue.
I would greatly appreciate if someone could show me what is causing this issue and help me fix it.
I don't know why it worked previously, but startTime and endTime should be Date.
I have checked that you columns are String.
Reference:
createEvent(title, startTime, endTime, options)
The error on the app script console says : Exception: The parameters (String,String,String,(class)) don't match the method signature for CalendarApp.Calendar.createEvent.
This is simply saying it's reading from data that is not in the proper data type. In this case, perhaps, try encasing the entries with 'new Date(entry[x])' for the respective start and end date/time entries.
For people trying to run the scripts, one underlying cause might be the fact that you may be using US locale when the date have been formatted as UK.
(e.g. Date that App Script is looking for is mm/dd/yyyy tt:tt:tt, but if you click in the formula cell it shows as dd/mm/yyyy tt:tt:tt)
What you would do is to go to Files > General > Locale > (Country of Choice) > Save settings.
You would then reload the page and try if the script is working now without that "Cannot find method createEvent(string,string,string)" error.
The line of code to use in your script would be:
SpreadsheetApp.getActive().setSpreadsheetLocale('en_UK');
You could include it in your onOpen trigger function.
Sorry - I'm a newbie!
I need to use a script to read a date from a Googlesheet, add a week and save the new date back to the sheet.
I've tried various suggestions from various posts without success. The approach I thought should work is failing to get a millisecond value from a date from a cell - subsequent processing appeared OK.
var oldDate = sheet.getRange('oldDateRange').getValue(); // obtains a date object and then...
var oldDateValue = oldDate.getMilliseconds() // I expected to return milliseconds but shows as undefined...
See link to a simplified illustration sheet and script illustrating my problem.
This is my first question on StackOverflow - feedback welcome on how to make it more helpful for others....
In order to convert the date obtained from the sheet to milliseconds, I think you simply need to replace .getMilliseconds() with .getTime()
I am building an app that records my spending with Angular 5. I want to take the data input which includes an integer(spend amount) and a date and basically show a daily spend amount as well as total spend and other weekly categories etc. The first thing I have been trying to get is a daily spend. So I thought it would be best to add dynamically to an object containing with property as date and value as total spend amount for that day. Adding dynamically to the object if the date in question doesn't exist yet. The part which currently doesn't work is that I can't seem to add to the value of an already defined property (e.g a date)
dailySpends =
{
"2017-12-01": 0, // <-- I want to add to this with every new entry that is also on this date for a running total.
}
I have a function which works on click called addItem(), it does a number of things and one of the things I want it to do is add to this running daily total. So far I have written this.
for(var key in this.dailySpends){
if(this.dailySpends[key] == this.date){
this.dailySpends[key] += this.spendAmount; //<<--Problematic line
alert(Object.entries(this.dailySpends)); //alert for checking entry
}
else this.dailySpends[this.date] = this.spendAmount;
alert(Object.entries(this.dailySpends)) //alert for checking entry
}
So update the object fine when new dates are put in, but I cant seem to update the value of already defined properties. Would it be better if I was working with an array, or is there a simple way of adding to it that I am missing.
I'm far from good at javascript. I'm cobbling together a page to analyze a csv file and created a page with results.
So I'm using papaparse.js for csv parsing and the stepFn to process each line, to eliminate records using various selection criteria.
I've also included moment.js to handle dates and times.
so there's 3 pieces of data I want to work with. (I'm simplifying).
[fundraising] team, amount, and date (which I'll store as a unix time integer).
I've been trying to see if outdata[teamname] exists, and if it does, update the amount. And if the amount >= goalamount, then populate date (if it's not already populated).
basically my web page allows them to define selection criteria, a goal, and to choose whether the challenge was [who gets their first]/sort on date, or [who got the most] sort on amount. [where total can actually be a count or
if the team isn't in the outdata array, add it, and place in it the total and a date (which of course I have to check for goal-reaching).
I've tried
var exists = typeof outdata[thisteamname];
if (exists == undefined)
{
outdata.push({ team: thisteamname, total: usevalue, adate: 0 });
}
else
{
var z = outdata[thisteamname]['total'];
//---->>> Cannot read property 'total' of undefined
outdata[thisteamname]['total'] += usevalue;
}
etc .. but i think I'm going about it all wrong. Suggestions? I will also need to sort the outdata array by eithe date or total, and loop through it for a top-ten style list at the end to write html.
all help appreciated, I know my javascript looks rather BASICy.
In my Firebug, it is showing me:
TypeError: this[r]._ticks[0] is undefined
But in my JS Array, the items are well constructed. Should not be the data problem.
So, as i said it should not be the data problem. The mystery is:
The problem is not consistent, just that SOMETIME JUST GOT WHOLE BLANK.
I have multiple log ranges (e.g, Show 1 week, Show 1 day, Show 1 hour), then sometime some got BLANK like now and at the same time, graphs are OK in some time ranges. And next time, this range got OK and next range got problem. (With this same code, same data)
I am super sure all my Array Rooms are filled with respective data inside. (I got no blank or corrupted array rooms)
I'm outta idea already :S
Please help.
I have the same problem this day, and resoled this by hard coding the second array value is number but not string type. You can do this simply in php code: $output["1"]=(double)$var, then try to use json_encode to output the data.
Here is the difference example:
valid array format:
var data=[[['2014-01', 2],['2014-02',5.12],['2014-03',13.1],['2014-04',33.6],['2014-05',85.9],['2014-06',219.9],['2014-07',39.9],['2014-08',99.9]]];
invalid array format:
var data=[[["2014-02","1920.97"],["2014-03","2040.92"],["2014-04","1704.52"],["2014-05","1630.88"],["2014-06","207.43"]]]
Use parseFloat(var) or parseInt(var) before passing data to the graph.
Where var is your variable or value which you are passing to graph.