2.vue中echarts使用

1.先声明对象


image.png

2.给对象赋值


image.png

3.js方法


image.png

image.png

4.echarts使用

getCharts3() {
let charts3 = echarts.init(document.getElementById("ecahrts3"));

  let options = {
    title: {
      text: "重点单位统计",
      textStyle: {
        color: "#fff",
        fontWeight: "normal",
        fontSize: 16,
      },
      left: "center",
      top: "10%",
    },
    tooltip: {
      trigger: "item",
      formatter: "{a} <br/>{b}: {c} ({d}%)",
    },
    color: [
      "#D4EC59",
      "#668ED6",
    ],
    legend: {
      orient: "vertical",
      right: "5%",
      top: "25%",
      bottom:"5%",
      type :"scroll",
      textStyle: {
        color: "#fff",
      },
      /*data:  [
        "重点",
        "非重点",]*/
      data: this.isKeyName
    },
    series: [
      {
        name: "重点单位统计",
        type: "pie",
        radius: ["35%", "48%"],
        center: ["32%", "55%"],
        label: {
          show: false,
          position: "center",
        },
        /*data: [
          { value: 310, name: "重点单位" },
          { value: 300, name: "非重点单位" },
        ],*/
        data:this.isKeyCount
      },
    ],
  };

  charts3.setOption(options);
},

  • 具体代码
    ---vue
    <template>
    <div class="left">
    <div class="top">
    <hj-tab
    style="width: calc(100% - 2vw); margin: 0 auto"
    :tabList="tabList"
    :value.sync="active"
    @change="change"
    />
    <div id="ecahrts1" v-show="active == 1"></div>
    <div id="ecahrts3" v-show="active == 2"></div>
    </div>
    <div class="bottom">
    <div id="ecahrts2"></div>
    </div>
    </div>
    </template>
    <script>
    import echarts from "echarts";
    import {
    getCompanyCountByIsKey,
    getCompanyCountByVillage,
    getCompanyCountByPlace,
    } from "@/api/company/company"

