-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
377 additions
and
84 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<!doctype html> | ||
<html> | ||
|
||
<head> | ||
<title>Line Chart</title> | ||
<script src="https://moment.github.io/luxon/global/luxon.min.js"></script> | ||
<script src="../../../dist/Chart.js"></script> | ||
<script src="../../utils.js"></script> | ||
<style> | ||
canvas { | ||
-moz-user-select: none; | ||
-webkit-user-select: none; | ||
-ms-user-select: none; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div style="width:1000px"> | ||
<canvas id="chart1"></canvas> | ||
</div> | ||
<br> | ||
<br> | ||
Chart Type: | ||
<select id="type"> | ||
<option value="line">Line</option> | ||
<option value="bar">Bar</option> | ||
</select> | ||
<button id="update">update</button> | ||
<script> | ||
function randomNumber(min, max) { | ||
return Math.random() * (max - min) + min; | ||
} | ||
|
||
function randomBar(date, lastClose) { | ||
var open = randomNumber(lastClose * 0.95, lastClose * 1.05); | ||
var close = randomNumber(open * 0.95, open * 1.05); | ||
return { | ||
t: date.valueOf(), | ||
y: close | ||
}; | ||
} | ||
|
||
var date = window.luxon.DateTime.local(2017, 4, 1, 0, 0); | ||
var data = [randomBar(date, 30)]; | ||
var labels = [date.valueOf()]; | ||
while (data.length < 60) { | ||
date = date.plus({days: 1}); | ||
if (date.weekday <= 5) { | ||
data.push(randomBar(date, data[data.length - 1].y)); | ||
labels.push(date.valueOf()); | ||
} | ||
} | ||
|
||
var ctx = document.getElementById('chart1').getContext('2d'); | ||
ctx.canvas.width = 1000; | ||
ctx.canvas.height = 300; | ||
|
||
var color = Chart.helpers.color; | ||
var cfg = { | ||
type: 'bar', | ||
data: { | ||
labels: labels, | ||
datasets: [{ | ||
label: 'CHRT - Chart.js Corporation', | ||
backgroundColor: color(window.chartColors.red).alpha(0.5).rgbString(), | ||
borderColor: window.chartColors.red, | ||
data: data, | ||
type: 'line', | ||
pointRadius: 0, | ||
fill: false, | ||
lineTension: 0, | ||
borderWidth: 2 | ||
}] | ||
}, | ||
options: { | ||
scales: { | ||
xAxes: [{ | ||
type: 'time', | ||
distribution: 'series', | ||
ticks: { | ||
source: 'labels' | ||
} | ||
}], | ||
yAxes: [{ | ||
scaleLabel: { | ||
display: true, | ||
labelString: 'Closing price ($)' | ||
} | ||
}] | ||
} | ||
} | ||
}; | ||
var chart = new Chart(ctx, cfg); | ||
|
||
document.getElementById('update').addEventListener('click', function() { | ||
var type = document.getElementById('type').value; | ||
chart.config.data.datasets[0].type = type; | ||
chart.update(); | ||
}); | ||
|
||
</script> | ||
</body> | ||
|
||
</html> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict'; | ||
|
||
var luxonHelpers = require('./helpers.luxon'); | ||
var momentHelpers = require('./helpers.moment'); | ||
|
||
module.exports = momentHelpers.moment ? momentHelpers : (luxonHelpers.luxon ? luxonHelpers : undefined); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
'use strict'; | ||
|
||
var luxon, DateTime; | ||
try { | ||
luxon = require('luxon'); // eslint-disable-line global-require | ||
luxon = (luxon && luxon.DateTime) ? luxon : window.luxon; | ||
DateTime = luxon.DateTime; | ||
} catch (lxe) { | ||
// swallow the error here | ||
} | ||
|
||
|
||
module.exports = { | ||
|
||
luxon: luxon, | ||
|
||
createDate: function(value) { | ||
if (value === undefined) { | ||
value = new Date(); | ||
} | ||
|
||
if (typeof value === 'number') { | ||
return DateTime.fromMillis(value); | ||
} | ||
if (value instanceof Date) { | ||
return DateTime.fromJSDate(value); | ||
} | ||
if (value instanceof DateTime) { | ||
return value; | ||
} | ||
return undefined; | ||
}, | ||
|
||
isValid: function(date) { | ||
return date.isValid; | ||
}, | ||
|
||
millisecond: function(date) { | ||
return date.millisecond; | ||
}, | ||
|
||
second: function(date) { | ||
return date.second; | ||
}, | ||
|
||
minute: function(date) { | ||
return date.minute; | ||
}, | ||
|
||
hour: function(date) { | ||
return date.hour; | ||
}, | ||
|
||
isoWeekday: function(date, value) { | ||
return date.isoWeekday(value); | ||
}, | ||
|
||
startOf: function(date, value) { | ||
return date.startOf(value); | ||
}, | ||
|
||
endOf: function(date, value) { | ||
return date.endOf(value); | ||
}, | ||
|
||
valueOf: function(date) { | ||
return date.valueOf(); | ||
}, | ||
|
||
toFormat: function(date, format) { | ||
return date.toFormat(format); | ||
}, | ||
|
||
add: function(date, value, type) { | ||
var arg = {}; | ||
arg[type] = value; | ||
return date.plus(arg); | ||
}, | ||
|
||
diff: function(date, other, unit) { | ||
var duration = date.diff(other); | ||
return duration.as(unit); | ||
}, | ||
|
||
defaultDisplayFormats: { | ||
millisecond: 'h:mm:ss.SSS a', // 11:20:01.123 AM, | ||
second: 'h:mm:ss a', // 11:20:01 AM | ||
minute: 'h:mm a', // 11:20 AM | ||
hour: 'ha', // 5PM | ||
day: 'MMM d', // Sep 4 | ||
week: 'WW', // Week 46, or maybe "[W]WW - YYYY" ? | ||
month: 'MMM yyyy', // Sept 2015 | ||
quarter: '\'Q\'q - yyyy', // Q3 - 2015 | ||
year: 'yyyy' // 2015 | ||
} | ||
}; |
Oops, something went wrong.