Created
May 2, 2019 15:44
-
-
Save gpDA/4d485a202555bcecb387aaa6dab61d59 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ./components/Chart/Chart.js | |
| import Moment from 'moment'; | |
| import { extendMoment } from 'moment-range'; | |
| // moment.js + moment-range | |
| const moment = extendMoment(Moment); | |
| let now = moment(new Date()); | |
| // var formatted_now = now.format('HH:mm:ss'); | |
| let five_min_ago = moment(now).subtract(5, 'minutes'); | |
| // let formatted_then = five_min_ago.format('HH:mm:ss'); | |
| // get the range from now to five minutes ago with steps of 10 seconds | |
| // and initialize array for x_axis in the LINE chart | |
| const range1 = moment.range(five_min_ago, now); | |
| let acc = Array.from(range1.by('second', { step: 10 })); | |
| var x_axis = Array.from(acc.map(m => m.format('HH:mm:ss'))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment