Java Listens to LotusScript, Runs JFreeChart


//...
//JfreeChartWithCSVDataJavaAgent.java

/**
 * Created from copy: 2012.04.23.10.47.AM
 * Load CSV Data into Bar Chart
 *
 */

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.SQLException;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.jdbc.JDBCCategoryDataset;

/**
 * @author Dököll Solutions, Inc.
 * @version 2012.04.23.10.47.AM
 * 
 */
public class JFreeChartWithCSVDataJavaAgent {
	// Set up static path/file variables
	private static final String FILE_PATH = "C:\\temp\\JFREE_DATA\\";
	private static final String OUTFILE_NAME = "JFreeChartCSVExplorerData.jpg";

	//TO DO: Add button code to this, run as a bean
	public String doLoadJFreeChart() throws ClassNotFoundException, SQLException{
	//public static void main(String[] args) throws Exception {
		//set up query string
		String query = "SELECT * FROM UserNewLineOutboundInformation";
		//set path and connection to CSV file
		JDBCCategoryDataset dataset = new JDBCCategoryDataset(
				"jdbc:relique:csv:C:\\temp\\CSV_DATA\\",
				"org.relique.jdbc.csv.CsvDriver", "root", "root");
		//run query
		dataset.executeQuery(query);
		//create bar chart in 3D
		JFreeChart chart = ChartFactory.createBarChart3D(
				"JFreeChart Agent CSV Trend", "SiteName", "SiteNumber", dataset,
				PlotOrientation.VERTICAL, true, true, false);
		try {
			//save chart to location, gets picked up by Explorer
			ChartUtilities.saveChartAsJPEG(new File(FILE_PATH+OUTFILE_NAME), chart, 400,
					300);
			System.out.println("Chart 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 file created from C:/
			//set it up to run through Explorer window
			FileOutputStream fos = new FileOutputStream(FILE_PATH+OUTFILE_NAME);
			ChartUtilities.writeChartAsJPEG(fos, 1, chart, 950, 600);
			//...
			fos.flush();
			fos.close();

			//load chart to Explorer window...
			Runtime run = Runtime.getRuntime();
			//...
			run.exec("explorer.exe  " + FILE_PATH+OUTFILE_NAME);

		} catch (Exception e) {

		}
		//...
		return query;

	}
}
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...