Unable to get date xAxis working with unix timestamp - anychart

I am having some trouble understanding the Anychart axis documentation.
Using this example https://jsfiddle.net/gvb29tc2/2/ i have some data points i want to plot using the unix date stamp for x-axis.
[
1497786600, // <- ID
'Sun Jun 18 2017 19:53:35 GMT+0800 (SGT)', // <- date
1497786815630, // <- unix date
...
]
I select it using x: new Date([2]), but i cant get it to display. Just outputs a single vertical line. Also, i wanted the major tick on 5min and minor on 2min. Can't get that working either.
Since all i am trying is a simple line chart, i think i'm missing something stupid. Can someone explain where i'm going wrong please ?

You shouldn't use any functions in mapping settings.
Right way is
x:[2]
After that you can work with mapped value as timestamp
https://jsfiddle.net/gvb29tc2/4/

Related

How to map from an Array into a Google react Chart (React)?

I actually face a problem with react I did not expect so far. Actually I have a google-react-chart Calender and an array, that I have parsed from different Date formats in one. Now i want to parse through my array and to map it's data to my google-react-chart calender. Unfortunatley I did most of my coding on the web in php so far, and guys, I don't have any idea how I can bring this construction to work :))
I tried to replace my hard coded data with a mapping function, but - as you may know - that only leads to a parsing error :)
So my simple question is: How can I process my arrayData to my Google react chart calender?
//did not work
mydateArray.map((item) =>{JSON.parse{item)}
The problem is that you are trying to parse a string, instead of a JSON object.
If you are getting this array from PHP, try passing it as a json_encode($variable), but not with the new Date() class. You can just pass it as the date string itself in the first position and the amount in the second position of the array;
Assuming you have the date and the data as something like this in PHP (before the json_encode):
$variable = [['MM/DD/YYYY', 50126],['MM/DD/YYY', 50126], and so on];
After you pass to React your PHP variable (via fetch or the dataset),
you can do something like:
mydateArray = JSON.parse(phpVariable);
and THEN, you can map it:
mydateArray.map(item => [new Date(item[0]), item[1]);
Just some Date warnings:
- Date in javascript must be constructed using Month/Day/Year, unfortunatelly. There is no createFromFormat, like PHP.
- The date ranges from 0 to 11, so october (10th month) must be written as 09/day/year, and so on.

React-Moment- Parsing ISO 8601 Time Left Into Readable Format

I'm trying to take the 'timeLeft field from the eBay API and turn it into something that looks normal, like 3 Hours, 10 Minute and 5 seconds left.
The data looks something like this: P3DT6H28M15S
I'm trying to use the React Moment module but can't figure out exactly how to do this.
This is my latest test:
<Moment format="h:mm:ss">
{card.sellingStatus && card.sellingStatus[0].timeLeft}
</Moment>
But this is returning 'invalid date'.
I also try the following code just to see what HTML output looks like, but i'm trying a different output field
<Moment>{card.listingInfo && card.listingInfo[0].endTime}</Moment>
note that endTime looks like this
2019-11-09T19:45:32.000Z
but the above code is generating the same exact value for each item
Tue Jan 01 2019 00:00:00 GMT-0500
even though all of the endTime fields are different
Any ideas as to what I might be doing wrong here?
So i mostly accomplished what I needed by using the react-timeago npm module.
<TimeAgo
date={new Date(
card.listingInfo && card.listingInfo[0].startTime
).toLocaleDateString()}
/>

Problems with diagnostics of prophet forecast

I am working with an dataset of crimes in chicago and specially working on a future prediction of the crime rate in chicago (from 2012 till 2016 I have data). I generated a forecast using the prophet package of facebook. It worked very well and all done. Now I would like to train and test my model. Therefore, I split the dataset into 70% train and 30% test. I trained the model and test it and at the end I got a nice plot. I am further interested in the diagnostic part. Prophet provides for that a function called cross_validation() which I used: df.cv<- cross_validation(m, initial = nrow(trainData), period = 365, horizon = nrow(testData), units = 'days')
. The problems is here, I am geting always this error and trying since yesterday to fix it, without success:
Fehler in generate_cutoffs(df, horizon.dt, initial.dt, period.dt) :
Less data than horizon after initial window. Make horizon or initial shorter.
Does somebody know how to fix this error and provide a list of diagnostics?
My train/test plot looks so:
And my train Dataset can be downloaded here: https://ufile.io/4e38c
And my test Dataset here: https://ufile.io/ds65p
I hope somebody could help me! It would be really great and I would really appreciate it. Thanks in advance!
Cross-validation will be applied on a sliding window, performing cutoffs based on the settings. Please read the docs here:
https://facebook.github.io/prophet/docs/diagnostics.html
The error you get because your sliding window is out of bounds. Try like this:
df.cv<- cross_validation(m, initial = 100, period = 100, horizon = 100, units = 'days')
I had similar issue and I managed to fix it by using string arguments such as horizon="365 days" , instead of int horizon = 365.
This solution worked on Python version.

anychart stock - range selection with mm:ss resolution

i'm using anychart stock 8.1.0. I have a dataset with 24 hours of date with per-second resolution. I would like for only a small 30 seconds subset of that data to be shown/zoomed on load.
I could not find out how to do this so i tried adding a range selector option like below but i couldn't get that working either.
rangeSelector.ranges([{
'text': 'Testing',
'startDate': '2006 May 16 13:00:00',
'endDate': '2006 May 16 13:00:30'
}
If i use the range selector slider i can zoom as i require but how do i define this in code ?
So to recap i'd like
have the chart zoomed on load for a specific time range of type
start-stop in format of dd/MM/yyy mm:ss
have range selector button options for various time ranges of same format as above.
thank you.
Yes, you can define your own custom periods for rangeSelector, but if you want to zoom to specific period on load you have to call selectRange() method after chart drawing.
If you want to show only 30 seconds in the beginning of your series you should put the following line into your code:
chart.selectRange("second", 30, "first-date", true);
You can learn more about this method here
And find a similar example of using it here

CakePHP: CakeTime i18nFormat for date and time

I'm using the CakeTime class for my localization of dates & times.
For dates it works like I want it to:
$timestring = $this->Time->format('Y-m-d H:i:s', time());
echo 'DateTime: '.$this->Time->i18nFormat($timestring);
// Result => DateTime: 11/08/2013
I want it to also display the time.
For example in the US they use AM/PM and in other places they use the 24 hour notation.
I've looked but can't seem to find a way to do this.
Any idea's?
Edit*
To be clear, the localization works perfectly for the dates(have the LC_TIME files), but the i18nFormat function only returns the date, and from what i saw, passing a format will use that format, not the localized one, example MM/DD/YYYY vs DD.MM.YYYY in a different locale
*Edit2:
The solution vicocamacho gave in the comments is the correct one
So to get the Date + Time in the localized form:
$this->Time->i18nFormat(time(), '%x %X') does the trick!
You can use the TimeHelper::i18nFormat method. You also can check this repo to find common date/time translations https://github.com/cakephp/localized be sure to store them in the APP/locale/<locale>/LC_TIMEdirectory

Resources