vue中使用echarts
这里是官方引入说明
注意:图表容器必须设置高度,以下都是按需引入,否则体积太大
饼状图
<script> var echarts = require('echarts/lib/echarts') require('echarts/theme/macarons') //主题可选 [6个官方主题](https://echarts.baidu.com/download-theme.html)vintage | dark | roma | macarons | infographic | shine require('echarts/lib/chart/pie') require('echarts/lib/component/tooltip') require('echarts/lib/component/legendScroll') export default { name: 'pie', mounted () { this.createChart() } methods: { createChart () { let myChart = echarts.init(this.$refs.pie, 'macarons') myChart.showLoading()//显示加载动画 myChart.setOption({ //roseType: 'angle',//设置为南丁格尔图 //图表标题和副标题 title: { text: '人员统计', //主标题 subtext: '统计示例',//副标题 x: 'center'//标题在水平方向的位置 }, //鼠标放在图标上显示的信息 tooltip: { trigger: 'item', formatter: "{a} <br/>{b} : {c} ({d}%)" }, // 分类显示 legend: { type: 'scroll', orient: 'vertical', right: 10, top: 20, bottom: 20, data: ['小孩', '少年', '青年', '中年', '老年'], // 分类 //当前哪些分类显示,哪些未显示 selected: {小孩: false,少年: true,青年: true,中年: false,老年:true} }, series: [ { name: '年纪', //tooltip上显示的说明 type: 'pie', //图表类型,这里是饼图 radius: '55%', //图表占容器面积的百分比 center: ['40%', '50%'], //图标在容器水平和竖直方向的定位 // 图表数据 data: [ { name: '小孩', value: 20 }, { name: '少年', value: 25 }, { name: '青年', value: 10 }, { name: '中年', value: 30 }, { name: '老年', value: 15 } ], // 阴影效果 itemStyle: { emphasis: { shadowBlur: 10, shadowOffsetX: 0, shadowColor: 'rgba(0, 0, 0, 0.5)' } } } ] }) } } } </script>
折线图
<script> var echarts = require('echarts/lib/echarts') require('echarts/lib/chart/line')//引入折线 require('echarts/lib/component/grid')//布局 require('echarts/lib/component/tooltip')//提示 require('echarts/lib/component/toolbox')//图表工具,比如将图表另存为图片 require('echarts/lib/component/legend') export default { name: 'HelloWorld', mounted () { this.createChart() }, methods: { createChart () { let myChart = echarts.init(this.$refs.chart, 'macarons') let option = { title: {text: '折线图堆叠'}, tooltip: {trigger: 'axis'}, legend: {data: ['邮件营销', '联盟广告', '视频广告', '直接访问']}, grid: {left: '3%',right: '4%',bottom: '3%',containLabel: true}, toolbox: { feature: { saveAsImage: {}//另存为图片 } }, xAxis: { type: 'category', boundaryGap: false, data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'] }, yAxis: {type: 'value'}, series: [ { name: '邮件营销', type: 'line', stack: '总量', data: [120, 132, 101, 134, 90, 230, 210] }, { name: '联盟广告', type: 'line', stack: '总量', data: [220, 182, 191, 234, 290, 330, 310] }, { name: '视频广告', type: 'line', stack: '总量', data: [150, 232, 201, 154, 190, 330, 410] }, { name: '直接访问', type: 'line', stack: '总量', data: [320, 332, 301, 334, 390, 330, 320] } ] }; myChart.setOption(option) } } } </script>
柱状图
<script> var echarts = require('echarts/lib/echarts'); require('echarts/lib/chart/bar');// 引入柱状图 require('echarts/lib/component/tooltip');// 引入提示框 require('echarts/lib/component/title');//引入标题 export default { mounted () { this.createChart() }, methods: { createChart () { var myChart = echarts.init(this.$refs.chart); myChart.setOption({ title: { text: 'ECharts 入门示例' }, tooltip: {}, xAxis: { data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子'] }, yAxis: {}, series: [{ name: '销量', type: 'bar', data: [5, 20, 36, 10, 10, 20] }] }); } } } </script>
转载于//www.cnblogs.com/ak-b/p/11176772.html
还没有评论,来说两句吧...