mt-polygon-simplification/benchmarking/src/loadChart.js

25 lines
604 B
JavaScript
Raw Normal View History

2019-08-06 14:03:05 +02:00
import 'file-drop-element'
import Chart from 'chart.js'
const fileDrop = document.getElementById('file-drop')
const canvas = document.getElementById('myChart')
const ctx = canvas.getContext('2d')
async function readFile(file) {
return new Promise(resolve => {
let reader = new FileReader()
reader.readAsText(file)
reader.onload = function() {
resolve(this.result)
}
})
}
fileDrop.addEventListener('filedrop', e => {
readFile(e.files[0])
.then(JSON.parse)
.then(config => new Chart(ctx, config))
2019-08-07 03:51:34 +02:00
.then(document.getElementsByTagName('file-drop')[0].remove())
2019-08-06 14:03:05 +02:00
})