翻譯|使用教程|編輯:王香|2018-09-20 16:23:45.000|閱讀 443 次
概述:本文詳細(xì)介紹了在TeeChart for Java使用代碼導(dǎo)出和導(dǎo)入圖表。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
【下載TeeChart for Java最新版本】
可以將所有格式復(fù)制到文件或剪貼板或Stream。
Tej格式是一種靈活的格式,可存儲圖表屬性信息以及(可選)圖表數(shù)據(jù)。文件很小(取決于數(shù)據(jù)),非常適合網(wǎng)絡(luò)用于更新基于實時客戶端的圖表。
導(dǎo)出到文件是合理的,在大多數(shù)情況下,您只需要定義目標(biāo)文件名,例:
try { tChart1.getExport().getImage().getBMP().save(fileName); } catch (IOException ex) { System.out.println(ex); }
JPEG文件導(dǎo)出具有速度和質(zhì)量的附加參數(shù),例:
int tmpResult = fc.showSaveDialog(JpegExportDemo.this); if (tmpResult == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); String tmpName = file.getAbsolutePath(); if (!ExportUtils.isExtension(file, ExportUtils.JPG)) { tmpName = ExportUtils.replaceExtension(file, ExportUtils.JPG); } myChart.getExport().getImage().getJPEG().save(tmpName); }
代碼示例:
int tmpResult = fc.showSaveDialog(BmpExportDemo.this); if (tmpResult == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); String tmpName = file.getAbsolutePath(); if (!ExportUtils.isExtension(file, ExportUtils.BMP)) { tmpName = ExportUtils.replaceExtension(file, ExportUtils.BMP); } myChart.getExport().getImage().getBMP().save(tmpName); }
PNG格式保留了GIF格式的許多優(yōu)點,但也提供了超出GIF格式的功能。PNG改進了GIF逐步顯示圖像的能力; 也就是說,當(dāng)圖像通過網(wǎng)絡(luò)連接到達(dá)時,顯示更好和更好的圖像近似值,例:
int tmpResult = fc.showSaveDialog(PngExportDemo.this); if (tmpResult == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); String tmpName = file.getAbsolutePath(); if (!ExportUtils.isExtension(file, ExportUtils.PNG)) { tmpName = ExportUtils.replaceExtension(file, ExportUtils.PNG); } myChart.getExport().getImage().getPNG().save(tmpName); }
以下示例以Text或XML格式從Chart Series導(dǎo)出數(shù)據(jù)。它們可以創(chuàng)建并與圖表系列相關(guān)聯(lián),從中可以將數(shù)據(jù)導(dǎo)出為文件,流或剪貼板。
try { myChart.getExport().getData().getText().save(tmpName); }
try { myChart.getExport().getTemplate().toXML(tmpName); showSavedFile(tmpName); }
Tej文件是TeeChart自己的模板格式,用于保存圖表及其數(shù)據(jù),并在Java IDE中具有.tej擴展名。修改的圖表屬性隨模板一起保存,并在模板導(dǎo)入新圖表時重現(xiàn),優(yōu)點:
try { tChart1.getExport().getTemplate().toFile("/temp/chart1.tej"); } catch (IOException ex1) { ex1.printStackTrace(); }
顯示如何從xml導(dǎo)出和加載的示例:
保存到xml
try { myChart.getExport().getTemplate().toXML(tmpName); showSavedFile(tmpName); } catch (FileNotFoundException e) { System.out.println(e); }
從XML加載
try { myChart.setChart(myChart.getImport().getTemplate().fromXML(tmpName)); myChart.repaint(); } catch (FileNotFoundException e) { System.out.println(e); }
從本地文件源或http數(shù)據(jù)源導(dǎo)入已保存的Tej文件。
文件導(dǎo)入
tChart1.getImport().getTemplate().fromFile("myFile.tej");
XML
tChart1.getImport().getTemplate().fromXML("myFile.xml");
Stream
try { //( 1) Save the template into a Stream... ByteArrayOutputStream m = new ByteArrayOutputStream(); myChart.getExport().getTemplate().toStream(m); //( 2) Load the template into other Chart... copyChart.setChart(copyChart.getImport().getTemplate().fromStream( new ByteArrayInputStream(m.toByteArray()) )); //( 3) repaint the Chart copyChart.repaint(); } catch (IOException ex) { System.out.println(ex); } catch (ClassNotFoundException ex) { System.out.println(ex); }
購買TeeChart for Java正版授權(quán),請點擊“”喲!
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn