Created
November 20, 2018 13:53
-
-
Save femioladeji/0b40045022544c8e6be09547826bf3c2 to your computer and use it in GitHub Desktop.
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
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