001 package jp.osdl.jbento2.chart; 002 003 import org.jfree.chart.ChartFactory; 004 import org.jfree.chart.JFreeChart; 005 import org.jfree.chart.axis.ValueAxis; 006 import org.jfree.chart.labels.StandardXYToolTipGenerator; 007 import org.jfree.chart.plot.PlotOrientation; 008 import org.jfree.chart.plot.XYPlot; 009 import org.jfree.chart.renderer.xy.StandardXYItemRenderer; 010 import org.jfree.chart.urls.StandardXYURLGenerator; 011 import org.jfree.data.general.AbstractDataset; 012 import org.jfree.data.xy.XYDataset; 013 014 public class TimeSeriesChartType implements ChartType { 015 016 public JFreeChart getChart(String title, String xLabel, String yLabel, 017 long xMin, long xMax, long yMin, long yMax, 018 AbstractDataset dataset, PlotOrientation orientation, 019 boolean legend, boolean tooltips, boolean urls, boolean shape) { 020 021 JFreeChart chart = ChartFactory.createTimeSeriesChart(title, xLabel, 022 yLabel, (XYDataset) dataset, legend, tooltips, urls); 023 StandardXYItemRenderer renderer = null; 024 if (shape) { 025 renderer = new StandardXYItemRenderer( 026 StandardXYItemRenderer.SHAPES_AND_LINES); 027 } else { 028 renderer = new StandardXYItemRenderer(); 029 } 030 if (tooltips) { 031 renderer.setToolTipGenerator(new StandardXYToolTipGenerator()); 032 } 033 if (urls) { 034 renderer.setURLGenerator(new StandardXYURLGenerator()); 035 } 036 037 XYPlot plot = chart.getXYPlot(); 038 plot.setRenderer(renderer); 039 040 ValueAxis xAxis = plot.getDomainAxis(); 041 // xAxis.setUpperMargin(0.0); 042 // xAxis.setLowerMargin(0.0); 043 if (xMax > 0) { 044 xAxis.setAutoRange(false); 045 xAxis.setRange(xMin, xMax); 046 } 047 048 ValueAxis yAxis = plot.getRangeAxis(); 049 yAxis.setLowerBound(yMin); 050 if (yMax > 0) { 051 yAxis.setRange(yMin, yMax); 052 } 053 054 return chart; 055 } 056 }