vue图表组件使用,组件文档echarts

摘要:
vue图表组件使用,组件文档echartshttp://echarts.baidu.com/echarts2/doc/example.htmlvue组件手动封装barChart.vueimport

vue图表组件使用,组件文档echarts

http://echarts.baidu.com/echarts2/doc/example.html
vue组件手动封装barChart.vue
<template>
    <div :class="className" :id="id" :style="{height:height,width:width}"></div>
</template>

<script>
    import echarts from 'echarts';
    require('echarts/theme/macarons')
    export default {
        props: {
            className: {
                type: String,
                default: 'chart'
},
            id: {
                type: String,
                default: 'chart'
},
            width: {
                type: String,
                default: '200px'
},
            height: {
                type: String,
                default: '200px'
}
        },
        data() {
            return {
                chart: null
};
        },
        mounted() {
            /*this.initChart();*/
            this.chart = null;
        },
        methods: {
            initChart(monthdata, seriesVoList, yeardata) {
                this.chart = echarts.init(document.getElementById(this.id));
                this.chart.setOption({
  title: {
    text: '2010-2013年中国城镇居民家庭人均消费构成(元)',
    subtext: '数据来自国家统计局',
    sublink: 'http://data.stats.gov.cn/search/keywordlist2?keyword=%E5%9F%8E%E9%95%87%E5%B1%85%E6%B0%91%E6%B6%88%E8%B4%B9'
  },
  tooltip: {
    trigger: 'axis',
    backgroundColor: 'rgba(255,255,255,0.7)',
    axisPointer: {
      type: 'shadow'
    },
   
  },
  legend: {
    x: 'right',
    data:['2010','2011','2012','2013']
  },
  toolbox: {
    show: true,
    orient: 'vertical',
    y: 'center',
    feature: {
      mark: {show: true},
      dataView: {show: true, readOnly: false},
      restore: {show: true},
      saveAsImage: {show: true}
    }
  },
  calculable: true,
  grid: {
    y: 80,
    y2: 40,
    x2: 40
  },
  xAxis: [
    {
      type: 'category',
      data: ['食品', '衣着', '居住', '家庭设备及用品', '医疗保健', '交通和通信', '文教娱乐服务', '其他']
    }
  ],
  yAxis: [
    {
      type: 'value'
    }
  ],
  series: [
    {
      name: '2010',
      type: 'bar',
      data: [4804.7,1444.3,1332.1,908,871.8,1983.7,1627.6,499.2]
    },
    {
      name: '2011',
      type: 'bar',
      data: [5506.3,1674.7,1405,1023.2,969,2149.7,1851.7,581.3]
    },
    {
      name: '2012',
      type: 'bar',
      data: [6040.9,1823.4,1484.3,1116.1,1063.7,2455.5,2033.5,657.1]
    },
    {
      name: '2013',
      type: 'bar',
      data: [6311.9,1902,1745.1,1215.1,1118.3,2736.9,2294,699.4]
    }
  ]})
            }
        }
    }
</script>
vue页面引用组件,及调用方式:
this.$refs.onclick.initChart(monthdata,seriesVoList,yeardata);
<template>
  <div class="components-container" style='height:100vh'>
    
<div class='chart-container'>
    <chart ref="onclick" height='100%' width='100%'></chart>
</div>
 </div>
</template><script>import Chart from 'components/Charts/barChart'; export default { components: { Chart },
methods: {
getstoreStatistics() {
    this.dialogauditorFormVisible = true;
    this.statisticsQuery.productId = this.productobj.productId;
    this.statisticsQuery.collectinCode = this.productobj.downSuperiorCode;
    this.statisticsQuery.year = (new Date().toISOString().slice(0,4));
    storeStatistics(this.statisticsQuery).then(response => {
        if (response.data != null && response.data.status == 0) {
            /*console.log(response);*/
            let monthdata = response.data.data.monthdata;
            let seriesVoList = response.data.data.seriesVoList;
            let yeardata = response.data.data.yeardata;
            this.$refs.onclick.initChart(monthdata,seriesVoList,yeardata);
        }
        else {
            this.$message({
                message: '获取信息失败'
});
        }
    });
},
}
</script>

<style scoped>
.chart-container{
  position: relative;
  width: 100%;
  height: 90%;
  padding-bottom: 40px;
}
</style>

免责声明:文章转载自《vue图表组件使用,组件文档echarts》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇破壳漏洞(CVE-2014-6271)分析react-native环境搭建下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

vue中引入第三方字体图标库iconfont,及iconfont引入彩色图标

转载原文:https://www.cnblogs.com/goloving/p/8855794.html iconfont字体图标使用就不多说了,大致是几部: 1、在iconfont官网选图标,加入购物车,加入项目,下载到本地,解压 2、在项目assets目录新建目录iconfont,用于存放刚才下载解压的代码 3、在main.js导入iconfont.c...

FastDFS集群数据整体迁移

场景介绍: 系统从一个地方迁移到另一个地方,数据保持不变,但是ip地址和网络情况不一样了,最困难的是要迁移的那个地方还么有互联网,这TM就坑了,所以想到将FastDFS存储的目录整体拷贝过去,这个方法简单粗暴,这样文件在文件系统中的位置也不会发生变化,访问文件时文件地址只需要修改为迁移后的ip即可,那就这么干。 解决方案: 1.在需要迁移的那边用同同样的d...

扩展Django中的分页

Django中封装了分页模块,定义了两个类分别是Paginator和Page。虽然可以满足一般的需求,但是稍想添加点新的功能就显得鸡肋,而且创建paginator类对象时需要传人所有的数据对象(由于django的惰性查询所以适用django),没有可移植性。 下面先在原分类模块基础上另外封装两个功能,分别实现设置页面最多显示页码数 和切换页码时保留原搜索条...

通过jQuery和C#分别实现对.NET Core Web Api的访问以及文件上传

建立.NET Core Web Api项目建立请求模型 public class UserInfo { public int Age { get; set; } public string Name { get; set; } public bool Sex { get; set; }...

vue 路由嵌套 及 router-view vue-router --》children

vue 路由嵌套 vue-router --》children 在项目的很多子页面中,我们往往需要在同一个页面做一个组件的切换,同时保存这个页面的部分数据(比如树形菜单),进而显示不同的数据,之前我都是通过v-show/v-if来实现,但当切换的组件太多时,上述方法显然不太合理,而在实际开发中,当你切换的组件太多时,后端往往会将你切换组件的路由给你,所以在...

Vue组件别名及Ctrl跳转组件问题

Vue + webstorm Vue项目中,嫌弃导入组件的路径太长,因此为路径配置了别名,也是因此,导致 Ctrl + 鼠标左键 点击进入不了组件,为此还吐槽了一段时间配置这个别名的 “副作用” 今天突然感觉这个操作不太对劲,肯定有解决办法,后面搜索后发现果然有解决办法 File -> Settings -> Languuages &...