Highchart第三方图表控件,导出默认是从官方地址导出,这样在无外网的条件下则导致导出失败,改进如下:
后台导出代码:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101 |
public
partial class HighChart : System.Web.UI.Page{ protected
void Page_Load(object
sender, EventArgs e) { if
(!Page.IsPostBack) { if
(Request.Form["type"] != null
&& Request.Form["svg"] != null
&& Request.Form["filename"] != null) { string
tType = Request.Form["type"].ToString(); string
tSvg = Request.Form["svg"].ToString(); string
tFileName = Request.Form["filename"].ToString(); if
(tFileName == "") { tFileName = "chart"; } MemoryStream tData = new
MemoryStream(Encoding.UTF8.GetBytes(tSvg)); MemoryStream tStream = new
MemoryStream(); string
tTmp = new
Random().Next().ToString(); string
tExt = ""; string
tTypeString = ""; switch
(tType) { case
"image/png": tTypeString = "-m image/png"; tExt = "png"; break; case
"image/jpeg": tTypeString = "-m image/jpeg"; tExt = "jpg"; break; case
"application/pdf": tTypeString = "-m application/pdf"; tExt = "pdf"; break; case
"image/svg+xml": tTypeString = "-m image/svg+xml"; tExt = "svg"; break; } if
(tTypeString != "") { string
tWidth = Request.Form["width"].ToString(); Svg.SvgDocument tSvgObj = SvgDocument.Open(tData); switch
(tExt) { case
"jpg": tSvgObj.Draw().Save(tStream, ImageFormat.Jpeg); break; case
"png": tSvgObj.Draw().Save(tStream, ImageFormat.Png); break; case
"pdf": PdfWriter tWriter = null; Document tDocumentPdf = null; try { tSvgObj.Draw().Save(tStream, ImageFormat.Png); tDocumentPdf = new
Document(new
Rectangle((float)tSvgObj.Width, (float)tSvgObj.Height)); tDocumentPdf.SetMargins(0.0f, 0.0f, 0.0f, 0.0f); iTextSharp.text.Image tGraph = iTextSharp.text.Image.GetInstance(tStream.ToArray()); tGraph.ScaleToFit((float)tSvgObj.Width, (float)tSvgObj.Height); tStream = new
MemoryStream(); tWriter = PdfWriter.GetInstance(tDocumentPdf, tStream); tDocumentPdf.Open(); tDocumentPdf.NewPage(); tDocumentPdf.Add(tGraph); tDocumentPdf.CloseDocument(); } catch
(Exception ex) { throw
ex; } finally { tDocumentPdf.Close(); tDocumentPdf.Dispose(); tWriter.Close(); tWriter.Dispose(); tData.Dispose(); tData.Close(); } break; case
"svg": tStream = tData; break; } } Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = tType; Response.AppendHeader("Content-Disposition", "attachment; filename="
+ tFileName + "."
+ tExt + ""); Response.BinaryWrite(tStream.ToArray()); Response.End(); } } }} |
exporting.src.js文件中,导出服务地址改为 url: ‘HighChart.aspx‘即可。
原文:http://www.cnblogs.com/kinger906/p/3545141.html