Skip to content

Instantly share code, notes, and snippets.

@femioladeji
Created November 20, 2018 13:53
Show Gist options
  • Save femioladeji/0b40045022544c8e6be09547826bf3c2 to your computer and use it in GitHub Desktop.
Save femioladeji/0b40045022544c8e6be09547826bf3c2 to your computer and use it in GitHub Desktop.
import { HorizontalBar } from 'vue-chartjs';
export default {
extends: HorizontalBar,
methods: {
getData() {
const currentDate = new Date().toISOString().substr(0, 10);
return new Promise((resolve) => {
chrome.storage.local.get(currentDate, result => {
return result[currentDate] ? resolve(result[currentDate]) : resolve({});
});
});
}
},
async mounted() {
const currentDate = new Date;
const data = await this.getData();
const values = Object.values(data).map(each => (each / 60).toFixed(2));
// Overwriting base render method with actual data.
this.renderChart({
labels: Object.keys(data),
datasets: [{
label: `Stats for ${currentDate}`,
// label: 'Stats for today',
backgroundColor: '#f87979',
data: values
}]
}, {
scales: {
xAxes: [{
ticks: {
beginAtZero: true
},
scaleLabel: {
display: true,
labelString: 'Minutes'
}
}],
yAxes: [{
barThickness: 'flex'
}]
}
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment