| 1 2 35 36 package org.krysalis.jcharts.demo.samples; 37 38 39 import org.krysalis.jcharts.Chart; 40 import org.krysalis.jcharts.chartData.ChartDataException; 41 import org.krysalis.jcharts.encoders.PNGEncoder; 42 43 import java.io.FileOutputStream ; 44 45 46 51 public abstract class Sample 52 { 53 private static String path; 54 private static final String dir= "/samples/"; 55 56 57 58 protected abstract void render() throws ChartDataException; 59 protected abstract String getSubdir(); 60 61 62 69 public static void main( String [] args ) throws ChartDataException 70 { 71 Sample.path= args[ 0 ]; 72 73 new AreaChartSamples().render(); 74 new Pie3DSamples().render(); 75 } 76 77 78 83 protected void encode( Chart chart, String filename ) 84 { 85 FileOutputStream fileOutputStream; 86 87 try 88 { 89 fileOutputStream = new FileOutputStream ( path + dir + this.getSubdir() + filename + ".png" ); 90 PNGEncoder.encode( chart, fileOutputStream ); 91 fileOutputStream.flush(); 92 fileOutputStream.close(); 93 } 94 catch( Throwable throwable ) 95 { 96 throwable.printStackTrace(); 97 } 98 } 99 } 100 | Popular Tags |