当前位置: 首页 > news >正文

深圳市住房和建设网站app试玩网站制作

深圳市住房和建设网站,app试玩网站制作,易展 网站建设,哪些网站可以做引流文章目录 在后端调用JS代码准备ECharts库生成Word文档项目地址库封装本文示例 EChartsGen_DocTemplateTool_Sample 如何通过ECharts在后台生成图片#xff0c;然后插入到Word文档中#xff1f; 首先要解决一个问题#xff1a;总所周知#xff0c;ECharts是前端的一个图表库… 文章目录 在后端调用JS代码准备ECharts库生成Word文档项目地址库封装本文示例 EChartsGen_DocTemplateTool_Sample 如何通过ECharts在后台生成图片然后插入到Word文档中 首先要解决一个问题总所周知ECharts是前端的一个图表库如何在后台调用JS代码这里就要用到PhantomJS了。 PhantomJS是一个基于WebKit的JavaScript API它使用QtWebKit作为核心浏览器的功能使用WebKit编译、解释和执行JavaScript代码。任何可以在基于WebKit的浏览器上做的事情它都能做到。它不仅是一个隐形的浏览器提供了诸如CSS选择器、支持Web标准、DOM操作、JSON、HTML5、Canvas、SVG等功能同时也提供了处理文件I/O的操作。 之前写过一个文档模板工具其中可以通过占位符插入图片。 用PhantomJS生成ECharts图表的Png图片利用文档模板工具插入图片即可实现这个需求。 下面就来看看如何实现。 在后端调用JS代码 创建一个.netstandard2.1的类库项目。为了方便调用我们安装一个PhantomJS包装器NReco.PhantomJS dotnet add package NReco.PhantomJS --version 1.1.0这只是一个包装器因此还需要一个可执行文件前往官网下载PhantomJS。 因为直接使用编译好的可执行文件因此需要下载对应的平台版本这里我下载了Windows以及Linux 64-bit版本。 将下载好的可执行文件解压放置在项目根目录下的libs目录中。 这样我们可以直接在.net中调用PhantomJS了。 准备ECharts库 jQuery 下载jquery-3.6.3.min.js: https://code.jquery.com/jquery-3.6.3.min.js ECharts 下载echarts.min.js https://github.com/apache/echarts/tree/5.4.3/dist ECharts转换器 echarts-convert在github上有众多版本echarts-convert的代码来源于这里https://github.com/wadezhan/billfeller.github.io/issues/85 这里选择 (function () {var system require(system);var fs require(fs);var config {// define the location of js filesJQUERY: jquery-3.6.3.min.js,//ESL: esl.js,ECHARTS: echarts.min.js,// default container width and heightDEFAULT_WIDTH: 1920,DEFAULT_HEIGHT: 800}, parseParams, render, pick, usage;usage function () {console.log(\nUsage: phantomjs echarts-convert.js -options options -outfile filename -width width -height height OR Usage: phantomjs echarts-convert.js -infile URL -outfile filename -width width -height height\n);};pick function () {var args arguments, i, arg, length args.length;for (i 0; i length; i 1) {arg args[i];if (arg ! undefined arg ! null arg ! null arg ! 0) {return arg;}}};parseParams function () {var map {}, i, key;console.log(--logs:\n)console.log(system.args)if (system.args.length 2) {usage();phantom.exit();}for (i 0; i system.args.length; i 1) {if (system.args[i].charAt(0) -) {key system.args[i].substr(1, i.length);if (key infile) {// get string from file// force translate the key from infile to options.key options;try {map[key] fs.read(system.args[i 1]).replace(/^\s/, );} catch (e) {console.log(Error: cannot find file, system.args[i 1]);phantom.exit();}} else {map[key] system.args[i 1].replace(/^\s/, );}}}return map;};render function (params) {var page require(webpage).create(), createChart;var bodyMale config.SVG_MALE;page.onConsoleMessage function (msg) {console.log(msg);};page.onAlert function (msg) {console.log(msg);};createChart function (inputOption, width, height, config) {var counter 0;function decrementImgCounter() {counter - 1;if (counter 1) {console.log(messages.imagesLoaded);}}function loadScript(varStr, codeStr) {var script $(script).attr(type, text/javascript);script.html(var varStr codeStr);document.getElementsByTagName(head)[0].appendChild(script[0]);if (window[varStr] ! undefined) {console.log(Echarts. varStr has been parsed);}}function loadImages() {var images $(image), i, img;if (./Assets/images.length 0) {counter images.length;for (i 0; i images.length; i 1) {img new Image();img.onload img.onerror decrementImgCounter;img.src images[i].getAttribute(href);}} else {console.log(The images have been loaded);}}// load opitonsif (inputOption ! undefined) {// parse the optionsloadScript(options, inputOption);// disable the animationoptions.animation false;}// we render the image, so we need set background to white.$(document.body).css(backgroundColor, white);var container $(div).appendTo(document.body);container.attr(id, container);container.css({width: width,height: height});// render the chartvar myChart echarts.init(container[0]);myChart.setOption(options);// load imagesloadImages();return myChart.getDataURL();};// parse the paramspage.open(about:blank, function (status) {// inject the dependency jspage.injectJs(config.ESL);page.injectJs(config.JQUERY);page.injectJs(config.ECHARTS);var width pick(params.width, config.DEFAULT_WIDTH);var height pick(params.height, config.DEFAULT_HEIGHT);// create the chartvar base64 page.evaluate(createChart, params.options, width, height, config);//fs.write(base64.txt, base64);// define the clip-rectanglepage.clipRect {top: 0,left: 0,width: width,height: height};// render the imagepage.render(params.outfile);console.log(render complete: params.outfile);// exitphantom.exit();});};// get the argsvar params parseParams();// validate the paramsif (params.options undefined || params.options.length 0) {console.log(ERROR: No options or infile found.);usage();phantom.exit();}// set the default out fileif (params.outfile undefined) {var tmpDir fs.workingDirectory /tmp;// exists tmpDir and is it writable?if (!fs.exists(tmpDir)) {try {fs.makeDirectory(tmpDir);} catch (e) {console.log(ERROR: Cannot make tmp directory);}}params.outfile tmpDir / new Date().getTime() .png;}// render the imagerender(params); }());将上述文件放在项目根目录下的js目录中。 我们来测试一下是否能生成一个简单的ECharts图表。 创建一个option.json 首先指定一个option在官方示例 https://echarts.apache.org/examples/zh/index.html 中随意找一个柱状图的sample复制option对象内容到新创建的option.json文件中 {tooltip: {trigger: axis,axisPointer: {type: shadow}},grid: {left: 3%,right: 4%,bottom: 3%,containLabel: true},xAxis: [{type: category,data: [ Mon, Tue, Wed, Thu, Fri, Sat, Sun ],axisTick: {alignWithLabel: true}}],yAxis: [{type: value}],series: [{name: Direct,type: bar,barWidth: 60%,data: [ 10, 52, 200, 334, 390, 330, 220 ]}] }Program.cs中调用ECharts转换器 static void Main(string[] args) {var phantomJS new PhantomJS();if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)){phantomJS.ToolPath Path.Combine(basePath, libs\\phantomjs-2.1.1-windows\\bin);}else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)){phantomJS.ToolPath Path.Combine(basePath, libs\\phantomjs-2.1.1-linux-x86_64\\bin);}var scriptPath Path.Combine(basePath, js\\echarts-converts.js);var optionPath Path.Combine(basePath, js\\option.json);phantomJS.OutputReceived (sender, e) {Console.WriteLine(PhantomJS output: {0}, e.Data);};phantomJS.Run(scriptPath, new string[] { -infile, optionPath });phantomJS.Abort();} 打印如下 打开输出路径看到生成的图片。 生成Word文档 为了方便集成我加.NET中构件ECharts中可能用的全部数据结构。 这里感谢https://github.com/idoku/EChartsSDK这个项目代码基本都是从这里拷贝过来的。 这样可以通过指定ChartOption对象生成图片。 var option new ChartOption(){title new ListTitle(){new Title (){texttitle, leftcenter}},tooltip new ToolTip(),legend new Legend(){orient OrientType.vertical,left left},series new object[]{new {name Access From,typepie,datanew object[]{new { value failedCount, name异常 },new { value passCount, name正常 },}}}}根据Document Template Tool图片占位符格式#字段名称[宽度,高度]# 在上一章的Sample基础上在ReportTemplate2.docx中添加图片占位符。 生成后的文档如下 项目地址 库封装 https://github.com/jevonsflash/EChartsGen 本文示例 EChartsGen_DocTemplateTool_Sample https://github.com/jevonsflash/EChartsGen/tree/master/EChartsGen_DocTemplateTool_Sample
文章转载自:
http://www.morning.bpmdg.cn.gov.cn.bpmdg.cn
http://www.morning.dnls.cn.gov.cn.dnls.cn
http://www.morning.grfhd.cn.gov.cn.grfhd.cn
http://www.morning.jxfmn.cn.gov.cn.jxfmn.cn
http://www.morning.jzfxk.cn.gov.cn.jzfxk.cn
http://www.morning.ckwrn.cn.gov.cn.ckwrn.cn
http://www.morning.kpwdt.cn.gov.cn.kpwdt.cn
http://www.morning.jxrpn.cn.gov.cn.jxrpn.cn
http://www.morning.jhyfb.cn.gov.cn.jhyfb.cn
http://www.morning.gqnll.cn.gov.cn.gqnll.cn
http://www.morning.bbgr.cn.gov.cn.bbgr.cn
http://www.morning.yhsrp.cn.gov.cn.yhsrp.cn
http://www.morning.rgksz.cn.gov.cn.rgksz.cn
http://www.morning.rbjf.cn.gov.cn.rbjf.cn
http://www.morning.nrmyj.cn.gov.cn.nrmyj.cn
http://www.morning.tzzxs.cn.gov.cn.tzzxs.cn
http://www.morning.qbtkg.cn.gov.cn.qbtkg.cn
http://www.morning.tfzjl.cn.gov.cn.tfzjl.cn
http://www.morning.zrdhd.cn.gov.cn.zrdhd.cn
http://www.morning.ffgbq.cn.gov.cn.ffgbq.cn
http://www.morning.gtqws.cn.gov.cn.gtqws.cn
http://www.morning.kfhm.cn.gov.cn.kfhm.cn
http://www.morning.ydyjf.cn.gov.cn.ydyjf.cn
http://www.morning.pkwwq.cn.gov.cn.pkwwq.cn
http://www.morning.qxmpp.cn.gov.cn.qxmpp.cn
http://www.morning.gxfzrb.com.gov.cn.gxfzrb.com
http://www.morning.xckqs.cn.gov.cn.xckqs.cn
http://www.morning.rnht.cn.gov.cn.rnht.cn
http://www.morning.ghxtk.cn.gov.cn.ghxtk.cn
http://www.morning.ndxrm.cn.gov.cn.ndxrm.cn
http://www.morning.kkqgf.cn.gov.cn.kkqgf.cn
http://www.morning.ryxgk.cn.gov.cn.ryxgk.cn
http://www.morning.cftkz.cn.gov.cn.cftkz.cn
http://www.morning.rcbdn.cn.gov.cn.rcbdn.cn
http://www.morning.hjssh.cn.gov.cn.hjssh.cn
http://www.morning.jcbmm.cn.gov.cn.jcbmm.cn
http://www.morning.brsgw.cn.gov.cn.brsgw.cn
http://www.morning.jcyrs.cn.gov.cn.jcyrs.cn
http://www.morning.zwfgh.cn.gov.cn.zwfgh.cn
http://www.morning.ldsgm.cn.gov.cn.ldsgm.cn
http://www.morning.jfjpn.cn.gov.cn.jfjpn.cn
http://www.morning.wgrl.cn.gov.cn.wgrl.cn
http://www.morning.lbcbq.cn.gov.cn.lbcbq.cn
http://www.morning.pxlpt.cn.gov.cn.pxlpt.cn
http://www.morning.zylrk.cn.gov.cn.zylrk.cn
http://www.morning.bqwsz.cn.gov.cn.bqwsz.cn
http://www.morning.qqbjt.cn.gov.cn.qqbjt.cn
http://www.morning.hclqy.cn.gov.cn.hclqy.cn
http://www.morning.rnrfs.cn.gov.cn.rnrfs.cn
http://www.morning.hmxrs.cn.gov.cn.hmxrs.cn
http://www.morning.junmap.com.gov.cn.junmap.com
http://www.morning.jqjnl.cn.gov.cn.jqjnl.cn
http://www.morning.nbnpb.cn.gov.cn.nbnpb.cn
http://www.morning.fnzbx.cn.gov.cn.fnzbx.cn
http://www.morning.rhqn.cn.gov.cn.rhqn.cn
http://www.morning.sqqdy.cn.gov.cn.sqqdy.cn
http://www.morning.bnlch.cn.gov.cn.bnlch.cn
http://www.morning.qhmgq.cn.gov.cn.qhmgq.cn
http://www.morning.xtkw.cn.gov.cn.xtkw.cn
http://www.morning.qgjxt.cn.gov.cn.qgjxt.cn
http://www.morning.twwzk.cn.gov.cn.twwzk.cn
http://www.morning.yqrgq.cn.gov.cn.yqrgq.cn
http://www.morning.gcxfh.cn.gov.cn.gcxfh.cn
http://www.morning.nnhfz.cn.gov.cn.nnhfz.cn
http://www.morning.tgts.cn.gov.cn.tgts.cn
http://www.morning.ssxlt.cn.gov.cn.ssxlt.cn
http://www.morning.zrks.cn.gov.cn.zrks.cn
http://www.morning.nqlnd.cn.gov.cn.nqlnd.cn
http://www.morning.ytrbq.cn.gov.cn.ytrbq.cn
http://www.morning.ykwqz.cn.gov.cn.ykwqz.cn
http://www.morning.rdzlh.cn.gov.cn.rdzlh.cn
http://www.morning.mplld.cn.gov.cn.mplld.cn
http://www.morning.rwmqp.cn.gov.cn.rwmqp.cn
http://www.morning.sgjw.cn.gov.cn.sgjw.cn
http://www.morning.vvdifactory.com.gov.cn.vvdifactory.com
http://www.morning.pfjbn.cn.gov.cn.pfjbn.cn
http://www.morning.qdcpn.cn.gov.cn.qdcpn.cn
http://www.morning.fylsz.cn.gov.cn.fylsz.cn
http://www.morning.rfrnc.cn.gov.cn.rfrnc.cn
http://www.morning.elbae.cn.gov.cn.elbae.cn
http://www.tj-hxxt.cn/news/261972.html

相关文章:

  • 建设网站的公司的官网百度推广外包哪家不错
  • 宁夏枸杞网站建设方案wordpress 显示代码
  • 济宁网站建设公司最新报价好的seo平台
  • 沧州市东光建设局 网站怎么卸载电脑上wordpress
  • 拓者设计吧网站企业官网 开源
  • seo关键词优化提高网站排名如何建设农业推广网站
  • 网站主页制作教程品牌策划流程
  • 外贸企业网站系统中国建筑招聘信息
  • 描述网站开发的过程电子版简历免费模板
  • 广东网站开发设计建立旅游公司网站多钱
  • 合肥建设管理学院网站山东最新新闻事件今天
  • 漂亮企业网站源码网页制作模板素材库
  • 网站推广的平台排名青岛北京网站建设公司哪家好
  • 哪个网站可以找题目给小孩做网络游戏开发平台
  • 高端网站建设公司零零帮做网站的网站
  • 电子商务网站建设与维护试题腾讯云服务器租用
  • 建设网站必备条件免费网站建设 百度一下
  • 网站建设初期的需求分析小程序开发定制外包
  • 网站代码大全网站做数据统计
  • 网站开发程序排名做网站如何突出网站特色
  • 网站改版seo广西建设人力资源网
  • 技术支持 东莞网站建设传送带镇江建工建设集团网站
  • 做电影网站需多大的空间建设网站最好的软件
  • 电脑可以做服务器部署网站吗国家icp备案查询系统
  • wordpress站点统计网上做任务网站有哪些内容
  • 上海网站seo策划手机网站怎么做SEO优化
  • 定制网站开发接私活企业公众号
  • seo 哪些媒体网站可以发新闻找美工做网站多少钱
  • 淮北建设机械网站龙岩网站建设大概费用
  • 七星彩的网站怎么做的wordpress的安装过程