翻譯|使用教程|編輯:王香|2018-09-20 16:23:45.000|閱讀 443 次
概述:本文詳細介紹了在TeeChart for Java使用代碼導出和導入圖表。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
【下載TeeChart for Java最新版本】
可以將所有格式復制到文件或剪貼板或Stream。
Tej格式是一種靈活的格式,可存儲圖表屬性信息以及(可選)圖表數據。文件很小(取決于數據),非常適合網絡用于更新基于實時客戶端的圖表。
導出到文件是合理的,在大多數情況下,您只需要定義目標文件名,例:
try { tChart1.getExport().getImage().getBMP().save(fileName); } catch (IOException ex) { System.out.println(ex); }
JPEG文件導出具有速度和質量的附加參數,例:
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格式的許多優點,但也提供了超出GIF格式的功能。PNG改進了GIF逐步顯示圖像的能力; 也就是說,當圖像通過網絡連接到達時,顯示更好和更好的圖像近似值,例:
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導出數據。它們可以創建并與圖表系列相關聯,從中可以將數據導出為文件,流或剪貼板。
try { myChart.getExport().getData().getText().save(tmpName); }
try { myChart.getExport().getTemplate().toXML(tmpName); showSavedFile(tmpName); }
Tej文件是TeeChart自己的模板格式,用于保存圖表及其數據,并在Java IDE中具有.tej擴展名。修改的圖表屬性隨模板一起保存,并在模板導入新圖表時重現,優點:
try { tChart1.getExport().getTemplate().toFile("/temp/chart1.tej"); } catch (IOException ex1) { ex1.printStackTrace(); }
顯示如何從xml導出和加載的示例:
保存到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數據源導入已保存的Tej文件。
文件導入
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正版授權,請點擊“”喲!
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn