Skip to content

Instantly share code, notes, and snippets.

@AllenJB
Created May 13, 2016 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AllenJB/d0febe4912c3d8e84d9962cbf67a8ead to your computer and use it in GitHub Desktop.
Save AllenJB/d0febe4912c3d8e84d9962cbf67a8ead to your computer and use it in GitHub Desktop.
Chart.js: Pre-parse time values into moment objects
var preparsePlugin = Chart.PluginBase.extend({
beforeInit: function(chartCtrlr) {
var chart = chartCtrlr.chart;
var labels = chartCtrlr.data.labels;
var momentLabels = [];
labels.forEach(function(v) {
momentLabels.push(moment(v, moment.ISO_8601));
});
chartCtrlr.data.labels = momentLabels;
},
});
Chart.pluginService.register(new preparsePlugin());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment