日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

java导出highcharts_Highcharts导出代码Java版

發布時間:2023/12/2 java 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java导出highcharts_Highcharts导出代码Java版 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Highcharts是一個用純JavaScript編寫的圖表庫,提供了一個交互式的圖表添加到您的網站或Web應用程序的簡單方法。Highcharts目前支持線,樣條,面積,areaspline,柱形圖,條形圖,餅圖和散點圖類型。

同時Highcharts提供將圖表導出為圖片或者PDF格式文件,只需要在頁面中載入exporting.js文件。

由于生成的圖表是SVG格式,所以導出時需要將數據發送到服務器端來進行轉換。在exporting.js中默認導出地址是http://export.highcharts.com/,另外在demo中也提供了php版本。

本文是介紹如何在java web application中來實現導出功能。

首選需要在lib中加入batik?jar包,如果是使用maven來管理項目,則在庫中只能找到1.6的版本,同時需要另外下載一個包(xml-apis-ext.jar)。

public class ExportHighFreqChartServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {

public ExportHighFreqChartServlet() {

super();

}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

doPost(request, response);

}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServerException, IOException {

String type = request.getParameter("type");

String svg = request.getParameter("svg");

String filename = request.getParameter("filename");

filename = filename==null?"chart":filename;

ServletOutputStream out = response.getOutputStream();

if (null != type && null != svg) {

svg = svg.replaceAll(":rect", "rect");

String ext = "";

Transcoder t = null;

if (type.equals("image/png")) {

ext = "png";

t = new PNGTranscoder();

} else if (type.equals("image/jpeg")) {

ext = "jpg";

t = new JPEGTranscoder();

} else if (type.equals("application/pdf")) {

ext = "pdf";

t = new PDFTranscoder();

}

response.addHeader("Content-Disposition", "attachment; filename="+ filename + "."+ext);

response.addHeader("Content-Type", type);

if (null != t) {

TranscoderInput input = new TranscoderInput(new StringReader(svg));

TranscoderOutput output = new TranscoderOutput(out);

try {

t.transcode(input, output);

} catch (TranscoderException e) {

out.print("Problem transcoding stream. See the web logs for more details.");

e.printStackTrace();

}

} else if (ext.equals("svg")) {

out.print(svg);

} else {

out.print("Invalid type: " + type);

}

} else {

response.addHeader("Content-Type", "text/html");

out.println("Usage:\n\tParameter [svg]: The DOM Element to be converted.

\n\tParameter [type]: The destination MIME type for the elment to be transcoded.");

}

out.flush();

out.close();

}

}

總結

以上是生活随笔為你收集整理的java导出highcharts_Highcharts导出代码Java版的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。