Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. Vue.component('vue-chart', {
  2. template: '<canvas></canvas>',
  3. props: {
  4. type: {
  5. type: String,
  6. default: 'line'
  7. },
  8. data: {
  9. type: Object,
  10. default: function _default() {
  11. return {
  12. labels: [],
  13. datasets: []
  14. };
  15. }
  16. },
  17. options: {
  18. type: Object
  19. }
  20. },
  21. data: function data() {
  22. return {
  23. chart: null
  24. };
  25. },
  26. mounted: function mounted() {
  27. var _this = this;
  28.  
  29. this.chart = new Chart(this.$el, {
  30. type: this.type,
  31. data: this.data,
  32. options: this.options
  33. });
  34. this.$watch('data', function () {
  35. if (_this.data.datasets && _this.data.datasets.length > 0) {
  36. _this.data.datasets.map(function (dataset, i) {
  37. if (i === _this.chart.config.data.datasets.length) return;
  38. _this.data.datasets[i] = _.assign(_this.chart.config.data.datasets[i], dataset);
  39. });
  40. }
  41. _this.chart.config.data = _.assign(_this.chart.config.data, _this.data);
  42. _this.$nextTick(function () {
  43. _this.chart.update();
  44. });
  45. });
  46. this.$watch('options', function () {
  47. _this.chart.config.options = _.assign(_this.chart.config.options, _this.options);
  48. _this.$nextTick(function () {
  49. _this.chart.update();
  50. });
  51. });
  52. }
  53. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement