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 XYLineChartType 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.createXYLineChart(title, xLabel,
022 yLabel, (XYDataset) dataset, orientation, legend, tooltips,
023 urls);
024
025 StandardXYItemRenderer renderer = null;
026 if (shape) {
027 renderer = new StandardXYItemRenderer(
028 StandardXYItemRenderer.SHAPES_AND_LINES);
029 } else {
030 renderer = new StandardXYItemRenderer();
031 }
032 if (tooltips) {
033 renderer.setToolTipGenerator(new StandardXYToolTipGenerator());
034 }
035 if (urls) {
036 renderer.setURLGenerator(new StandardXYURLGenerator());
037 }
038
039 XYPlot plot = chart.getXYPlot();
040 plot.setRenderer(renderer);
041
042 ValueAxis xAxis = plot.getDomainAxis();
043 // xAxis.setUpperMargin(0.05);
044 // xAxis.setLowerMargin(0.05);
045 if (xMax > 0) {
046 xAxis.setAutoRange(false);
047 xAxis.setRange(xMin, xMax);
048 }
049 ValueAxis yAxis = plot.getRangeAxis();
050 yAxis.setLowerBound(yMin);
051 if (yMax > 0) {
052 yAxis.setRange(yMin, yMax);
053 }
054
055 return chart;
056 }
057 }