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.CategoryAxis;
006    import org.jfree.chart.axis.ValueAxis;
007    import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
008    import org.jfree.chart.plot.CategoryPlot;
009    import org.jfree.chart.plot.PlotOrientation;
010    import org.jfree.chart.renderer.category.LineAndShapeRenderer;
011    import org.jfree.data.category.CategoryDataset;
012    import org.jfree.data.general.AbstractDataset;
013    
014    public class LineChartType 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.createLineChart(title, xLabel, yLabel,
022                    (CategoryDataset) dataset, orientation, legend, tooltips, urls);
023    
024            LineAndShapeRenderer renderer = new LineAndShapeRenderer();
025    
026            if (tooltips) {
027                renderer
028                        .setToolTipGenerator(new StandardCategoryToolTipGenerator());
029            }
030            if (shape) {
031                renderer.setShapesFilled(true);
032            }
033            CategoryPlot plot = chart.getCategoryPlot();
034            plot.setRenderer(renderer);
035    
036            CategoryAxis xAxis = plot.getDomainAxis();
037            xAxis.setUpperMargin(0.0);
038            xAxis.setLowerMargin(0.0);
039    
040            ValueAxis yAxis = plot.getRangeAxis();
041            yAxis.setLowerBound(yMin);
042            if (yMax > 0) {
043                yAxis.setRange(yMin, yMax);
044            }
045            return chart;
046        }
047    }