export default {
// 挂载vue实列对象后使用
mounted() {
this.getInfo();
/九小场所/
this.getCharts1();
/不同小区/
this.getCharts2();
/重点单位/
// this.getCharts3();
},

data() {
return {
/重点非重点之和/
isKeySum: 0,
isKeyCount:[{
name: "",
value: 0
}],
isKeyName: [{_name:""}],
active: 1,
tabList: [
{ name: "九小场所分类统计", value: 1 },
{ name: "重点单位统计", value: 2 },
],
};
},
methods: {

getInfo() {
  // 重点单位
  getCompanyCountByIsKey().then(res=>{
    this.isKeySum = 0;
    // 2. 获取名字对应的总数
    let arr = res.data.map(item => {
      var _obj = {};
      _obj.name = item.name;
      _obj.value = item.count;
      return _obj;
    })
    this.isKeyCount = arr
    // 1.计算总和
    let sum = res.data.reduce((prev, cur) => {
      return prev.count + cur.count;
    })
    this.isKeySum = sum;

    // 3.获取侧标篮
    let nameArr = this.isKeyCount.map(item => {
      return item.name;
    })
    this.isKeyName = nameArr;
  }).catch(e => {
    this.isKeyCount = [{name:'', count:''}];
    this.getCharts3();
  });
  // // 九小
  // getCompanyCountByPlace().then(res=>{
  //
  // });
  // // 企业
  // getCompanyCountByVillage().then(res=>{
  //
  // });
},




change(value){
  if(value == 1){
    this.$nextTick(() =>{
      this.getCharts1();
    })
  }else{
    this.$nextTick(() =>{
      this.getCharts3();
    })
  }
},
getCharts1() {
  let charts1 = echarts.init(document.getElementById("ecahrts1"));

  let options = {
    title: {
      text: "九小场所分类统计",
      textStyle: {
        color: "#fff",
        fontWeight: "normal",
        fontSize: 16,
      },
      left: "center",
      top: "10%",
    },
    tooltip: {
      trigger: "item",
      formatter: "{a} <br/>{b}: {c} ({d}%)",
    },
    color: [
      "#D4EC59",
      "#9CDC82",
      "#32D3EB",
      "#23C2DB",
      "#3294FB",
      "#668ED6",
      "#4A79CD",
      "#7CBAFF",
      "#7079DF",
      "#9D96F5",
    ],
    legend: {
      orient: "vertical",
      right: "5%",
      top: "25%",
      bottom:"5%",
      type :"scroll",
      textStyle: {
        color: "#fff",
      },
      data: [
        "非九小",
        "小学校及幼儿园",
        "小生产加工企业",
        "小歌舞娱乐场所",
        "小美容洗浴场所",
        "小餐饮场所",
        "小医院",
        "小商店",
        "小网吧",
        "小旅馆",
      ],
    },
    series: [
      {
        name: "九小场所分类统计",
        type: "pie",
        selectedMode: "single",
        radius: [0, "25%"],
        center: ["32%", "55%"],
        label: {
          position: "inner",
        },
        labelLine: {
          show: false,
        },
        color:["#FFE168","#60ACFC"],
        data: [
          { value: 300, name: "非九小" },
          { value: 2700, name: "九小场所"},
        ],
      },
      {
        name: "九小场所分类统计",
        type: "pie",
        radius: ["35%", "48%"],
        center: ["32%", "55%"],
        label: {
          show: false,
          position: "center",
        },
        data: [
          { value: 300, name: "非九小" },
          { value: 300, name: "小学校及幼儿园" },
          { value: 300, name: "小生产加工企业" },
          { value: 300, name: "小歌舞娱乐场所" },
          { value: 300, name: "小美容洗浴场所" },
          { value: 300, name: "小餐饮场所" },
          { value: 300, name: "小医院" },
          { value: 300, name: "小商店" },
          { value: 300, name: "小网吧" },
          { value: 300, name: "小旅馆" },
        ],
      },
    ],
  };

  charts1.setOption(options);
},
getCharts3() {
  let charts3 = echarts.init(document.getElementById("ecahrts3"));

  let options = {
    title: {
      text: "重点单位统计",
      textStyle: {
        color: "#fff",
        fontWeight: "normal",
        fontSize: 16,
      },
      left: "center",
      top: "10%",
    },
    tooltip: {
      trigger: "item",
      formatter: "{a} <br/>{b}: {c} ({d}%)",
    },
    color: [
      "#D4EC59",
      "#668ED6",
    ],
    legend: {
      orient: "vertical",
      right: "5%",
      top: "25%",
      bottom:"5%",
      type :"scroll",
      textStyle: {
        color: "#fff",
      },
      data: this.isKeyCount
    },
    series: [
      {
        name: "重点单位统计",
        type: "pie",
        radius: ["35%", "48%"],
        center: ["32%", "55%"],
        label: {
          show: false,
          position: "center",
        },
        /*data: [
          { value: 310, name: "重点单位" },
          { value: 300, name: "非重点单位" },
        ],*/
        data:this.isKeyCount
      },
    ],
  };

  charts3.setOption(options);
},
getCharts2() {
  let charts2 = echarts.init(document.getElementById("ecahrts2"));

  let options = {
    title: {
      text: "小区相关企业TOP5",
      textStyle: {
        color: "#fff",
        fontWeight: "normal",
        fontSize: 16,
      },
      left: "center",
      top: "10%",
    },
    color: ["#3398DB"],
    tooltip: {
      trigger: "axis",
      axisPointer: {
        // 坐标轴指示器,坐标轴触发有效
        type: "shadow", // 默认为直线,可选为:'line' | 'shadow'
      },
    },
    grid: {
      left: "5%",
      right: "5%",
      bottom: "5%",
      top:"25%",
      containLabel: true,
    },
    xAxis: [
      {
        type: "category",
        data: ["满庭春", "世纪朝阳", "红谷君庭", "利仁苑", "青瓷野墅"],
        axisTick: {
          show: false,
        },
        axisLabel:{
          color :"#7ECEF4"
        },
        axisLine:{
          lineStyle:{
            color:"#1B2A50"
          }
        }
      },
    ],
    yAxis: [
      {
        type: "value",
        axisTick: {
          show: false,
        },
        axisLabel:{
          color :"#7ECEF4"
        },
        axisLine:{
          lineStyle:{
            color:"#1B2A50"
          }
        },
        splitLine:{
          lineStyle:{
            color:"#1B2A50"
          }
        }
      },
    ],
    series: [
      {
        name: "小区相关企业TOP5",
        type: "bar",
        barWidth: "20%",
        label:{
          show:true,
          position:"top",
          color:"#fff"
        },
        itemStyle:{
          barBorderRadius:8,
          color:{
              type: 'linear',
              x: 0,
              y: 0,
              x2: 0,
              y2: 1,
              colorStops: [{
                  offset: 0, color: '#20B0DF' // 0% 处的颜色
              }, {
                  offset: 1, color: '#0C5CB0' // 100% 处的颜色
              }],
              globalCoord: false // 缺省为 false
          }
        },
        data: [334, 220, 200, 152, 89],
      },
    ],
  };

  charts2.setOption(options);
},

},

};
</script>

<style lang="scss" scoped>
.left {
height: 88vh;
width: 22vw;
margin-left: 2vw;
float: left;
.title {
margin: 0;
color: #fff;
text-align: center;
font-size: 1.4vh;
line-height: 2.8vh;
}
.top {
background-image: url(/images/archives/company/left.png);
background-size: 100% 100%;
background-repeat: no-repeat;
height: calc(50% - 3vh);
margin-bottom: 2vh;
padding-top: 2vh;
#ecahrts1 {
height: 38vh;
}
#ecahrts3 {
height: 38vh;
}
}
.bottom {
background-image: url(/images/archives/company/left.png);
background-size: 100% 100%;
background-repeat: no-repeat;
height: calc(50% - 1vh);
#ecahrts2 {
height: 100%;
}
}
}
</style>


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,847评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,208评论 1 292
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,587评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,942评论 0 205
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,332评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,587评论 1 218
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,853评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,568评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,273评论 1 242
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,542评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,033评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,373评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,031评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,073评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,830评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,628评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,537评论 2 269

推荐阅读更多精彩内容