JfreeChart 학습 총화

    3D   :
public class Report {
	public static void main(String[] args) {
		//        
		DefaultCategoryDataset dataset = new DefaultCategoryDataset();
		//     
		dataset.setValue(6, "Profit", "Jane");
		dataset.setValue(3, "Profit2", "Jane");
		dataset.setValue(7, "Profit", "Tom");
		dataset.setValue(6, "Profit2", "Tom");
		dataset.setValue(8, "Profit", "Jill");
		dataset.setValue(9, "Profit2", "Jill");
		dataset.setValue(5, "Profit", "John");
		dataset.setValue(8, "Profit2", "John");
		dataset.setValue(12, "Profit", "Fred");
		dataset.setValue(11, "Profit2", "Fred");

		//      
		// JFreeChart chart =
		// ChartFactory.createXYLineChart("  ","x   ","y   ","    "
		// ,"        ",      ,      ,          );
		//       :
		// (1)HORIZONTAL:      
		// (2)VERTICAL:      

		// 3D   
		JFreeChart chart = ChartFactory.createBarChart3D("     ", "Salesman",
				"Profit", dataset, PlotOrientation.VERTICAL, true, true, false);

		try {
			// //         
			// ChartFrame cf = new ChartFrame("   ",chart);
			// cf.pack();
			// //       
			// cf.setSize(500,300);
			// //       
			// cf.setVisible(true);

			//           
			ChartUtilities.saveChartAsJPEG(new File("C:\\BarChart.jpg"), chart,
					500, 300);
		} catch (Exception e) {
			System.err.println("Problem occurred creating chart.");
		}
	}
}

 
public class JFreeReport {
	Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
	Connection conn = DriverManager
			.getConnection("jdbc:microsoft:sqlserver://localhost:1433;User=sa;Password=;DatabaseName=library");
	Statement stmt = conn.createStatement();
	ResultSet rs = stmt
			.executeQuery("select bookType, bookCount=count(*) from books group by bookType");
	// 2 , ResultSet  CategoryDataset
	DefaultCategoryDataset dataset = new DefaultCategoryDataset();

	while (rs.next()) {
		String bookType = rs.getString("bookType");
		int bookCount = rs.getInt("bookCount");
		//        ,                :“Count”。
		//             : bookType  , bookCount  
		//Count            
		//  《   JFreeChart     web   》              
		dataset.setValue(bookCount, "Count", bookType);
	}
	/*
	 JfreeChart       Datasource/Connection
	    Dataset JDBCDataset,           
	 */

	// 3 , Dateset   Chart
	JFreeChart chart = ChartFactory.createBarChart("          ", "  ",
			"  ", dataset, PlotOrientation.VERTICAL, true, true, false);
	//    ,     WEB
	ChartUtilities.writeChartAsJPEG(response.getOutputStream(), chart,
			640, 370);
	//640 370    Chart      
	//      ResultSet          
	//               
	//   Chart      ,         
}

좋은 웹페이지 즐겨찾기