Java Grab CSV Data Load JFreeChart


//...
// Set up static path/file variables
	private static final String FILE_PATH = "C:\\temp\\JFREE_DATA\\";
	private static final String OUTFILE_NAME = "JFreeChartCSVExplorerData.jpg";

 //...
    //run chart - Xpages button
    public void doRunJFreeBarChartFromCSV() throws IOException {
    	
    	String query = "SELECT * FROM UserNewLineOutboundInformation";
		JDBCCategoryDataset dataset = null;
		try {
			dataset = new JDBCCategoryDataset("jdbc:relique:csv:C:\\temp\\CSV_DATA\\","org.relique.jdbc.csv.CsvDriver", "root", "root");
		} catch (ClassNotFoundException e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		} catch (SQLException e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}
		try {
			dataset.executeQuery(query);
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		JFreeChart chart = ChartFactory.createBarChart3D(
				"JFreeChart CSV Trend", "SiteName", "SiteNumber", dataset,
				PlotOrientation.VERTICAL, true, true, false);
		try {
			ChartUtilities.saveChartAsJPEG(new File(FILE_PATH+OUTFILE_NAME), chart, 400,300);
			System.out.println("JFreeChart created from CSV file.");

		} catch (IOException e) {
			System.out.println("Problem in creating chart.");
		}

		// Load Chart to Explorer
		// 2012.04.23.8.25.AM
		try {

			//Grab the file created from location
			//Load to Explorer window for user
			FileOutputStream fos = new FileOutputStream(FILE_PATH+OUTFILE_NAME);
			ChartUtilities.writeChartAsJPEG(fos, 1, chart, 950, 600);
			fos.flush();
			fos.close();

			Runtime run = Runtime.getRuntime();
			run.exec("explorer.exe  " + FILE_PATH+OUTFILE_NAME);

		} catch (Exception e) {

		}
    } 
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
No comments yetLogin first to comment...