bar-chart.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. (function () {
  2. Vue.component('bar-chart', {
  3. template: '<div class="chart_box" >\
  4. <div v-show="!isEmpty" :id="chartid" class="chart_box"></div>\
  5. <div class="noData" v-show="isEmpty" class="chart-no-data">\
  6. <p v-show="isEmpty" style="text-align: center">{{title}}</p>\
  7. <img src="../../bigData/images/noData.png" alt="">\
  8. 暂无数据\
  9. </div>\
  10. </div>',
  11. props: ['config'],
  12. data: function () {
  13. return {
  14. chartid: _.uniqueId("chart_"),
  15. chart: null,
  16. isEmpty: false,
  17. title:''
  18. }
  19. },
  20. mounted: function () {
  21. var that =this;
  22. this.$nextTick(function () {
  23. that.chart = echarts.init(document.getElementById(that.chartid));
  24. if (that.config) {
  25. that.chart.setOption(that.setOption( that.config));
  26. }
  27. })
  28. },
  29. methods: {
  30. setOption: function (options) {
  31. var vm = this;
  32. if(!options)return
  33. var options = $.extend({}, defaults, options);
  34. vm.chart.on('click', function (param){
  35. vm.$emit('click-item', {param:param});
  36. });
  37. return options
  38. }
  39. },
  40. watch: {
  41. config: function (data) {
  42. if (data) {
  43. debugger
  44. if(!data.series[0].data){
  45. this.isEmpty = true;
  46. this.title =data.title && data.title.text; //无数据时渲染的标题
  47. }else{
  48. if(data.series[0].data.length == 0){
  49. this.isEmpty = true;
  50. this.title =data.title && data.title.text; //无数据时渲染的标题
  51. }
  52. }
  53. this.chart.setOption(this.setOption(data));
  54. }
  55. }
  56. }
  57. })
  58. var defaults = {
  59. }
  60. })()