List of usage examples for org.jfree.chart.axis ValueAxis setUpperMargin
public void setUpperMargin(double margin)
From source file:com.ewcms.plugin.report.generate.service.chart.ChartGenerationService.java
/** * ?//from ww w .j ava 2 s .co m * <P> * ?XYPlot? ??? * <P> * ?:???TimeSeriesCollection?XYDataset? * * @param title * @param titleFont * @param timeAxisLabel * @param valueAxisLabel * @param data ?? * @param legend * @param tooltips ???? * @param urls ??URL * * @return ? */ public static JFreeChart createTimeSeriesChart(String title, java.awt.Font titleFont, String timeAxisLabel, String valueAxisLabel, XYDataset data, boolean legend, boolean tooltips, boolean urls) { ValueAxis timeAxis = new DateAxis(timeAxisLabel); timeAxis.setLowerMargin(0.02); timeAxis.setUpperMargin(0.02); NumberAxis valueAxis = new NumberAxis(valueAxisLabel); valueAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(data, timeAxis, valueAxis, null); XYToolTipGenerator tooltipGenerator = null; if (tooltips) { tooltipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance(); // new StandardXYToolTipGenerator(DateFormat.getDateInstance()); } XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } plot.setRenderer(new StandardXYItemRenderer(StandardXYItemRenderer.LINES, tooltipGenerator, urlGenerator)); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:com.tonbeller.jpivot.chart.ChartFactory.java
/** * Creates and returns a time series chart. * <P>//from w w w .ja va2 s .c om * A time series chart is an XYPlot with a date axis (horizontal) and a number axis (vertical), * and each data item is connected with a line. * <P> * Note that you can supply a TimeSeriesCollection to this method, as it implements the * XYDataset interface. * * @param title the chart title. * @param timeAxisLabel a label for the time axis. * @param valueAxisLabel a label for the value axis. * @param data the dataset for the chart. * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return a time series chart. */ public static JFreeChart createTimeSeriesChart(String title, java.awt.Font titleFont, String timeAxisLabel, String valueAxisLabel, XYDataset data, boolean legend, boolean tooltips, boolean urls) { ValueAxis timeAxis = new DateAxis(timeAxisLabel); timeAxis.setLowerMargin(0.02); // reduce the default margins on the time axis timeAxis.setUpperMargin(0.02); NumberAxis valueAxis = new NumberAxis(valueAxisLabel); valueAxis.setAutoRangeIncludesZero(false); // override default XYPlot plot = new XYPlot(data, timeAxis, valueAxis, null); XYToolTipGenerator tooltipGenerator = null; if (tooltips) { tooltipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance(); //new StandardXYToolTipGenerator(DateFormat.getDateInstance()); } XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } plot.setRenderer(new StandardXYItemRenderer(StandardXYItemRenderer.LINES, tooltipGenerator, urlGenerator)); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:org.gumtree.vis.awt.PlotFactory.java
/** * Creates and returns a time series chart. A time series chart is an * {@link XYPlot} with a {@link DateAxis} for the x-axis and a * {@link NumberAxis} for the y-axis. The default renderer is an * {@link XYLineAndShapeRenderer}.//from w w w . j a v a 2 s . c o m * <P> * A convenient dataset to use with this chart is a * {@link org.jfree.data.time.TimeSeriesCollection}. * * @param title the chart title (<code>null</code> permitted). * @param timeAxisLabel a label for the time axis (<code>null</code> * permitted). * @param valueAxisLabel a label for the value axis (<code>null</code> * permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A time series chart. */ public static JFreeChart createTimeSeriesChart(String title, String timeAxisLabel, String valueAxisLabel, XYDataset dataset, boolean legend, boolean tooltips, boolean urls) { ValueAxis timeAxis = new DateAxis(timeAxisLabel); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02); // NumberAxis valueAxis = new NumberAxis(valueAxisLabel); LogAxis valueAxis = new LogAxis(valueAxisLabel); // valueAxis.setAutoRangeIncludesZero(false); // override default XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null); XYToolTipGenerator toolTipGenerator = null; if (tooltips) { toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance(); } XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); renderer.setBaseToolTipGenerator(toolTipGenerator); renderer.setURLGenerator(urlGenerator); plot.setRenderer(renderer); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); ChartFactory.getChartTheme().apply(chart); return chart; }
From source file:org.opennms.netmgt.charts.ChartUtils.java
/** * @param chartConfig/* w w w . j ava 2s .com*/ * @param baseDataSet * @return */ private static JFreeChart createBarChart(BarChart chartConfig, DefaultCategoryDataset baseDataSet) { PlotOrientation po = (chartConfig.getPlotOrientation() == "horizontal" ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL); JFreeChart barChart = null; if ("3d".equalsIgnoreCase(chartConfig.getVariation())) { barChart = ChartFactory.createBarChart3D(chartConfig.getTitle().getValue(), chartConfig.getDomainAxisLabel(), chartConfig.getRangeAxisLabel(), baseDataSet, po, chartConfig.getShowLegend(), chartConfig.getShowToolTips(), chartConfig.getShowUrls()); } else { barChart = ChartFactory.createBarChart(chartConfig.getTitle().getValue(), chartConfig.getDomainAxisLabel(), chartConfig.getRangeAxisLabel(), baseDataSet, po, chartConfig.getShowLegend(), chartConfig.getShowToolTips(), chartConfig.getShowUrls()); } // Create a bit more headroom for value labels than is allowed for by the default 0.05 upper margin ValueAxis rangeAxis = barChart.getCategoryPlot().getRangeAxis(); if (rangeAxis.getUpperMargin() < 0.1) { rangeAxis.setUpperMargin(0.1); } return barChart; }
From source file:com.hmsinc.epicenter.webapp.chart.ChartService.java
/** * @param adapter//w w w . ja va2s.com * @param annotations * @return */ private static JFreeChart createChart(final AbstractChart adapter, final List<XYAnnotation> annotations) { final JFreeChart chart; if (adapter.getItems() instanceof XYDataset) { chart = ChartFactory.createTimeSeriesChart(adapter.getTitle(), adapter.getXLabel(), adapter.getYLabel(), (XYDataset) adapter.getItems(), true, false, false); final ValueAxis domainAxis = new DateAxis(); domainAxis.setLabelFont(LABEL_FONT); domainAxis.setTickLabelFont(LABEL_FONT); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); chart.getXYPlot().setDomainAxis(domainAxis); chart.getXYPlot().getRangeAxis().setLabelFont(LABEL_FONT); chart.getXYPlot().getRangeAxis().setTickLabelFont(LABEL_FONT); chart.getXYPlot().getRangeAxis().setStandardTickUnits(adapter.getRangeTickUnits()); if (adapter.isAlwaysScaleFromZero()) { final double upperBound = chart.getXYPlot().getRangeAxis().getRange().getUpperBound(); final Range range = new Range(0, upperBound + (upperBound * 0.2)); chart.getXYPlot().getRangeAxis().setRange(range); } for (Marker marker : adapter.getMarkers()) { chart.getXYPlot().addDomainMarker(marker); } if (annotations != null) { for (XYAnnotation annotation : annotations) { if (annotation instanceof XYPointerAnnotation) { ((XYPointerAnnotation) annotation).setFont(ANNOTATION_FONT); } chart.getXYPlot().addAnnotation(annotation); } } // Add any bands to the chart if (adapter instanceof TimeSeriesChart) { final TimeSeriesChart tsc = (TimeSeriesChart) adapter; for (int i = 0; i < tsc.getBands().size(); i++) { final Color c = tsc.getBandColors().get(i); final Color fill = tsc.getBandFillColors().get(i); final XYDifferenceRenderer renderer = new XYDifferenceRenderer(fill, fill, false); renderer.setSeriesPaint(0, c); renderer.setSeriesPaint(1, c); renderer.setSeriesStroke(0, LineStyle.THICK.getStroke()); renderer.setSeriesStroke(1, LineStyle.THICK.getStroke()); chart.getXYPlot().setDataset(i + 1, tsc.getBands().get(i)); chart.getXYPlot().setRenderer(i + 1, renderer); } } } else if (adapter.getItems() instanceof CategoryDataset) { chart = ChartFactory.createBarChart(adapter.getTitle(), adapter.getXLabel(), adapter.getYLabel(), (CategoryDataset) adapter.getItems(), PlotOrientation.VERTICAL, true, false, false); chart.getCategoryPlot().getDomainAxis().setLabelFont(LABEL_FONT); chart.getCategoryPlot().getRangeAxis().setLabelFont(LABEL_FONT); chart.getCategoryPlot().getDomainAxis().setTickLabelFont(LABEL_FONT); chart.getCategoryPlot().getRangeAxis().setTickLabelFont(LABEL_FONT); if (adapter.isAlwaysScaleFromZero()) { final double upperBound = chart.getCategoryPlot().getRangeAxis().getRange().getUpperBound(); final Range range = new Range(0, upperBound + (upperBound * 0.1)); chart.getCategoryPlot().getRangeAxis().setRange(range); } } else { throw new UnsupportedOperationException("Unsupported chart type: " + adapter.getItems().getClass()); } chart.getPlot().setNoDataMessage(NO_DATA_MESSAGE); return chart; }
From source file:org.jreserve.gui.plot.charts.AbstractChart.java
private void setAxisMargins(ValueAxis axis) { axis.setUpperMargin(MARGIN); axis.setLowerMargin(MARGIN); }
From source file:org.jfree.chart.demo.StackedBarChartDemo3.java
/** * Creates a sample chart.//from ww w . j ava 2 s. c om * * @param dataset the dataset for the chart. * * @return a sample chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createStackedBarChart("Stacked Bar Chart Demo 3", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // the plot orientation true, // legend false, // tooltips false // urls ); final CategoryPlot plot = chart.getCategoryPlot(); // final CategoryItemRenderer renderer = new ExtendedStackedBarRenderer(); // renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); // plot.setRenderer(renderer); final ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setLowerMargin(0.15); rangeAxis.setUpperMargin(0.15); return chart; }
From source file:com.sonyericsson.jenkins.plugins.bfa.graphs.TimeSeriesUnkownFailuresChart.java
@Override protected JFreeChart createGraph() { TimeTableXYDataset dataset = createDataset(); ValueAxis xAxis = new DateAxis(); xAxis.setLowerMargin(0.0);/*from w ww . j av a 2s. co m*/ xAxis.setUpperMargin(0.0); Calendar lowerBound = getLowerGraphBound(); xAxis.setRange(lowerBound.getTimeInMillis(), Calendar.getInstance().getTimeInMillis()); NumberAxis yAxis = new NumberAxis(Y_AXIS_LABEL); yAxis.setRange(0, HUNDRED_PERCENT); XYItemRenderer renderer = new XYBarRenderer(); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); JFreeChart chart = new JFreeChart(graphTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.removeLegend(); return chart; }
From source file:org.jfree.chart.demo.XYAreaChartDemo2.java
/** * Creates a chart.// www.j a v a 2 s. com * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final XYDataset dataset) { final JFreeChart chart = ChartFactory.createXYAreaChart("XY Area Chart Demo 2", "Time", "Value", dataset, PlotOrientation.VERTICAL, true, // legend true, // tool tips false // URLs ); final XYPlot plot = chart.getXYPlot(); final ValueAxis domainAxis = new DateAxis("Time"); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); plot.setDomainAxis(domainAxis); plot.setForegroundAlpha(0.5f); final XYItemRenderer renderer = plot.getRenderer(); renderer.setToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("#,##0.00"))); return chart; }
From source file:org.jfree.chart.demo.DifferenceChartDemo.java
/** * Creates a chart./* ww w . ja v a 2 s . c om*/ * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final XYDataset dataset) { final JFreeChart chart = ChartFactory.createTimeSeriesChart("Difference Chart Demo", "Time", "Value", dataset, true, // legend true, // tool tips false // URLs ); chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); plot.setRenderer(new XYDifferenceRenderer(Color.green, Color.red, false)); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); final ValueAxis domainAxis = new DateAxis("Time"); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); plot.setDomainAxis(domainAxis); plot.setForegroundAlpha(0.5f); return chart; }