List of usage examples for org.jfree.chart JFreeChart getXYPlot
public XYPlot getXYPlot()
From source file:herbie.running.analysis.ModeSharesEventHandler.java
public JFreeChart getTraveledDistancesHistogram(final int numberOfBins) { String title = "Traveled distances distribution by mode"; String xLabel = "Distance (m)"; String yLabel = "Number of trips"; boolean legend = true; boolean tooltips = false; boolean urls = false; //XYSeriesCollection data = new XYSeriesCollection(); HistogramDataset data = getHistogramDataset(numberOfBins); double step = this.maxDistance / numberOfBins; //for (String mode : this.rawData.keySet()) { // data.addSeries(getTraveledDistancesHistogram(mode, step)); //}/* ww w. j a va2 s . c o m*/ JFreeChart chart = ChartFactory.createHistogram(title, xLabel, yLabel, data, PlotOrientation.VERTICAL, legend, tooltips, urls); chart.getXYPlot().setForegroundAlpha(0.5F); return chart; }
From source file:org.jfree.chart.demo.TimeSeriesDemo9.java
/** * A demonstration application showing how to create a simple time series chart. This * example uses monthly data.//from w ww . j av a 2 s .c o m * * @param title the frame title. */ public TimeSeriesDemo9(final String title) { super(title); // create a title... final String chartTitle = "Test"; final XYDataset dataset = createDataset(); final JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Date", "Price Per Unit", dataset, true, true, false); // final StandardLegend sl = (StandardLegend) chart.getLegend(); // sl.setDisplaySeriesShapes(true); final XYPlot plot = chart.getXYPlot(); final XYItemRenderer r = plot.getRenderer(); if (r instanceof StandardXYItemRenderer) { final StandardXYItemRenderer renderer = (StandardXYItemRenderer) r; renderer.setPlotShapes(true); renderer.setShapesFilled(true); renderer.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0)); renderer.setSeriesShape(1, new Rectangle2D.Double(-3.0, -3.0, 6.0, 6.0)); final GeneralPath s2 = new GeneralPath(); s2.moveTo(0.0f, -3.0f); s2.lineTo(3.0f, 3.0f); s2.lineTo(-3.0f, 3.0f); s2.closePath(); renderer.setSeriesShape(2, s2); final GeneralPath s3 = new GeneralPath(); s3.moveTo(-1.0f, -3.0f); s3.lineTo(1.0f, -3.0f); s3.lineTo(1.0f, -1.0f); s3.lineTo(3.0f, -1.0f); s3.lineTo(3.0f, 1.0f); s3.lineTo(1.0f, 1.0f); s3.lineTo(1.0f, 3.0f); s3.lineTo(-1.0f, 3.0f); s3.lineTo(-1.0f, 1.0f); s3.lineTo(-3.0f, 1.0f); s3.lineTo(-3.0f, -1.0f); s3.lineTo(-1.0f, -1.0f); s3.closePath(); renderer.setSeriesShape(3, s3); } plot.getDomainAxis().setVisible(false); plot.getRangeAxis().setVisible(false); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:org.yooreeka.util.gui.XyGui.java
public XyGui(String title, double[] x) { super(title); errMsg = new StringBuilder(); setLoopInt(x.length);/*from ww w . j a v a2s . c om*/ if (checkX(x)) { XYSeries xydata = new XYSeries(title); for (int i = 0; i < loopInt; i++) { xydata.add(x[i], C.ZERO_DOUBLE); } xycollection = new XYSeriesCollection(xydata); final JFreeChart chart = ChartFactory.createXYLineChart(title, "X", "Y", xycollection, PlotOrientation.VERTICAL, true, true, false); final XYPlot plot = chart.getXYPlot(); final NumberAxis domainAxis = new NumberAxis("x"); plot.setDomainAxis(domainAxis); final NumberAxis rangeAxis = new NumberAxis("y"); plot.setRangeAxis(rangeAxis); chart.setBackgroundPaint(Color.white); plot.setOutlinePaint(Color.black); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); } else { System.err.println(errMsg.toString()); } }
From source file:org.uncommons.watchmaker.swing.evolutionmonitor.JVMView.java
private JFreeChart createHeapChart(double maxMemory) { TimeSeriesCollection dataSet = new TimeSeriesCollection(); dataSet.addSeries(memoryUsageSeries); dataSet.addSeries(heapSizeSeries);/*from w w w. java 2 s. com*/ JFreeChart chart = ChartFactory.createXYAreaChart("JVM Heap", "Time", "Megabytes", dataSet, PlotOrientation.VERTICAL, true, // Legend. false, // Tooltips. false); DateAxis timeAxis = new DateAxis("Time"); timeAxis.setLowerMargin(0); timeAxis.setUpperMargin(0); chart.getXYPlot().setDomainAxis(timeAxis); chart.getXYPlot().getRangeAxis().setLowerBound(0); chart.getXYPlot().getRangeAxis().setUpperBound(maxMemory * 1.1); // Add 10% to leave room for marker. // Add a horizontal marker to indicate the heap growth limit. ValueMarker marker = new ValueMarker(maxMemory, Color.BLACK, new BasicStroke(1)); marker.setLabel("Maximum Permitted Heap Size (adjust with -Xmx)"); marker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); marker.setLabelAnchor(RectangleAnchor.RIGHT); chart.getXYPlot().addRangeMarker(marker); chart.getXYPlot().getRenderer().setSeriesPaint(0, Color.RED); chart.getXYPlot().getRenderer().setSeriesPaint(1, new Color(0, 128, 0, 128)); return chart; }
From source file:com.compomics.pepshell.view.statistics.CleavingProbabilityPane.java
@Override public void setGraphData(PepshellProtein aPepshellProtein) { //obligatory checks if (aPepshellProtein != null && experiment.getProteins().contains(aPepshellProtein)) { if (aPepshellProtein != currentPepshellProtein) { //TODO: run this outside of the gui thread currentPepshellProtein = experiment.getProteins() .get(experiment.getProteins().indexOf(aPepshellProtein)); XYSeriesCollection xYSeriesCollection = new XYSeriesCollection(); fillSeries(currentPepshellProtein).forEach(xYSeriesCollection::addSeries); JFreeChart CPDTchart = ChartFactory.createXYLineChart("probability of cleaving", "aminoacids of " + currentPepshellProtein.getVisibleAccession(), "probability", xYSeriesCollection, PlotOrientation.VERTICAL, false, true, false); prettifyChart(CPDTchart);/*from w w w. j ava2s .c o m*/ CPDTchart.getXYPlot().getRangeAxis().setLowerBound(cutoff - 0.05); for (int i = 0; i < CPDTchart.getXYPlot().getSeriesCount(); i++) { CPDTchart.getXYPlot().getRenderer().setSeriesStroke(i, new BasicStroke(5)); } if (!aPepshellProtein.getDomains().isEmpty()) { CPDTchart.setBackgroundImageAlpha(0.18f); CPDTchart.getXYPlot().getDomainAxis().setRange(0, aPepshellProtein.getProteinSequence().length()); BufferedImage anImage = new BufferedImage(this.getHeight(), this.getWidth(), BufferedImage.TYPE_INT_ARGB); for (FeatureWithLocation aDomain : aPepshellProtein.getDomains()) { anImage.getGraphics().drawRect(aDomain.getStartPosition(), 0, aDomain.getEndPosition(), this.getHeight()); } CPDTchart.setBackgroundImage(anImage); } chart.setChart(CPDTchart); } } else { chart.setChart(null); this.getGraphics().drawString("missing data", 0, 0); } }
From source file:org.jfree.chart.demo.LineChart.java
private JFreeChart createChart(final XYDataset dataset) { // create the chart... final JFreeChart chart = ChartFactory.createXYLineChart("Line Chart", // chart title "X", // x axis label "Y", // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls );// w w w . j av a2 s . co m 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()); return chart; }
From source file:org.yooreeka.util.gui.XyLogGui.java
public XyLogGui(String title, double[] x, double[] y) { super(title); errMsg = new StringBuilder(); setLoopInt(x.length);/*from w w w . j a v a2 s. c o m*/ if (checkX(x) && checkY(x.length, y)) { XYSeries xydata = new XYSeries(title); for (int i = 0; i < loopInt; i++) { if (x[i] == C.ZERO_DOUBLE || x[i] < 0) { x[i] = C.SMALL_DOUBLE; } if (y[i] == C.ZERO_DOUBLE || y[i] < 0) { y[i] = C.SMALL_DOUBLE; } xydata.add(x[i], y[i]); } xycollection = new XYSeriesCollection(xydata); final JFreeChart chart = ChartFactory.createXYLineChart(title + " (XY Plot)", "X", "Y", xycollection, PlotOrientation.VERTICAL, true, true, false); final XYPlot plot = chart.getXYPlot(); final NumberAxis domainAxis = new NumberAxis("x"); plot.setDomainAxis(domainAxis); final NumberAxis logRangeAxis = new LogarithmicAxis("Log(y)"); plot.setRangeAxis(logRangeAxis); chart.setBackgroundPaint(Color.white); plot.setOutlinePaint(Color.black); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); } else { System.err.println(errMsg.toString()); } }
From source file:com.trivadis.loganalysis.ui.ChartPanel.java
private JFreeChart createChart(final XYDataset dataset, final Composite parent, final IChart data, final String chartName, final String xAxisLabel, final String yAxisLabel) { final JFreeChart chart = ChartFactory.createXYLineChart(chartName, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); plot.setDomainGridlinePaint(Color.lightGray); final ChartComposite chartComposite = new ChartComposite(parent, SWT.NONE, chart, true); chartComposite.setLayoutData(new GridDataBuilder().fill().build()); return chart; }
From source file:ip.ui.plot.PlotGenerator.java
public void generateResultsChart(ResultsPlotData data, String fileName) throws IOException { XYSeries expectedData = new XYSeries("Expected output"); XYSeries networkData = new XYSeries("Network output"); List<double[]> inputs = new ArrayList(data.getInputs().size()); data.getInputs().stream().forEach((InputRow row) -> { inputs.add(row.getValues());/* w w w . ja v a 2 s . c om*/ }); List<double[]> expectedOutputs = new ArrayList(data.getInputs().size()); data.getInputs().stream().forEach((InputRow row) -> { expectedOutputs.add(row.getExpectedOutput()); }); List<double[]> outputs = data.getOutputs(); for (int i = 0; i < inputs.size(); ++i) { expectedData.add(inputs.get(i)[0], expectedOutputs.get(i)[0]); networkData.add(inputs.get(i)[0], outputs.get(i)[0]); } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(expectedData); dataset.addSeries(networkData); JFreeChart chart = ChartFactory.createXYLineChart(data.getPlotName(), data.getxAxisLabel(), data.getyAxisLabel(), dataset, PlotOrientation.VERTICAL, true, true, true); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesLinesVisible(1, false); chart.getXYPlot().setRenderer(renderer); File XYChart = new File(fileName); ChartUtilities.saveChartAsJPEG(XYChart, chart, chartWidth, chartHeight); }
From source file:DualAxisDemo2.java
/** * A demonstration application showing how to create a time series chart with dual axes. * * @param title the frame title./*from w w w . j av a 2 s. c om*/ */ public DualAxisDemo2(final String title) { super(title); // create a title... final String chartTitle = "Dual Axis Demo 2"; final XYDataset dataset = createDataset1(); final JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Date", "Price Per Unit", dataset, true, true, false); // final StandardLegend legend = (StandardLegend) chart.getLegend(); // legend.setDisplaySeriesShapes(true); final XYPlot plot = chart.getXYPlot(); final NumberAxis axis2 = new NumberAxis("Secondary"); axis2.setAutoRangeIncludesZero(false); plot.setRangeAxis(1, axis2); plot.setDataset(1, createDataset2()); plot.mapDatasetToRangeAxis(1, 1); final XYItemRenderer renderer = plot.getRenderer(); renderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); if (renderer instanceof StandardXYItemRenderer) { final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer; // rr.setPlotShapes(true); rr.setShapesFilled(true); } final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer(); renderer2.setSeriesPaint(0, Color.black); // renderer2.setPlotShapes(true); renderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); plot.setRenderer(1, renderer2); final DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }