List of usage examples for org.jfree.chart.plot XYPlot setBackgroundPaint
public void setBackgroundPaint(Paint paint)
From source file:org.hxzon.demo.jfreechart.XYDatasetDemo2.java
private static JFreeChart createHistogramChart(XYDataset dataset) { NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); ValueAxis yAxis = new NumberAxis(yAxisLabel); XYItemRenderer renderer = new XYBarRenderer(); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); }//from www . ja va2s .c o m if (urls) { renderer.setURLGenerator(new StandardXYURLGenerator()); } XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(orientation); plot.setDomainZeroBaselineVisible(true); plot.setRangeZeroBaselineVisible(true); JFreeChart chart = new JFreeChart("Histogram Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); return chart; }
From source file:org.gwaspi.reports.GenericReportGenerator.java
private static void appendToCombinedRangeManhattanPlot(CombinedRangeXYPlot combinedPlot, String chromosome, XYSeriesCollection currChrSC, boolean showlables, double threshold, Color background, Color backgroundAlternative, Color main) { XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true); // Set dot shape of the currently appended Series renderer.setSeriesPaint(currChrSC.getSeriesCount() - 1, main); renderer.setSeriesVisibleInLegend(currChrSC.getSeriesCount() - 1, showlables); renderer.setSeriesShape(currChrSC.getSeriesCount() - 1, new Rectangle2D.Double(-1.0, -1.0, 2.0, 2.0)); // Set range axis if (combinedPlot.getSubplots().isEmpty()) { LogAxis rangeAxis = new LogAxis("P value"); rangeAxis.setBase(10);//from w w w .ja va 2 s .co m rangeAxis.setInverted(true); rangeAxis.setNumberFormatOverride(FORMAT_P_VALUE); rangeAxis.setTickMarkOutsideLength(2.0f); rangeAxis.setMinorTickCount(2); rangeAxis.setMinorTickMarksVisible(true); rangeAxis.setAxisLineVisible(true); rangeAxis.setUpperMargin(0); TickUnitSource units = NumberAxis.createIntegerTickUnits(); rangeAxis.setStandardTickUnits(units); combinedPlot.setRangeAxis(0, rangeAxis); } // Build subchart JFreeChart subchart = ChartFactory.createScatterPlot("", "Chr " + chromosome, "", currChrSC, PlotOrientation.VERTICAL, false, false, false); // Get subplot from subchart XYPlot subplot = (XYPlot) subchart.getPlot(); subplot.setRenderer(renderer); subplot.setBackgroundPaint(null); // CHART BACKGROUD COLOR if (combinedPlot.getSubplots().size() % 2 == 0) { subplot.setBackgroundPaint(background); // Hue, saturation, brightness } else { subplot.setBackgroundPaint(backgroundAlternative); // Hue, saturation, brightness } // Add significance Threshold to subplot final Marker thresholdLine = new ValueMarker(threshold); thresholdLine.setPaint(Color.red); // Add legend to hetzyThreshold if (showlables) { thresholdLine.setLabel("P = " + FORMAT_P_VALUE.format(threshold)); } thresholdLine.setLabelAnchor(RectangleAnchor.TOP_RIGHT); thresholdLine.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); subplot.addRangeMarker(thresholdLine); // Chromosome Axis Labels NumberAxis chrAxis = (NumberAxis) subplot.getDomainAxis(); chrAxis.setLabelAngle(1.0); chrAxis.setAutoRangeIncludesZero(false); chrAxis.setAxisLineVisible(true); chrAxis.setTickLabelsVisible(false); chrAxis.setTickMarksVisible(false); // chrAxis.setNumberFormatOverride(Report_Analysis.FORMAT_SCIENTIFIC); // TickUnitSource units = NumberAxis.createIntegerTickUnits(); // chrAxis.setStandardTickUnits(units); //combinedPlot.setGap(0); combinedPlot.add(subplot, 1); }
From source file:org.hxzon.demo.jfreechart.XYDatasetDemo2.java
private static JFreeChart createXYStepChart(XYDataset dataset) { DateAxis xAxis = new DateAxis(xAxisLabel); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYToolTipGenerator toolTipGenerator = null; if (tooltips) { toolTipGenerator = new StandardXYToolTipGenerator(); }//from w w w .j a v a 2 s. c o m XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } XYItemRenderer renderer = new XYStepRenderer(toolTipGenerator, urlGenerator); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); plot.setRenderer(renderer); plot.setOrientation(orientation); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); JFreeChart chart = new JFreeChart("XYStep Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); xAxis.setDateFormatOverride(new SimpleDateFormat("MM-yyyy")); return chart; }
From source file:org.hxzon.demo.jfreechart.XYDatasetDemo2.java
private static JFreeChart createXYStepAreaChart(XYDataset dataset) { NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); XYToolTipGenerator toolTipGenerator = null; if (tooltips) { toolTipGenerator = new StandardXYToolTipGenerator(); }// w w w . ja v a 2 s . c om XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } XYItemRenderer renderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA_AND_SHAPES, toolTipGenerator, urlGenerator); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); plot.setRenderer(renderer); plot.setOrientation(orientation); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); JFreeChart chart = new JFreeChart("XYStepArea Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); yAxis.setNumberFormatOverride(MyNumberFormat.getMyNumberFormat()); return chart; }
From source file:org.hxzon.demo.jfreechart.DatasetVisibleDemo2.java
private static JFreeChart createTimeSeriesChart(XYDataset dataset) { //DomainAxis// w w w . ja v a2 s.co m DateAxis timeAxis = new DateAxis(""); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02); timeAxis.setDateFormatOverride(new SimpleDateFormat("MM-yyyy")); //RangeAxis NumberAxis valueAxis = new NumberAxis(""); valueAxis.setAutoRangeIncludesZero(false); // override default // valueAxis.setDefaultAutoRange(new Range(100, 1150)); //Renderer XYToolTipGenerator toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance(); XYURLGenerator urlGenerator = null; // urlGenerator = new StandardXYURLGenerator(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); renderer.setBaseToolTipGenerator(toolTipGenerator); renderer.setURLGenerator(urlGenerator); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawSeriesLineAsPath(true); //AbstractRenderer.dataBoundsIncludesVisibleSeriesOnly renderer.setDataBoundsIncludesVisibleSeriesOnly(false); renderer.setBaseSeriesVisibleInLegend(true); //Plot XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null) { private static final long serialVersionUID = 1L; // public void rendererChanged(RendererChangeEvent event) { // // if the event was caused by a change to series visibility, then // // the axis ranges might need updating... // if (event.getSeriesVisibilityChanged()) { //// configureDomainAxes(); //// configureRangeAxes(); // } // fireChangeEvent(); // } }; plot.setRenderer(renderer); plot.setBackgroundPaint(plotBackgroundPaint); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); // plot.setRangePannable(true); //chart JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint(Color.white); valueAxis.setAutoRange(false); timeAxis.setAutoRange(false); return chart; }
From source file:org.ala.spatial.web.services.GDMWSController.java
public static void generateChart5(String outputdir, String plotName, String plotData) { try {/*from w w w .ja v a2 s . com*/ CSVReader csv = new CSVReader(new FileReader(plotData)); List<String[]> rawdata = csv.readAll(); double[][] dataCht = new double[2][rawdata.size() - 1]; for (int i = 1; i < rawdata.size(); i++) { String[] row = rawdata.get(i); dataCht[0][i - 1] = Double.parseDouble(row[0]); dataCht[1][i - 1] = Double.parseDouble(row[1]); } DefaultXYDataset dataset = new DefaultXYDataset(); dataset.addSeries("", dataCht); System.out.println("Setting up jChart for " + plotName); //generateChartByType(plotName, plotName, "f("+plotName+")", null, outputdir, "xyline", plotName); JFreeChart jChart = ChartFactory.createXYLineChart(plotName, plotName, "f(" + plotName + ")", dataset, PlotOrientation.VERTICAL, false, false, false); jChart.getTitle().setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14)); XYPlot plot = (XYPlot) jChart.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)); 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)); System.out.println("Writing image...."); ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/" + plotName + ".png"), jChart, 500, 500); ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/" + plotName + "_thumb.png"), jChart, 210, 140); } 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;/*ww w. ja va 2 s . c o 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.matsim.contrib.parking.parkingchoice.lib.GeneralLib.java
public static void generateXYScatterPlot(String fileName, double[] x, double[] y, String title, String xLabel, String yLabel) {//from ww w . j av a 2 s.c o m if (x.length != y.length) { DebugLib.stopSystemAndReportInconsistency("dimensions of arrays do not match"); } final XYSeries series1 = new XYSeries(title); for (int i = 0; i < x.length; i++) { series1.add(x[i], y[i]); } final XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series1); final JFreeChart chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShapesVisible(1, false); plot.setRenderer(renderer); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); int width = 500; int height = 300; try { ChartUtilities.saveChartAsPNG(new File(fileName), chart, width, height); } catch (IOException e) { } }
From source file:org.hxzon.demo.jfreechart.XYDatasetDemo2.java
private static JFreeChart createXYLineChart(XYDataset dataset) { NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(orientation);// www .j a v a 2 s.c om if (tooltips) { renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); } if (urls) { renderer.setURLGenerator(new StandardXYURLGenerator()); } JFreeChart chart = new JFreeChart("XYLine Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); yAxis.setNumberFormatOverride(MyNumberFormat.getMyNumberFormat()); return chart; }
From source file:ec.util.chart.swing.Charts.java
/** * A sparkline is a type of information graphic characterized by its small * size and high data density. Sparklines present trends and variations * associated with some measurement, such as average temperature or stock * market activity, in a simple and condensed way. Several sparklines are * often used together as elements of a small multiple.<br> * * {@link http://en.wikipedia.org/wiki/Sparkline} * * @param dataset/*w w w . ja va2 s . co m*/ * @return * @author Philippe Charles */ @Nonnull public static JFreeChart createSparkLineChart(@Nonnull XYDataset dataset) { JFreeChart result = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, false, false); result.setBorderVisible(false); result.setBackgroundPaint(null); result.setAntiAlias(true); XYPlot plot = result.getXYPlot(); plot.getRangeAxis().setVisible(false); plot.getDomainAxis().setVisible(false); plot.setDomainGridlinesVisible(false); plot.setDomainCrosshairVisible(false); plot.setRangeGridlinesVisible(false); plot.setRangeCrosshairVisible(false); plot.setOutlineVisible(false); plot.setInsets(RectangleInsets.ZERO_INSETS); plot.setAxisOffset(RectangleInsets.ZERO_INSETS); plot.setBackgroundPaint(null); ((XYLineAndShapeRenderer) plot.getRenderer()).setAutoPopulateSeriesPaint(false); return result; }