Instance:
Function brandpie (args_datetime ){
VaR demis=windodoc ument. getelementbyid ("first"). value;
VaR chart;
$. Ajax ({
Type:
"Post ",
Data: {demision: "3", querydate: args_datetime },
URL: "report/dogetitempieorcolumn. Action? Querytype = "+ querytype,
Success: function (data)
{
VaR jsonarray = eval ('+ Data + ')');
VaR piedata = jsonarray. Data;
Chart = new highcharts. Chart ({
Chart:
{
Renderto:
'Containere2 ',
Plotbackgroundcolor:
Null,
Plotborderwidth: NULL,
Plotshadow: false
},
Title :{
Text:
'Test'
},
Subtitle :{
Text:
"Date:" + args_datetime,
X:-20
},
Tooltip :{
Percentagedecimals: 2,
Pointformat: '{series. Name }:{ point. Percentage} % ',
},
Credits :{
Enabled:
False,
},
Exporting :{
Filename: 'test ',
URL: 'chart/doexport. action ',
},
Plotoptions :{
Pie:
{
Allowpointselect:
True,
Cursor: 'pointer ',
Datalabels :{
Enabled:
False
},
Showinlegend: True
}
},
Series :[{
Type:
'Pie ',
Name: 'proportion ',
Data: piedata
}]
});
}
});
}
In the above example:The exporting attribute is mainly used and exported. filename indicates the name of the file that is everywhere, and URL indicates the action to be exported. The default request parameter isType: exported file (.jpg/PDF)
Filename: indicates the exported file name; SVG: indicates some parameters during export.
Background processing action:
ImportJava. Io. ioexception;
ImportJava. Io. stringreader;
ImportJavax. servlet. servletoutputstream;
ImportJavax. servlet. http. httpservletresponse;
ImportOrg. Apache. batik. Transcoder. Transcoder;
ImportOrg. Apache. batik. Transcoder. transcoderexception;
ImportOrg. Apache. batik. Transcoder. transcoderinput;
ImportOrg. Apache. batik. Transcoder. transcoderoutput;
ImportOrg. Apache. batik. Transcoder. image. Specify Transcoder;
ImportOrg. Apache. batik. Transcoder. image. pngtranscoder;
ImportOrg. Apache. fop. SVG. pdftranscoder;
@ Suppresswarnings ("serial ")
Public
ClassChartsexportactionExtendsBaseaction {
PrivateString
Type;
PrivateString
SVG;
PrivateString
Filename;
Public
VoidSetfilename (string filename ){
This. Filename = filename;
}
PublicString getfilename (){
Return
Filename;
}
Public
VoidSetsvg (string SVG ){
This. SVG = SVG;
}
PublicString getsvg (){
Return
SVG;
}
Public
VoidSettype (string type ){
This. Type = type;
}
PublicString GetType (){
Return
Type;
}
PublicString Export (){
String type =This. GetType ();
String SVG =This. Getsvg ();
Httpservletresponse response =Null;
System.Out. Println (SVG );
Servletoutputstream outputstream =
Null;
Try{
Response =This. Getresponse ();
Outputstream = response. getoutputstream ();
System.Out. Println ("type:" + type );
If(Null! = Type &&
Null! = SVG ){
SVG = SVG. replaceall (": rect ",
"Rect ");
String ext = "";
Transcoder T =Null;
If(Type. Equals ("image/PNG ")){
EXT = "PNG ";
T =NewPngtranscoder ();
}Else
If(Type. Equals ("image/JPEG ")){
EXT = "jpg ";
T =NewJpegtranscoder ();
}Else
If(Type. Equals ("image/SVG + XML ")){
EXT = "SVG ";
}Else
If(Type. Equals ("application/pdf ")){
EXT = "pdf ";
T =NewPdftranscoder ();
}
Response. addheader ("content-disposition ",
"Attachment; filename ="
+ Java.net. urlencoder.Encode(
This. Getfilename (),
"UTF-8") + "."
+ Ext );
Response. addheader ("Content-Type", type );
If(Null! = T ){
Transcoderinput input =NewTranscoderinput (
NewStringreader (SVG ));
Transcoderoutput output =NewTranscoderoutput (outputstream );
Try{
T. transcode (input, output );
}Catch(Transcoderexception e ){
Outputstream
. Print ("problem transcoding stream. See the web logs for more details .");
E. printstacktrace ();
}
}Else
If(EXT = "SVG "){
Outputstream. Print (SVG );
}Else{
Outputstream. Print ("invalid type:" + type );
}
}Else{
Response. addheader ("Content-Type ",
"Text/html ");
Outputstream
. Println ("Usage: \ n \ tparameter [SVG]: The Dom element to be converted. \ n \ tparameter [type]: The destinationmime type for the elment to be transcoded. ");
}
Outputstream. Flush ();
}Catch(Exception e ){
//Todo: Handleexception
E. printstacktrace ();
}Finally{
If(Outputstream! =
Null)
Try{
Outputstream. Close ();
}Catch(Ioexception e ){
//TodoAuto-generatedcatch Block
E. printstacktrace ();
}
}
Return
Null;
}
}