ECharts导出word 图表模糊失真
2018-10-29 15:27:34来源:博客园 阅读 ()
在项目中会有这样的需求,echars生成图表导入到word中
在项目中用的插件
博主有一篇文章将的是 vue使用jquery的三方插件jquery.wordexport.js
https://blog.csdn.net/sinat_37984999/article/details/81164818
这样就可以在vue中使用导出jquery.wordexport的方法了
用这个插件很方便导出了图表,下面页面是这样的,第一个图是echarts的图表,第二个图是根据base64生成的img图片,第三个图就是一个普通的图片
我将echarts自带的 getDataURL() 方法获取base64的url,赋值给页面上的img 。如果直接下载下载出来的图片是模糊的
先上个代码
<template> <div id="pagecontent"> hello word <div id="main" style="height:300px"></div> <input type="button" id="btn" value="下载"> <img :src="imgUrl" alt=""> <img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCADIAMgDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERU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7sp/adxauJpr3aeiYOFB9+ee/IoooA7B/hp4KePy28MadjGMiEA/mOazj8HvBu8tBZXVtk5C297KgU+oG7iiigAX4UaZHxHr/iaJOyJqjgCrNj8L/DFnex3lxBdancxnckuo3Lz7T64Y7f0oooA7UDAxS0UUAFFFFABRRRQAVGUBIJAJFFFS0nuBJRRRVAFFFFAH//Z" alt=""> </div> </template> <script> var echarts = require("echarts"); import $ from "./src/jqueryexport"; import "./src/filesaver"; import "./plugin/jquery.wordexport"; import { setTimeout } from 'timers'; export default { data() { return { imgUrl: "" }; }, mounted() { var myChart = echarts.init(document.getElementById("main")); myChart.setOption({ title: { text: "ECharts 入门示例" }, tooltip: {}, xAxis: { data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] }, yAxis: {}, series: [ { name: "销量", type: "bar", data: [5, 20, 36, 10, 10, 20] } ] }); setTimeout(()=>{ this.imgUrl = myChart.getDataURL(); },200) $(document).ready(function($) { $("#btn").click(function(event) { $("#pagecontent").wordExport(); }); }); } }; </script>
这样是模糊的,需要改动插件里面的一个地方就瞬间清晰了
找到jquery.wordexport.js
jquery.wordexport
这个数值可以根据你需要清晰图片的大小来设置
希望可以帮到和我遇到一样问题的你
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- Vue结合后台导入导出Excel问题详解 2019-08-14
- vue学习【一】vue引用封装echarts并展示多个echarts图表 2019-08-14
- http请求post,文件导出兼容IE10+ 2019-08-14
- vue项目中导出Excel文件功能的前端代码实现 2019-08-14
- 多个浏览器下应用前端JS实现一键导出excel表 2019-08-14
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash