List of usage examples for org.jfree.chart.axis NumberAxis setAutoRangeIncludesZero
public void setAutoRangeIncludesZero(boolean flag)
From source file:org.pentaho.plugin.jfreereport.reportcharts.XYAreaChartExpression.java
/** * Creates a stacked XY area plot. The chart object returned by this method uses an {@link * org.jfree.chart.plot.XYPlot} instance as the plot, with a {@link org.jfree.chart.axis.NumberAxis} for the domain * axis, a {@link org.jfree.chart.axis.NumberAxis} as the range axis, and a {@link * org.jfree.chart.renderer.xy.StackedXYAreaRenderer2} as the renderer. * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the plot orientation (horizontal or vertical) (<code>null</code> NOT 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 stacked XY area chart./*from w w w.j a v a2 s . com*/ */ protected static JFreeChart createStackedXYAreaChart(final String title, final String xAxisLabel, final String yAxisLabel, final XYDataset dataset, final PlotOrientation orientation, final boolean legend, final boolean tooltips, final boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } final NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); xAxis.setLowerMargin(0.0); xAxis.setUpperMargin(0.0); final NumberAxis yAxis = new NumberAxis(yAxisLabel); XYToolTipGenerator toolTipGenerator = null; if (tooltips) { toolTipGenerator = new StandardXYToolTipGenerator(); } XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } final StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2(toolTipGenerator, urlGenerator); renderer.setOutline(true); final XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(orientation); plot.setRangeAxis(yAxis); // forces recalculation of the axis range return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); }
From source file:org.jfree.chart.demo.VectorPlotDemo1.java
private static JFreeChart createChart(VectorXYDataset dataset) { NumberAxis xAxis = new NumberAxis("X"); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); xAxis.setLowerMargin(0.01D);// w w w .j a v a 2s .co m xAxis.setUpperMargin(0.01D); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis("Y"); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); yAxis.setLowerMargin(0.01D); yAxis.setUpperMargin(0.01D); yAxis.setAutoRangeIncludesZero(false); // VectorRenderer renderer = new VectorRenderer(); renderer.setSeriesPaint(0, Color.blue); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); plot.setOutlinePaint(Color.black); JFreeChart chart = new JFreeChart("Vector Plot Demo 1", plot); chart.setBackgroundPaint(Color.white); return chart; }
From source file:org.jfree.chart.demo.VectorRendererDemo1.java
private static JFreeChart createChart(VectorXYDataset dataset) { NumberAxis xAxis = new NumberAxis("X"); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); xAxis.setLowerMargin(0.01D);//from ww w .j a va 2 s . c om xAxis.setUpperMargin(0.01D); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis("Y"); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); yAxis.setLowerMargin(0.01D); yAxis.setUpperMargin(0.01D); yAxis.setAutoRangeIncludesZero(false); // VectorRenderer renderer = new VectorRenderer(); renderer.setSeriesPaint(0, Color.blue); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); plot.setOutlinePaint(Color.black); JFreeChart chart = new JFreeChart("Vector Renderer Demo 1", plot); chart.setBackgroundPaint(Color.white); return chart; }
From source file:org.pentaho.plugin.jfreereport.reportcharts.XYAreaChartExpression.java
public static JFreeChart createTimeSeriesChart(final String title, final String timeAxisLabel, final String valueAxisLabel, final XYDataset dataset, final boolean legend, final boolean tooltips, final boolean urls, final boolean stacked) { final ValueAxis timeAxis = new DateAxis(timeAxisLabel); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02);/*from w w w . j av a2 s . c om*/ final NumberAxis valueAxis = new NumberAxis(valueAxisLabel); valueAxis.setAutoRangeIncludesZero(false); // override default final XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null); XYToolTipGenerator toolTipGenerator = null; if (tooltips) { toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance(); } XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } final XYAreaRenderer2 renderer; if (stacked) { renderer = new StackedXYAreaRenderer2(); } else { renderer = new XYAreaRenderer2(); } renderer.setBaseToolTipGenerator(toolTipGenerator); renderer.setURLGenerator(urlGenerator); plot.setRenderer(renderer); return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); }
From source file:org.jfree.graphics2d.demo.SVGBarChartDemo1.java
/** * Creates a sample chart.// w w w . j av a2 s . c om * * @param dataset a dataset. * * @return The chart. */ private static JFreeChart createChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createLineChart("Statistical Bar Chart Demo 1", "Type", "Value", dataset); CategoryPlot plot = (CategoryPlot) chart.getPlot(); // customise the range axis... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(false); // customise the renderer... StatisticalBarRenderer renderer = new StatisticalBarRenderer(); renderer.setDrawBarOutline(false); renderer.setErrorIndicatorPaint(Color.black); renderer.setIncludeBaseInRange(false); plot.setRenderer(renderer); // ensure the current theme is applied to the renderer just added ChartUtilities.applyCurrentTheme(chart); renderer.setDefaultItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setDefaultItemLabelsVisible(true); renderer.setDefaultItemLabelPaint(Color.yellow); renderer.setDefaultPositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.INSIDE6, TextAnchor.BOTTOM_CENTER)); // set up gradient paints for series... GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); return chart; }
From source file:cn.InstFS.wkr.NetworkMining.UIs.TimeSeriesChart2.java
public static JFreeChart createChart(DataItems nor, DataItems abnor, String title, String protocol1, String protocol2) {// w w w . j av a 2s.c o m // ? XYDataset xydataset1 = TimeSeriesChart1.createNormalDataset(nor, protocol1); JFreeChart jfreechart = ChartFactory.createScatterPlot(title, "", "", xydataset1); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); XYLineAndShapeRenderer xylineandshaperenderer1 = (XYLineAndShapeRenderer) xyplot.getRenderer(); // ??1?1 NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); java.awt.geom.Ellipse2D.Double double1 = new java.awt.geom.Ellipse2D.Double(-4D, -4D, 6D, 6D); // ??? // ?? xylineandshaperenderer1.setSeriesLinesVisible(0, true); xylineandshaperenderer1.setBaseShapesVisible(false); xylineandshaperenderer1.setSeriesShape(0, double1); xylineandshaperenderer1.setSeriesPaint(0, Color.blue); xylineandshaperenderer1.setSeriesFillPaint(0, Color.blue); xylineandshaperenderer1.setSeriesOutlinePaint(0, Color.blue); xylineandshaperenderer1.setSeriesStroke(0, new BasicStroke(0.5F)); // ? XYDataset xydataset2 = TimeSeriesChart1.createNormalDataset(abnor, protocol2); /* XYTextAnnotation localXYTextAnnotation = new XYTextAnnotation("aa",10, Double.parseDouble(abnor.getElementAt(10).getData())); xyplot.addAnnotation(localXYTextAnnotation);*/ XYLineAndShapeRenderer xylineandshaperenderer2 = new XYLineAndShapeRenderer(); int datasetcount = xyplot.getDatasetCount(); xyplot.setDataset(datasetcount, xydataset2); xyplot.setRenderer(datasetcount, xylineandshaperenderer2); /* System.out.println("DatasetCount="+xyplot.getDatasetCount()); for(int c=0;c<xyplot.getDatasetCount();c++){ System.out.println("DatasetSeriesCount="+xyplot.getDataset(c).getSeriesCount()); System.out.println("Dataset["+c+"]="+xyplot.getDataset(c).getSeriesKey(0)); }*/ /* // ??? xylineandshaperenderer2.setBaseShapesVisible(false); // ?? xylineandshaperenderer2.setSeriesLinesVisible(0, true); xylineandshaperenderer2.setSeriesShape(0, double1); // xylineandshaperenderer2.setSeriesPaint(0, Color.green); xylineandshaperenderer2.setSeriesFillPaint(0, Color.green); xylineandshaperenderer2.setSeriesOutlinePaint(0, Color.green); xylineandshaperenderer2.setUseFillPaint(true); xylineandshaperenderer2 .setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); xylineandshaperenderer2.setSeriesStroke(0, new BasicStroke(0.5F)); */ xylineandshaperenderer2.setSeriesLinesVisible(0, true); xylineandshaperenderer2.setBaseShapesVisible(false); xylineandshaperenderer2.setSeriesShape(0, double1); xylineandshaperenderer2.setSeriesPaint(0, Color.GREEN); xylineandshaperenderer2.setSeriesFillPaint(0, Color.GREEN); xylineandshaperenderer2.setSeriesOutlinePaint(0, Color.green); xylineandshaperenderer2.setSeriesStroke(0, new BasicStroke(0.5F)); jfreechart.getLegend().setVisible(true); return jfreechart; }
From source file:com.leonarduk.finance.chart.CandlestickChart.java
public static void displayCandlestickChart(final Stock stock) throws IOException { final TimeSeries series = TimeseriesUtils.getTimeSeries(stock, 1); /**//from www. j a va 2s . com * Creating the OHLC dataset */ final OHLCDataset ohlcDataset = CandlestickChart.createOHLCDataset(series); /** * Creating the additional dataset */ final TimeSeriesCollection xyDataset = CandlestickChart.createAdditionalDataset(series); /** * Creating the chart */ final JFreeChart chart = ChartFactory.createCandlestickChart(stock.getName() + " price", "Time", stock.getCurrency(), ohlcDataset, true); // Candlestick rendering final CandlestickRenderer renderer = new CandlestickRenderer(); renderer.setAutoWidthMethod(CandlestickRenderer.WIDTHMETHOD_SMALLEST); final XYPlot plot = chart.getXYPlot(); plot.setRenderer(renderer); // Additional dataset final int index = 1; plot.setDataset(index, xyDataset); plot.mapDatasetToRangeAxis(index, 0); final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false); renderer2.setSeriesPaint(index, Color.blue); plot.setRenderer(index, renderer2); // Misc plot.setRangeGridlinePaint(Color.lightGray); plot.setBackgroundPaint(Color.white); final NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis(); numberAxis.setAutoRangeIncludesZero(false); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); /** * Displaying the chart */ ChartDisplay.displayChartInFrame(chart, 740, 300, "Candlestick Chart"); }
From source file:plugins.tutorial.chart.ChartTutorial2.java
/** * Creates a sample chart./*from w w w .j a v a2 s. c o m*/ * * @param dataset * the dataset. * @return The chart. */ private static JFreeChart createChart(XYDataset xydataset) { JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Projected Values - Test", "Date", "Index Projection", xydataset, true, true, false); jfreechart.setBackgroundPaint(Color.white); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setInsets(new RectangleInsets(5D, 5D, 5D, 20D)); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); DeviationRenderer deviationrenderer = new DeviationRenderer(true, false); deviationrenderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1)); deviationrenderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1)); deviationrenderer.setSeriesStroke(1, new BasicStroke(3F, 1, 1)); deviationrenderer.setSeriesFillPaint(0, new Color(255, 200, 200)); deviationrenderer.setSeriesFillPaint(1, new Color(200, 200, 255)); xyplot.setRenderer(deviationrenderer); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return jfreechart; }
From source file:control.JGeraGraficos.java
private static JFreeChart createGraficoXY(String title, String categoryAxisLabel, String valueAxisLabel, IntervalXYDataset dataset) {/*from ww w. j av a 2 s .co m*/ NumberAxis domainAxis = new NumberAxis(categoryAxisLabel); domainAxis.setAutoRangeIncludesZero(false); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); XYBarRenderer renderer = new ClusteredXYBarRenderer(); XYPlot plot = new XYPlot((XYDataset) dataset, domainAxis, valueAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); return chart; }
From source file:com.orsonpdf.demo.PDFBarChartDemo1.java
/** * Creates a sample chart./*from ww w. j a va2 s . com*/ * * @param dataset a dataset. * * @return The chart. */ private static JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createLineChart("Statistical Bar Chart Demo 1", "Type", "Value", dataset, PlotOrientation.VERTICAL, true, false, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); // customise the range axis... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(false); // customise the renderer... StatisticalBarRenderer renderer = new StatisticalBarRenderer(); renderer.setDrawBarOutline(false); renderer.setErrorIndicatorPaint(Color.black); renderer.setIncludeBaseInRange(false); plot.setRenderer(renderer); // ensure the current theme is applied to the renderer just added ChartUtilities.applyCurrentTheme(chart); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelPaint(Color.yellow); renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.INSIDE6, TextAnchor.BOTTOM_CENTER)); // set up gradient paints for series... GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); return chart; }