vue中使用Echars(二)

1、使用Vue.directive 自定义指令。

Vue.directive('echarshis',function (data) {

          var myChart = echarts.init(document.getElementById(data.ele));

          var app = {};

          option = null;

          option = {

              title: {

                  text: '',

                  subtext: ''

              },

              tooltip: {

                  trigger: 'axis',

                  "axisPointer": {

                      "type": "shadow"

                  },

              },

              legend: {

                  orient: 'vertical',

                  top:'top',

                  data: []

              },

              grid: {

                  "borderWidth": 10,

                  "y2": 120,

                  "containLabel":true

              },

              toolbox: {

                  show: true,

                  feature: {

                      dataZoom: {

                          yAxisIndex: 'none'

                      },

                      dataView: {readOnly: false},

                      magicType: {type: ['bar','line']},

                      restore: {},

                      saveAsImage: {}

                  }

              },

              xAxis:  [

                  {

                      "type": "category",

                      "splitLine": {

                          "show": false

                      },

                      "axisTick": {

                          "show": false

                      },

                      "splitArea": {

                          "show": false

                      },

                      "axisLabel": {

                          "interval": 0,

                          "rotate": 45,

                          "show": true,

                          "splitNumber": data.lens,

                          "textStyle": {

                              "fontFamily": "微软雅黑",

                              "fontSize": 10

                          }

                      },

                      "data": data.prj

                  }

              ],

              yAxis: {

                  "type": "value",

                  "splitLine": {

                      "show": false

                  },

                  "axisLine": {

                      lineStyle: {

                          color: '#90979c'

                      }

                  },

                  "axisTick": {

                      "show": false

                  },

                  "axisLabel": {

                      "interval": 0,


                  },

                  "splitArea": {

                      "show": false

                  },

              },

              dataZoom: [

                  {

                      "show": true,

                      "height": 30,

                      "xAxisIndex": [

                          0

                      ],

                      bottom:40,

                      "start": 0,

                      "end": 80

                  },

                  {

                      "type": "inside",

                      "show": true,

                      "height": 15,

                      "xAxisIndex": [

                          0

                      ],

                      "start": 1,

                      "end": 35

                  }

              ],

              series: [

                  {

                      name:'严重Bug',

                      type:'bar',

                      data: data.seBug,

                      markPoint: {

                          data: [

                              {type: 'max', name: '最大值'}

                          ]

                      },

                      markLine: {

                          data: [

                              {type: 'average', name: '平均值'}

                          ]

                      }

                  }

              ]

          };

          ;

          if (option && typeof option === "object") {

              myChart.setOption(option, true);

          }

          window.onresize = myChart.resize;

      });

data 为json类型。

2、声明一个容器

<div id="prjcharhis" style="width:650px;height:480px;" v-echarshis="{ele:'prjcharhis',text:'',prj:prjList,seBug:seBugList,lens:len}" ></div>

3、创建一个Vue实例

var vmhischar = new Vue({

          el: '#prjcharhis',

          data:{

              prjList:[],

              seBugList:[],

              len:'',

              apiUrl: '/main/index/*****' 

          },

          ready: function(){

              this.getHisInfoData();

          },

          methods: {

              initHisInfoData:function() {

              },

              getHisInfoData: function(){

                  this.$http.get(this.apiUrl).then(function(response){

                      this.$set('prjList', response.data.prjList);

                      this.$set('seBugList', response.data.seBugList);

                      this.$set('len',response.data.prjList.length);

                  }).catch(function(response){

                      console.log(response);

                  })

              }

          }

      });

备注:vmhischar.$el=id=data.ele

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,280评论 19 139
  • 这篇笔记主要包含 Vue 2 不同于 Vue 1 或者特有的内容,还有我对于 Vue 1.0 印象不深的内容。关于...
    云之外阅读 5,095评论 0 29
  • 最近刚读完《天才在左疯子在右》,然后我就华丽丽的陷入了自暴自弃中,因为我发现,我连做精神病人的资格都没有。多角度分...
    十月七107阅读 449评论 0 0
  • 夫子曰:名不正而言不顺。 所以,每当网络上出现一些新的词汇的时候,我总是会细细的想想它到底是什么含义,以免用起来时...
    蕊生阅读 420评论 2 0
  • 很多时候,我们能听到这样的劝说“你想想人家也是好心……”,在这样的话语下,我们经常软下心来妥协,不再追究那些让我们...
    昭阳2017阅读 1,207评论 1 8