echarts圖表導(dǎo)出excel示例
根據(jù)傳入的參數(shù)生成相應(yīng)的圖形
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 : "圖表數(shù)據(jù)正在努力加載..."
});
var option = {
tooltip : {
trigger : 'axis',
axisPointer : { // 坐標(biāo)軸指示器,坐標(biāo)軸觸發(fā)有效
type : 'shadow' // 默認(rèn)為直線,可選為:'line' | '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');//獲取base64編碼
});
},
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'
}
});
}
將數(shù)據(jù)傳遞到后臺(tái)
doExport : function(){
var url = this.chartPanel.getImageURL();
var title = Ext.fly('indi-display-title-id').first().dom.innerHTML;
var left = Ext.getCmp("indi_pivotGrid_id").leftAxis.getTuples();
var t = Ext.getCmp("indi_pivotGrid_id").topAxis.getTuples();
//TODO 獲取base64的圖片編碼
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(';'));
}
解析base64,生成圖片
public void base64TOpic(String fileName, HttpServletRequest req) {
//對(duì)字節(jié)數(shù)組字符串進(jìn)行Base64解碼并生成圖片
if (imgsURl == null) //圖像數(shù)據(jù)為空
return ;
BASE64Decoder decoder = new BASE64Decoder();
try
{
String[] url = imgsURl.split(",");
String u = url[1];
//Base64解碼
byte[] buffer = new BASE64Decoder().decodeBuffer(u);
//生成圖片
OutputStream out = new FileOutputStream(new File(req.getRealPath("pic/"+fileName+".jpg")));
out.write(buffer);
out.flush();
out.close();
return;
}
catch (Exception e)
{
return;
}
}
通過poi畫圖,將圖片放入到excel中
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(); // 將圖片寫入流中
BufferedImage bufferImg = ImageIO.read(new File(req.getRealPath("pic/"+fileName+".jpg")));
ImageIO.write(bufferImg, "PNG", outStream); // 利用HSSFPatriarch將圖片寫入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();
}
相關(guān)文章
java.util.Date與java.sql.Date的區(qū)別
這篇文章主要介紹了java.util.Date與java.sql.Date的區(qū)別的相關(guān)資料,需要的朋友可以參考下2015-07-07
Spring詳細(xì)講解FactoryBean接口的使用
這篇文章主要為大家介紹了Spring容器FactoryBean工廠實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06
Java IO流之節(jié)點(diǎn)流與字符流的相關(guān)知識(shí)總結(jié)
今天給大家?guī)淼氖顷P(guān)于Java的相關(guān)知識(shí),文章圍繞著Java節(jié)點(diǎn)流與字符流展開,文中有非常詳細(xì)的介紹及代碼示例,需要的朋友可以參考下2021-06-06
Spring Boot 中的 @ConditionalOnBean 注解作用及基
在 Spring Boot 中,@ConditionalOnBean 可以幫助我們根據(jù) 是否存在特定 Bean 來 動(dòng)態(tài)注冊(cè) Bean,廣泛用于 按需加載、自動(dòng)配置 等場(chǎng)景,本文給大家介紹Spring Boot 中的 @ConditionalOnBean 注解,感興趣的朋友一起看看吧2025-04-04
Java實(shí)戰(zhàn)之郵件的撰寫和發(fā)送
這篇文章主要為大家詳細(xì)介紹了通過Java代碼實(shí)現(xiàn)郵件的撰寫和發(fā)送功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,需要的小伙伴們可以學(xué)習(xí)一下2021-11-11
在idea中利用maven實(shí)現(xiàn)多環(huán)境配置自動(dòng)打包的流程步驟
這篇文章主要介紹了在idea中利用maven實(shí)現(xiàn)多環(huán)境配置自動(dòng)打包的流程步驟,文中通過圖文和代碼示例介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定幫助,需要的朋友可以參考下2024-11-11
C/C++中的struct結(jié)構(gòu)體詳細(xì)解讀
這篇文章主要介紹了C/C++中的struct結(jié)構(gòu)體詳細(xì)解讀,結(jié)構(gòu)體是由一批數(shù)據(jù)組合而成的結(jié)構(gòu)型數(shù)據(jù),組成結(jié)構(gòu)型數(shù)據(jù)的每個(gè)數(shù)據(jù)稱為結(jié)構(gòu)型數(shù)據(jù)的“成員”,其描述了一塊內(nèi)存區(qū)間的大小及意義,需要的朋友可以參考下2023-10-10
詳解OpenCV For Java環(huán)境搭建與功能演示
這篇文章主要介紹了x詳解OpenCV For Java環(huán)境搭建與功能演示,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-04-04

