List of usage examples for org.jfree.chart.axis NumberAxis setAutoRangeIncludesZero
public void setAutoRangeIncludesZero(boolean flag)
From source file:org.ala.spatial.web.services.GDMWSController.java
public static void generateCharts123(String outputdir) { try {//from w w w . j a v a2s .c o m IniReader ir = new IniReader(outputdir + "/gdm_params.txt"); double intercept = ir.getDoubleValue("GDMODEL", "Intercept"); // 1. read the ObservedVsPredicted.csv file System.out.println("Loading csv data"); CSVReader csv = new CSVReader(new FileReader(outputdir + "ObservedVsPredicted.csv")); List<String[]> rawdata = csv.readAll(); double[][] dataCht1 = new double[2][rawdata.size() - 1]; double[][] dataCht2 = new double[2][rawdata.size() - 1]; // for Chart 1: obs count int[] obscount = new int[11]; for (int i = 0; i < obscount.length; i++) { obscount[i] = 0; } System.out.println("populating data"); for (int i = 1; i < rawdata.size(); i++) { String[] row = rawdata.get(i); double obs = Double.parseDouble(row[4]); dataCht1[0][i - 1] = Double.parseDouble(row[6]); dataCht1[1][i - 1] = obs; dataCht2[0][i - 1] = Double.parseDouble(row[5]) - intercept; dataCht2[1][i - 1] = obs; int obc = (int) Math.round(obs * 10); obscount[obc]++; } DefaultXYDataset dataset1 = new DefaultXYDataset(); dataset1.addSeries("", dataCht1); DefaultXYDataset dataset2 = new DefaultXYDataset(); dataset2.addSeries("", dataCht2); DefaultCategoryDataset dataset3 = new DefaultCategoryDataset(); for (int i = 0; i < obscount.length; i++) { String col = "0." + i + "-0." + (i + 1); if (i == 10) { col = "0.9-1.0"; } dataset3.addValue(obscount[i] + 100, "col", col); } generateChartByType("Response Histogram", "Observed Dissimilarity Class", "Number of Site Pairs", dataset3, outputdir, "bar", "resphist"); XYDotRenderer renderer = new XYDotRenderer(); //Shape cross = ShapeUtilities.createDiagonalCross(3, 1); //renderer.setSeriesShape(0, cross); renderer.setDotWidth(3); renderer.setDotHeight(3); renderer.setSeriesPaint(0, Color.BLACK); JFreeChart jChart1 = ChartFactory.createScatterPlot( "Observed versus predicted compositional dissimilarity", "Predicted Compositional Dissimilarity", "Observed Compositional Dissimilarity", dataset1, PlotOrientation.VERTICAL, false, false, false); jChart1.getTitle().setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14)); XYPlot plot = (XYPlot) jChart1.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainZeroBaselineVisible(true); plot.setRangeZeroBaselineVisible(true); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlineStroke(new BasicStroke(0.5F, 0, 1)); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1)); plot.setRenderer(0, renderer); NumberAxis domain = (NumberAxis) plot.getDomainAxis(); domain.setAutoRangeIncludesZero(false); domain.setAxisLineVisible(false); domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); NumberAxis range = (NumberAxis) plot.getRangeAxis(); range.setAutoRangeIncludesZero(false); range.setAxisLineVisible(false); range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); double dMinPred = domain.getRange().getLowerBound(); double dMaxPred = domain.getRange().getUpperBound(); double dMinObs = range.getRange().getLowerBound(); double dMaxObs = range.getRange().getUpperBound(); System.out.println("1..pred.min.max: " + dMinPred + ", " + dMaxPred); int regressionLineSegs = 10; double dInc = (dMaxPred - dMinPred) / regressionLineSegs; double[][] dataReg1 = new double[2][regressionLineSegs + 1]; DefaultXYDataset dsReg1 = new DefaultXYDataset(); int i = 0; for (double d = dMinPred; d <= dMaxPred; d += dInc, i++) { dataReg1[0][i] = d; dataReg1[1][i] = d; } dsReg1.addSeries("", dataReg1); XYSplineRenderer regressionRenderer = new XYSplineRenderer(); regressionRenderer.setBaseSeriesVisibleInLegend(true); regressionRenderer.setSeriesPaint(0, Color.RED); regressionRenderer.setSeriesStroke(0, new BasicStroke(1.5f)); regressionRenderer.setBaseShapesVisible(false); plot.setDataset(1, dsReg1); plot.setRenderer(1, regressionRenderer); System.out.println("Writing image...."); ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/obspredissim.png"), jChart1, 600, 400); // For chart 3 JFreeChart jChart2 = ChartFactory.createScatterPlot( "Observed compositional dissimilarity vs predicted ecological distance", "Predicted ecological distance", "Observed Compositional Dissimilarity", dataset2, PlotOrientation.VERTICAL, false, false, false); jChart2.getTitle().setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14)); plot = (XYPlot) jChart2.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainZeroBaselineVisible(true); plot.setRangeZeroBaselineVisible(true); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlineStroke(new BasicStroke(0.5F, 0, 1)); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1)); plot.setRenderer(0, renderer); domain = (NumberAxis) plot.getDomainAxis(); domain.setAutoRangeIncludesZero(false); domain.setAxisLineVisible(false); domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); range = (NumberAxis) plot.getRangeAxis(); range.setAutoRangeIncludesZero(false); range.setAxisLineVisible(false); range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); dMinPred = domain.getRange().getLowerBound(); dMaxPred = domain.getRange().getUpperBound(); dMinObs = range.getRange().getLowerBound(); dMaxObs = range.getRange().getUpperBound(); System.out.println("2.pred.min.max: " + dMinPred + ", " + dMaxPred); regressionLineSegs = 10; dInc = (dMaxPred - dMinPred) / regressionLineSegs; dataReg1 = new double[2][regressionLineSegs + 1]; dsReg1 = new DefaultXYDataset(); i = 0; for (double d = dMinPred; d <= dMaxPred; d += dInc, i++) { dataReg1[0][i] = d; dataReg1[1][i] = (1.0 - Math.exp(-d)); } dsReg1.addSeries("", dataReg1); regressionRenderer.setBaseSeriesVisibleInLegend(true); regressionRenderer.setSeriesPaint(0, Color.RED); regressionRenderer.setSeriesStroke(0, new BasicStroke(1.5f)); regressionRenderer.setBaseShapesVisible(false); plot.setDataset(1, dsReg1); plot.setRenderer(1, regressionRenderer); System.out.println("Writing image...."); ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/dissimdist.png"), jChart2, 600, 400); } catch (Exception e) { System.out.println("Unable to generate charts 2 and 3:"); e.printStackTrace(System.out); } }
From source file:org.ala.spatial.web.services.GDMWSController.java
public static void generateChartByType(String title, String xLabel, String yLabel, Dataset dataset, String outputdir, String type, String filename) throws IOException { JFreeChart jChart = null;/*from ww w . j a va 2s . co m*/ if ("line".equalsIgnoreCase(type)) { jChart = ChartFactory.createLineChart(title, xLabel, yLabel, (CategoryDataset) dataset, PlotOrientation.VERTICAL, false, false, false); } else if ("bar".equalsIgnoreCase(type)) { System.out.println("Setting up jChart"); jChart = ChartFactory.createBarChart(title, xLabel, yLabel, (CategoryDataset) dataset, PlotOrientation.VERTICAL, false, false, false); System.out.println("Writing image...."); } else if ("xyline".equalsIgnoreCase(type)) { jChart = ChartFactory.createXYLineChart(title, xLabel, yLabel, (XYDataset) dataset, PlotOrientation.VERTICAL, false, false, false); } if ("xyline".equalsIgnoreCase(type)) { XYPlot plot = (XYPlot) jChart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setRangeZeroBaselineVisible(true); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1)); NumberAxis domain = (NumberAxis) plot.getDomainAxis(); domain.setAxisLineVisible(false); domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); domain.setAutoRangeIncludesZero(false); NumberAxis range = (NumberAxis) plot.getRangeAxis(); range.setAutoRangeIncludesZero(false); range.setAxisLineVisible(false); range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); //System.out.println("dataset.getColumnCount(): " + dataset.getColumnCount()); //System.out.println("dataset.getRowCount(): " + dataset.getRowCount()); } else { CategoryPlot plot = (CategoryPlot) jChart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setRangeZeroBaselineVisible(true); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1)); CategoryAxis domain = (CategoryAxis) plot.getDomainAxis(); domain.setAxisLineVisible(false); domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); NumberAxis range = (NumberAxis) plot.getRangeAxis(); range.setAutoRangeIncludesZero(false); range.setAxisLineVisible(false); range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); //System.out.println("dataset.getColumnCount(): " + dataset.getColumnCount()); //System.out.println("dataset.getRowCount(): " + dataset.getRowCount()); } jChart.getTitle().setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14)); ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/" + filename + ".png"), jChart, 900, 500); }
From source file:org.jfree.chart.demo.ScatterPlotDemo4.java
/** * A demonstration application showing a scatter plot. * * @param title the frame title./*from w ww . j a v a2 s . c o m*/ */ public ScatterPlotDemo4(final String title) { super(title); final XYDataset data = new SampleXYDataset2(); final JFreeChart chart = ChartFactory.createScatterPlot("Scatter Plot Demo", "X", "Y", data, PlotOrientation.VERTICAL, true, true, false); final XYPlot plot = chart.getXYPlot(); plot.setRenderer(new XYDotRenderer()); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRangeIncludesZero(false); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:org.jfree.chart.demo.ScatterPlotDemo.java
/** * A demonstration application showing a scatter plot. * /* w ww .ja v a2s .com*/ * @param title * the frame title. */ public ScatterPlotDemo(final String title) { super(title); final XYDataset data = new SampleXYDataset2(); final JFreeChart chart = ChartFactory.createScatterPlot("Scatter Plot Demo", "X", "Y", data, PlotOrientation.VERTICAL, true, true, false); final Legend legend = chart.getLegend(); if (legend instanceof StandardLegend) { final StandardLegend sl = (StandardLegend) legend; sl.setDisplaySeriesShapes(true); } XYPlot plot = (XYPlot) chart.getPlot(); plot.setNoDataMessage("NO DATA"); final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRangeIncludesZero(false); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); chartPanel.setVerticalAxisTrace(true); chartPanel.setHorizontalAxisTrace(true); chartPanel.setVerticalZoom(true); chartPanel.setHorizontalZoom(true); setContentPane(chartPanel); }
From source file:scatterplot1k.JFreeScatter.java
/** * Creates a new fast scatter plot demo. * * @param title the frame title.//from w w w . j ava 2 s .c om * @param sampleSize */ public JFreeScatter(final String title, int sampleSize) { super(title); this.sampleCount = sampleSize; data = new float[2][sampleSize]; populateData(); final NumberAxis domainAxis = new NumberAxis("X"); domainAxis.setAutoRangeIncludesZero(false); final NumberAxis rangeAxis = new NumberAxis("Y"); rangeAxis.setAutoRangeIncludesZero(false); final FastScatterPlot plot = new FastScatterPlot(this.data, domainAxis, rangeAxis); final JFreeChart chart = new JFreeChart("Fast Scatter Plot", plot); // chart.setLegend(null); // force aliasing of the rendered content.. chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); final ChartPanel panel = new ChartPanel(chart, true); panel.setPreferredSize(new java.awt.Dimension(800, 600)); // panel.setHorizontalZoom(true); // panel.setVerticalZoom(true); panel.setMinimumDrawHeight(10); panel.setMaximumDrawHeight(2000); panel.setMinimumDrawWidth(20); panel.setMaximumDrawWidth(2000); setContentPane(panel); }
From source file:com.xpn.xwiki.plugin.charts.plots.TimePlotFactory.java
public Plot create(DataSource dataSource, ChartParams params) throws GenerateException, DataSourceException { Class rendererClass = params.getClass(ChartParams.RENDERER); XYItemRenderer renderer;//from w w w .j ava 2s . co m if (rendererClass != null) { try { Constructor ctor = rendererClass.getConstructor(new Class[] {}); renderer = (XYItemRenderer) ctor.newInstance(new Object[] {}); } catch (Throwable e) { throw new GenerateException(e); } } else { renderer = new XYLineAndShapeRenderer(); } ChartCustomizer.customizeXYItemRenderer(renderer, params); DateAxis domainAxis = new DateAxis(); ChartCustomizer.customizeDateAxis(domainAxis, params, ChartParams.AXIS_DOMAIN_PREFIX); NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setAutoRangeIncludesZero(false); // override default ChartCustomizer.customizeNumberAxis(rangeAxis, params, ChartParams.AXIS_RANGE_PREFIX); XYDataset dataset = TimeSeriesCollectionFactory.getInstance().create(dataSource, params); XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); ChartCustomizer.customizeXYPlot(plot, params); return plot; }
From source file:org.jfree.chart.demo.XYSeriesDemo2.java
/** * A demonstration application showing an {@link XYSeries} where all the y-values are the same. * * @param title the frame title.//from w w w . jav a 2s .c o m */ public XYSeriesDemo2(final String title) { super(title); final XYSeries series = new XYSeries("Flat Data"); series.add(1.0, 100.0); series.add(5.0, 100.0); series.add(4.0, 100.0); series.add(12.5, 100.0); series.add(17.3, 100.0); series.add(21.2, 100.0); series.add(21.9, 100.0); series.add(25.6, 100.0); series.add(30.0, 100.0); final XYSeriesCollection data = new XYSeriesCollection(series); final JFreeChart chart = ChartFactory.createXYLineChart("XY Series Demo 2", "X", "Y", data, PlotOrientation.VERTICAL, true, true, false); final XYPlot plot = (XYPlot) chart.getPlot(); final NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setAutoRangeIncludesZero(false); axis.setAutoRangeMinimumSize(1.0); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:org.jfree.chart.demo.ScatterPlotDemo2.java
/** * Creates a chart.//www . j av a2 s. c om * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final XYDataset dataset) { final JFreeChart chart = ChartFactory.createScatterPlot("Scatter Plot Demo", "X", "Y", dataset, PlotOrientation.HORIZONTAL, true, // legend false, // tooltips false // urls ); final XYPlot plot = chart.getXYPlot(); plot.setRenderer(new XYDotRenderer()); final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRangeIncludesZero(false); return chart; }
From source file:info.debatty.java.datasets.examples.GaussianMixtureBuilder.java
/** * Creates a new fast scatter plot demo. * * @param title the frame title./*from w w w .jav a2s .c om*/ */ FastScatterPlot2D(final String title, final float[][] data) { super(title); final NumberAxis x_axis = new NumberAxis("X"); x_axis.setAutoRangeIncludesZero(false); final NumberAxis y_axis = new NumberAxis("Y"); y_axis.setAutoRangeIncludesZero(false); final FastScatterPlot plot = new FastScatterPlot(data, x_axis, y_axis); final JFreeChart chart = new JFreeChart(title, plot); // force aliasing of the rendered content.. chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); final ChartPanel panel = new ChartPanel(chart, true); panel.setPreferredSize(new java.awt.Dimension(1024, 768)); setContentPane(panel); }
From source file:org.operamasks.faces.render.graph.CurveAreaChartRenderer.java
private JFreeChart createCurveAreaChart(CategoryDataset dataset, PlotOrientation orientation) { CategoryAxis xAxis = new CategoryAxis(); xAxis.setLowerMargin(0.0);/*w w w . ja v a2 s . c o m*/ xAxis.setUpperMargin(0.0); xAxis.setCategoryMargin(0.0); NumberAxis yAxis = new NumberAxis(); yAxis.setAutoRangeIncludesZero(false); CurveAndShapeRenderer renderer = new CurveAndShapeRenderer(true, false); renderer.setDrawArea(true); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(orientation); if (dataset.getRowCount() > 1) { plot.setForegroundAlpha(0.75f); } return new JFreeChart(null, null, plot, false); }