2017-08-24 10:16:12 +00:00
|
|
|
<template>
|
|
|
|
<div class="doughnut-chart">
|
2018-11-24 18:49:19 +00:00
|
|
|
<DoughnutChart :data="doughnutChartData" :options="{ legend: { display: false }, maintainAspectRatio: false }" />
|
2017-08-24 10:16:12 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import axios from 'axios'
|
2019-06-25 10:01:58 +00:00
|
|
|
import DoughnutChart from '~/components/doughnut-chart'
|
2017-08-24 10:16:12 +00:00
|
|
|
|
|
|
|
function getRandomColor() {
|
2018-07-20 15:42:31 +00:00
|
|
|
const letters = '0123456789ABCDEF'
|
|
|
|
let color = '#'
|
|
|
|
for (let i = 0; i < 6; i++) {
|
2017-10-31 13:43:55 +00:00
|
|
|
color += letters[Math.floor(Math.random() * 16)]
|
2017-08-24 10:16:12 +00:00
|
|
|
}
|
2017-10-31 13:43:55 +00:00
|
|
|
return color
|
2017-08-24 10:16:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
2019-02-26 09:41:30 +00:00
|
|
|
components: {
|
|
|
|
DoughnutChart
|
|
|
|
},
|
2017-08-24 10:16:12 +00:00
|
|
|
async asyncData({ env }) {
|
|
|
|
const res = await axios.get(`https://api.github.com/repos/nuxt/nuxt.js/stats/contributors?access_token=${env.githubToken}`)
|
|
|
|
return {
|
|
|
|
doughnutChartData: {
|
2018-08-06 00:12:44 +00:00
|
|
|
labels: res.data.map(stat => stat.author.login),
|
2017-08-24 10:16:12 +00:00
|
|
|
datasets: [
|
|
|
|
{
|
|
|
|
label: 'Nuxt.js Contributors',
|
2018-07-20 15:42:31 +00:00
|
|
|
backgroundColor: res.data.map(getRandomColor),
|
|
|
|
data: res.data.map(() => 1)
|
2017-08-24 10:16:12 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.doughnut-chart {
|
|
|
|
position: fixed;
|
|
|
|
left: 10%;
|
|
|
|
top: 10%;
|
|
|
|
width: 80%;
|
|
|
|
height: 80%;
|
|
|
|
}
|
|
|
|
</style>
|