Created
July 31, 2017 15:15
-
-
Save nomoney4me/9e18b186eb5cc25a9ee10443817fc2f7 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
<!doctype html> | |
<html> | |
<head> | |
<!-- <script src="https://unpkg.com/vue"></script> --> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.2.6/vue.min.js"></script> | |
<script src="https://unpkg.com/[email protected]/dist/vue-chartjs.full.min.js"></script> | |
<head> | |
<body class="container-fluid"> | |
<div id="ticker" class="ticker"> | |
<line-chart :chart-data="datacollection" :options="{ responsive: true, maintainAspectRatio: false }"></line-chart> | |
</div> | |
<script> | |
Vue.component('line-chart', { | |
extends: VueChartJs.Line, | |
mixins:[VueChartJs.mixins.reactiveProp], | |
props: ['chartData', 'options'], | |
mounted () { | |
//console.log(this.chartData) | |
this.renderChart(this.chartData, this.options) | |
} | |
}) | |
var vm = new Vue({ | |
el:'.ticker', | |
data: function() { | |
return { | |
} | |
}, | |
computed: { | |
datacollection: function() { | |
var url = "/getGraphData" | |
// question: how come this doesn't work? I can replace "graphData" with a manual array and it works. Is there something going on with fetch? | |
fetch(url).then((data) => { | |
return data.json() | |
}).then((graphData) => { | |
console.log(graphData) | |
return { | |
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'], | |
datasets: [ | |
{ | |
label: 'Data One', | |
backgroundColor: '#f87979', | |
data: graphData | |
} | |
], | |
} | |
}) | |
} | |
} | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment