首页 技术 正文
技术 2022年11月15日
0 收藏 936 点赞 4,388 浏览 1522 个字

安装:

npm i v-charts echarts -S

组件中使用:

  1 <template>
2 <div class="app-chart">
3 <div id="print-content">
4 <!--用于图标组件-->
5 <ve-pie :data="chartData" :colors="colors"></ve-pie>
6 <!--导出的图片box-->
7 <div ref="box"></div>
8 </div>
9 <div class="foot">
10 <!--打印操作-->
11 <button type="primary" @click="doPrint">打 印</button>
12 </div>
13 </div>
14 </template>
15
16 <script>
17 //引入图标组件
18 import VePie from 'v-charts/lib/pie.common'
19
20 export default {
21
22 name: "app-pie",
23
24 data(){
25
26 return{
27
28 //图标相关参数(详情见官方文档)
29 chartData:{
30 columns: ['日期', '销售量'],
31
32 rows: [
33 { '日期': '1月1日', '销售量': 123 },
34 { '日期': '1月2日', '销售量': 207 },
35 { '日期': '1月3日', '销售量': 167 },
36 { '日期': '1月4日', '销售量': 193 },
37 ]
38
39 },
40
41 //图标样式的配置(相关配置查看官方文档)
42 colors:['#19d4ae','#fa6e86']
43 }
44
45 },
46
47 //注册图标组件
48 components:{
49 VePie
50 },
51
52 methods:{
53
54 //打印页面
55 doPrint(){
56
57 this.createImage();
58
59 this.$nextTick(()=>{
60
61 if(this.$refs.box.innerHTML){
62
63 let PrintContent = document.getElementById('print-content');
64 let newContent =PrintContent.innerHTML;
65 let oldContent = document.body.innerHTML;
66 document.body.innerHTML = newContent;
67 window.print();
68 window.location.reload();
69 document.body.innerHTML = oldContent;
70 return false;
71
72 }
73
74 });
75
76 },
77
78 //chart图标导出图片
79 createImage(){
80
81 // this.$nextTick(()=>{});
82
83 const canvas = document.getElementsByTagName('canvas')[0];
84
85 const box = this.$refs.box;
86
87 let image = canvas.toDataURL({
88 type:"png",
89 pixelRatio: 2,
90 backgroundColor: '#fff',//不设置此项,导出图片的底色是黑色
91 });
92
93 box.innerHTML = '<img src="'+image+'" alt="">';
94 }
95 },
96 }
97 </script>
98
99 <style scoped>
100 @media print {
101 .no-print{
102 display: none;
103 }
104 }
105 </style>
 
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,990
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,504
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,348
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,133
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,765
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,843