bar-chart.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. (function () {
  2. Vue.component('bar-chart', {
  3. template: '<div class="chart_box" >\
  4. <div :id="chartid" class="chart_box"></div>\
  5. </div>',
  6. props: ['config'],
  7. data: function () {
  8. return {
  9. chartid: _.uniqueId("chart_"),
  10. chart: null,
  11. }
  12. },
  13. mounted: function () {
  14. var that =this;
  15. this.$nextTick(function () {
  16. that.chart = echarts.init(document.getElementById(that.chartid));
  17. if (that.config) {
  18. debugger
  19. that.chart.setOption(that.setOption( that.config));
  20. }
  21. })
  22. },
  23. methods: {
  24. setOption: function (options) {
  25. if(!options)return
  26. var options = $.extend({}, defaults, options);
  27. return options
  28. }
  29. },
  30. watch: {
  31. config: function (data) {
  32. if (data) {
  33. this.chart.setOption(this.setOption(data));
  34. }
  35. }
  36. }
  37. })
  38. var defaults = {
  39. }
  40. })()