Last active
June 10, 2018 00:10
-
-
Save dzava/fa025d07e1ed9b5c8d124072d7a8b514 to your computer and use it in GitHub Desktop.
Plugin to automatically color chart.js datasets
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
const colors = [ | |
{ | |
backgroundColor: 'transparent', | |
borderColor: 'rgba(115,115,115,1)', | |
}, | |
{ | |
backgroundColor: 'transparent', | |
borderColor: 'rgba(241, 90, 96, 1)', | |
}, | |
{ | |
backgroundColor: 'transparent', | |
borderColor: 'rgba(122, 195, 106, 1)', | |
}, | |
{ | |
backgroundColor: 'transparent', | |
borderColor: 'rgba(90, 155, 212, 1)', | |
}, | |
{ | |
backgroundColor: 'transparent', | |
borderColor: 'rgba(250, 167, 91, 1)', | |
}, | |
{ | |
backgroundColor: 'transparent', | |
borderColor: 'rgba(158, 103, 171, 1)', | |
}, | |
{ | |
backgroundColor: 'transparent', | |
borderColor: 'rgba(206, 112, 88, 1)', | |
}, | |
{ | |
backgroundColor: 'transparent', | |
borderColor: 'rgba(215, 127, 180, 1)', | |
}, | |
] | |
export default { | |
beforeInit(chart, options) { | |
const datasets = chart.data.datasets | |
for (let i = 0; i < datasets.length; i++) { | |
datasets[i] = Object.assign({}, datasets[i], colors[i % colors.length]) | |
} | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment