JFreeChart - ChartFactory Method
이번엔 ChartFactory() 메소드에 대해 알아보자.
A collection of utility methods for creating some standard charts with JFreeChart.
우린 Renderer를 이용해 다양한 차트를 그릴 수 있다.
하지만 우리가 기본적으로 쓸 수 있는 차트에 대해선 ChartFactory를 이용해 간편히 그릴 수가 있다.
아래는 기본적인 사용 예이다.
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@page import="org.jfree.chart.JFreeChart"%> <%@page import="org.jfree.chart.ChartFrame"%> <%@page import="org.jfree.chart.ChartUtilities"%> <%@page import="org.jfree.data.general.DefaultPieDataset"%> <%@page import="org.jfree.chart.ChartFactory"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"> <title>Insert title here</title> </head> <body> <% DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("1",23); dataset.setValue("2",12); dataset.setValue("3",20); JFreeChart chart = ChartFactory.createPieChart("",dataset,true,true,false); ChartFrame frame = new ChartFrame("Chart", chart); frame.pack(); frame.setVisible(true); %> </body> </html> |
Area Charts Bar Charts Line Charts Pie Charts Financial Charts Gantt Chart Statistical Charts Etc Charts
PiePlot plot = chart.getPlot(); |
그리고나서 plot에 대한 set() method를 이용해 설정을 할 수가 있다.
ChartFactory를 이용하게 되면 위와 같이 간단한 코드만으로도 Chart를 그릴 수 있다.
일반사용자의 경우 위의 표에 있는 차트만으로도 충분하리라 본다.
더욱 복잡한 차트를 그리긴 위해선 Renderer를 이용하는 것이 좋을 듯 싶다.