Echarts Chart Export Excel example _java

Source: Internet
Author: User
Tags base64 flush

Generate the corresponding graphic based on the parameters passed in

Copy Code code as follows:

Loadchart:function (Data,item) {
var that = this;
Require ([' echarts ', ' echarts/chart/bar ', ' echarts/chart/line ',
' Echarts/chart/pie '], function (EC) {
That.body.setHeight (800);
var MyChart = Ec.init (that.body.dom);
Mychart.showloading ({
Text: "The chart data is trying to load ..."
});


var option = {
ToolTip: {
Trigger: ' Axis ',
Axispointer: {//Axis indicator, axis trigger valid
Type: ' Shadow '//default line, Optional: ' Lines ' | ' Shadow '
}
},
Legend: {
Data:data.indis,
x: ' Left ',
Y: ' Top '
},
Toolbox: {
Show:true,
Orient: ' Vertical ',
x: ' Right ',
Y: ' Center ',
Feature: {
Mark: {
Show:true
},
DataView: {
Show:true,
Readonly:true
},
Magictype: {
Show:true,
Type: [' line ', ' Bar ', ' stack ', ' tiled ']
},
Restore: {
Show:true
},
Saveasimage: {
Show:true
}
}
},
Calculable:true,
Animation:false,
Xaxis: [{
Type: ' Category ',
Data:data.grp
}],
YAxis: [{
Type: ' Value ',
Splitarea: {
Show:true
}
}],
Series:data.bar.series
};
}
Mychart.hideloading ();
mychart.setoption (option);
That.imgurl = Mychart.getdataurl (' png ');//Get Base64 encoding
});

},
Initechart:function () {
Require.config ({
paths:{
' Echarts ': ' Js/com/bhtec/echart/echarts ',
' Echarts/chart/bar ': ' Js/com/bhtec/echart/echarts ',
' Echarts/chart/line ': ' Js/com/bhtec/echart/echarts ',
' Echarts/chart/pie ': ' Js/com/bhtec/echart/echarts '
}
});
}

Passing data to the background

Copy Code code as follows:

Doexport:function () {

var url = This.chartPanel.getImageURL ();
var title = Ext.fly (' Indi-display-title-id ').-A (). dom.innerhtml;
var left = ext.getcmp ("indi_pivotgrid_id"). Leftaxis.gettuples ();
var t = ext.getcmp ("indi_pivotgrid_id"). Topaxis.gettuples ();

TODO get Base64 's picture encoding
Ext.Ajax.request ({
URL: ' Indicator/exp2excl.mvc ',
Params: {
Imgurl:url,
Left:gets (left)
}
});
function GetS (d) {
var arr = [],str;
for (Var i=0;i<d.length;i++) {
var s = indifn.getaxisstr (D[i]);
Arr.push (s);
}
str = Arr.join (', ');
return str;
}
var data = ext.getcmp ("indi_pivotgrid_id"). Extractdata ();
var s,arr=[];
for (Var i=0;i<data.length;i++) {
Arr.push (Data[i]);
}

window.open (' indicator/exportlist2excel.mvc?title= ' +encodeuricomponent (encodeuricomponent (title)) + ' &left= ' +encodeuricomponent (encodeURIComponent (GetS (left))) + ' +
' &top= ' +encodeuricomponent (encodeURIComponent (GetS (t))) + ' &data= ' +arr.join (';'));
}

Parsing base64, generating pictures

Copy Code code as follows:

public void Base64topic (String fileName, httpservletrequest req) {
Base64 decoding and generating a picture of a byte array string
if (Imgsurl = = null)//image data is empty
return;
Base64decoder decoder = new Base64decoder ();
Try
{
string[] url = imgsurl.split (",");
String u = url[1];
Base64 decoding
byte[] buffer = new Base64decoder (). Decodebuffer (U);
Generate pictures
OutputStream out = new FileOutputStream (New File (Req.getrealpath ("pic/" +filename+ ". jpg"));
Out.write (buffer);
Out.flush ();
Out.close ();
Return
}
catch (Exception e)
{
Return
}
}

Put a picture into Excel by poi the drawing

Copy Code code as follows:

row = Sheet.createrow (index+3);
Hssfcell Headercell = Row.createcell (0);
Headercell.setcelltype (Hssfcell.cell_type_blank);
Headercell.setcellvalue (title);

row = Sheet.createrow (index + 6);
Hssfcell cells = Row.createcell (0);
Cells.setcelltype (Hssfcell.cell_type_blank);
Bytearrayoutputstream OutStream = new Bytearrayoutputstream (); Write a picture to the stream
BufferedImage bufferimg = Imageio.read (New File (Req.getrealpath ("pic/" +filename+ ". jpg"));
Imageio.write (bufferimg, "PNG", OutStream); Use Hssfpatriarch to write pictures to Excel
Hssfpatriarch Patri = Sheet.createdrawingpatriarch ();
Hssfclientanchor anchor = new Hssfclientanchor (5, 5, 5, 5,
(short) 1, index + 6, (short) 6, 45);
Patri.createpicture (anchor, Workbook.addpicture (
Outstream.tobytearray (), hssfworkbook.picture_type_png));
try {
Workbook.write (out);
Out.flush ();
Out.close ();
catch (IOException e) {
E.printstacktrace ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.