List of usage examples for org.jfree.data.xy XYSeriesCollection addSeries
public void addSeries(XYSeries series)
From source file:utils.ChartUtils.java
/** * Update XY chart// www . j a va 2s. c o m * * @param plot ChartPanel Plot * @param sortedArray Sorted array of values */ public static void updateXYChart(ChartPanel plot, double[] sortedArray) { XYPlot xyplot = plot.getChart().getXYPlot(); double min = sortedArray[0]; double max = sortedArray[sortedArray.length - 1]; double median = Utils.getMedian(sortedArray); double q1 = Utils.getQ1(sortedArray); double q3 = Utils.getQ3(sortedArray); XYTextAnnotation annotation; //min-lowlimit horizontal XYSeries serie15 = new XYSeries("15"); serie15.add(min, 0.5); //max-toplimit horizontal XYSeries serie16 = new XYSeries("16"); serie16.add(max, 0.5); //min vertical XYSeries serie1 = new XYSeries("0"); serie1.add(min, 0.45); serie1.add(min, 0.55); annotation = new XYTextAnnotation("Min", min, 0.40); annotation.setFont(new Font("SansSerif", Font.PLAIN, 11)); xyplot.addAnnotation(annotation); //min-q1 horizontal XYSeries serie2 = new XYSeries("1"); serie2.add(min, 0.5); serie2.add(q1, 0.5); //q1 vertical XYSeries serie3 = new XYSeries("2"); serie3.add(q1, 0.1); serie3.add(q1, 0.9); annotation = new XYTextAnnotation("Q1", q1, 0.08); annotation.setFont(new Font("SansSerif", Font.PLAIN, 11)); xyplot.addAnnotation(annotation); // median XYSeries serie_mediana = new XYSeries("11"); serie_mediana.add(median, 0.1); serie_mediana.add(median, 0.9); annotation = new XYTextAnnotation("Median", median, 0.04); annotation.setFont(new Font("SansSerif", Font.PLAIN, 11)); xyplot.addAnnotation(annotation); //q1-q3 horizontal sup XYSeries serie4 = new XYSeries("3"); serie4.add(q1, 0.9); serie4.add(q3, 0.9); //q1-q3 horizontal inf XYSeries serie5 = new XYSeries("4"); serie5.add(q1, 0.1); serie5.add(q3, 0.1); //q3 vertical XYSeries serie6 = new XYSeries("5"); serie6.add(q3, 0.1); serie6.add(q3, 0.9); annotation = new XYTextAnnotation("Q3", q3, 0.08); annotation.setFont(new Font("SansSerif", Font.PLAIN, 11)); xyplot.addAnnotation(annotation); //q3-max horizontal XYSeries serie7 = new XYSeries("6"); serie7.add(q3, 0.5); serie7.add(max, 0.5); //max vertical XYSeries serie8 = new XYSeries("7"); serie8.add(max, 0.45); serie8.add(max, 0.55); annotation = new XYTextAnnotation("Max", max, 0.4); annotation.setFont(new Font("SansSerif", Font.PLAIN, 11)); xyplot.addAnnotation(annotation); XYSeriesCollection xyseriescollection = new XYSeriesCollection(); xyseriescollection.addSeries(serie1); xyseriescollection.addSeries(serie2); xyseriescollection.addSeries(serie3); xyseriescollection.addSeries(serie4); xyseriescollection.addSeries(serie5); xyseriescollection.addSeries(serie6); xyseriescollection.addSeries(serie7); xyseriescollection.addSeries(serie8); xyseriescollection.addSeries(serie15); xyseriescollection.addSeries(serie16); xyseriescollection.addSeries(serie_mediana); xyplot.getRenderer().setSeriesPaint(9, Color.black); xyplot.getRenderer().setSeriesPaint(10, Color.black); xyplot.getRenderer().setSeriesPaint(0, Color.black); xyplot.getRenderer().setSeriesPaint(1, Color.black); xyplot.getRenderer().setSeriesPaint(2, Color.black); xyplot.getRenderer().setSeriesPaint(3, Color.black); xyplot.getRenderer().setSeriesPaint(4, Color.black); xyplot.getRenderer().setSeriesPaint(5, Color.black); xyplot.getRenderer().setSeriesPaint(6, Color.black); xyplot.getRenderer().setSeriesPaint(7, Color.black); xyplot.getRenderer().setSeriesPaint(8, Color.black); xyplot.getRenderer().setSeriesPaint(9, Color.black); xyplot.getRenderer().setSeriesPaint(10, Color.black); xyplot.getRenderer().setSeriesPaint(11, Color.black); xyplot.getRenderer().setSeriesPaint(12, Color.black); xyplot.getRenderer().setSeriesPaint(13, Color.black); //add dataset xyplot.setDataset(xyseriescollection); // add a second dataset and renderer... XYSeriesCollection anotherserie = new XYSeriesCollection(); XYSeries serie_point = new XYSeries("21"); double[] yValue = { 0.47, 0.49, 0.51, 0.53 }; for (int i = 0, j = 0; i < sortedArray.length; i++, j++) { if (j % 4 == 0) { j = 0; } serie_point.add(sortedArray[i], yValue[j]); } anotherserie.addSeries(serie_point); XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer(false, true); renderer1.setSeriesPaint(0, Color.lightGray); xyplot.setDataset(1, anotherserie); xyplot.setRenderer(1, renderer1); }
From source file:org.jfree.chart.demo.XYSplineRendererDemo1a.java
private static XYDataset createSampleData() { XYSeries xyseries = new XYSeries("Series 1"); xyseries.add(2D, 56.270000000000003D); xyseries.add(3D, 41.32D);//from w w w .jav a 2 s. c om xyseries.add(4D, 31.449999999999999D); xyseries.add(5D, 30.050000000000001D); xyseries.add(6D, 24.690000000000001D); xyseries.add(7D, 19.780000000000001D); xyseries.add(8D, 20.940000000000001D); xyseries.add(9D, 16.73D); xyseries.add(10D, 14.210000000000001D); xyseries.add(11D, 12.44D); XYSeriesCollection xyseriescollection = new XYSeriesCollection(xyseries); XYSeries xyseries1 = new XYSeries("Series 2"); xyseries1.add(11D, 56.270000000000003D); xyseries1.add(10D, 41.32D); xyseries1.add(9D, 31.449999999999999D); xyseries1.add(8D, 30.050000000000001D); xyseries1.add(7D, 24.690000000000001D); xyseries1.add(6D, 19.780000000000001D); xyseries1.add(5D, 20.940000000000001D); xyseries1.add(4D, 16.73D); xyseries1.add(3D, 14.210000000000001D); xyseries1.add(2D, 12.44D); xyseriescollection.addSeries(xyseries1); return xyseriescollection; }
From source file:de.cebitec.readXplorer.plotting.CreatePlots.java
public synchronized static ChartPanel createPlot(Map<PersistentFeature, Pair<Double, Double>> data, String xName, String yName, XYToolTipGenerator toolTip) { XYSeriesCollection normal = new XYSeriesCollection(); XYSeries nor = new XYSeries("Normal"); for (Iterator<PersistentFeature> it = data.keySet().iterator(); it.hasNext();) { PersistentFeature key = it.next(); Pair<Double, Double> pair = data.get(key); Double X = pair.getFirst(); Double Y = pair.getSecond(); nor.add(new PlotDataItem(key, X, Y)); }// w w w .ja va2 s . c om normal.addSeries(nor); // create subplot 1... final XYItemRenderer renderer1 = new XYShapeRenderer(); renderer1.setBaseToolTipGenerator(toolTip); final NumberAxis domainAxis1 = new NumberAxis(xName); final NumberAxis rangeAxis1 = new NumberAxis(yName); final XYPlot subplot1 = new XYPlot(normal, domainAxis1, rangeAxis1, renderer1); JFreeChart chart = new JFreeChart(subplot1); chart.removeLegend(); ChartPanel panel = new ChartPanel(chart, true, false, true, true, true); panel.setInitialDelay(0); panel.setMaximumDrawHeight(1080); panel.setMaximumDrawWidth(1920); panel.setMouseWheelEnabled(true); panel.setMouseZoomable(true); MouseActions mouseAction = new MouseActions(); panel.addChartMouseListener(mouseAction); ChartPanelOverlay overlay = new ChartPanelOverlay(mouseAction); panel.addOverlay(overlay); return panel; }
From source file:org.deeplearning4j.examples.dataexamples.CSVPlotter.java
/** * Generate an xy plot of the datasets provided. *///from w w w . jav a 2 s.c o m private static void plotDataset(ArrayList<DataSet> DataSetList) { XYSeriesCollection c = new XYSeriesCollection(); int dscounter = 1; //use to name the dataseries for (DataSet ds : DataSetList) { INDArray features = ds.getFeatures(); INDArray outputs = ds.getLabels(); int nRows = features.rows(); XYSeries series = new XYSeries("S" + dscounter); for (int i = 0; i < nRows; i++) { series.add(features.getDouble(i), outputs.getDouble(i)); } c.addSeries(series); } String title = "title"; String xAxisLabel = "xAxisLabel"; String yAxisLabel = "yAxisLabel"; PlotOrientation orientation = PlotOrientation.VERTICAL; boolean legend = false; boolean tooltips = false; boolean urls = false; JFreeChart chart = ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, c, orientation, legend, tooltips, urls); JPanel panel = new ChartPanel(chart); JFrame f = new JFrame(); f.add(panel); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); f.pack(); f.setTitle("Training Data"); f.setVisible(true); }
From source file:org.efs.openreports.engine.ChartReportEngine.java
private static XYDataset createXYDataset(ChartValue[] values) { XYSeries series = null;//from w w w . j a va2 s .com XYSeriesCollection seriesCollection = new XYSeriesCollection(); for (int i = 0; i < values.length; i++) { XYChartValue value = (XYChartValue) values[i]; if (series == null || !series.getKey().equals(value.getSeries())) { if (series != null) { seriesCollection.addSeries(series); } series = new XYSeries(value.getSeries()); } series.add(value.getValue(), value.getSecondValue()); } seriesCollection.addSeries(series); return seriesCollection; }
From source file:org.micromanager.CRISP.CRISPFrame.java
/** * Create a frame with a plot of the data given in XYSeries *//*from w w w.j av a 2s . c o m*/ public static void plotData(String title, XYSeries data, String xTitle, String yTitle, int xLocation, int yLocation) { // JFreeChart code XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(data); JFreeChart chart = ChartFactory.createScatterPlot(title, // Title xTitle, // x-axis Label yTitle, // y-axis Label dataset, // Dataset PlotOrientation.VERTICAL, // Plot Orientation false, // Show Legend true, // Use tooltips false // Configure chart to generate URLs? ); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setSeriesPaint(0, Color.black); renderer.setSeriesFillPaint(0, Color.white); renderer.setSeriesLinesVisible(0, true); Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 4.0f, 4.0f); renderer.setSeriesShape(0, circle, false); renderer.setUseFillPaint(true); ChartFrame graphFrame = new ChartFrame(title, chart); graphFrame.getChartPanel().setMouseWheelEnabled(true); graphFrame.pack(); graphFrame.setLocation(xLocation, yLocation); graphFrame.setVisible(true); }
From source file:playground.johannes.socialnets.GraphStatistics.java
public static JFreeChart makeChart(Histogram1D hist, String title) { final XYSeriesCollection data = new XYSeriesCollection(); final XYSeries wave = new XYSeries(title, false, true); for (int i = 0; i < 100; i++) { wave.add(hist.xAxis().binCentre(i), hist.binHeight(i)); }//from w w w . j a va2 s. c om data.addSeries(wave); final JFreeChart chart = ChartFactory.createXYStepChart("title", "x", "y", data, PlotOrientation.VERTICAL, true, // legend false, // tooltips false // urls ); XYPlot plot = chart.getXYPlot(); final CategoryAxis axis1 = new CategoryAxis("x"); axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7)); plot.setDomainAxis(new NumberAxis("y")); return chart; }
From source file:com.comcast.cmb.test.tools.QueueDepthSimulator.java
public static void plotLineChart(Map<String, List<Double>> series, String filename, String title, String labelX, String labelY) throws IOException { XYSeriesCollection dataset = new XYSeriesCollection(); for (String label : series.keySet()) { XYSeries data = new XYSeries(label); int t = 0; for (Double d : series.get(label)) { data.add(t, d);/*from ww w .jav a 2s . c om*/ t++; } dataset.addSeries(data); } JFreeChart chart = ChartFactory.createXYLineChart(title, labelX, labelY, dataset, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = chart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, true); plot.setRenderer(renderer); ChartUtilities.saveChartAsPNG(new File(filename), chart, 1024, 768); }
From source file:com.comcast.cmb.test.tools.QueueDepthSimulator.java
public static void scatterPlot(Map<String, List<Double>> datasets, String filename, String title, String labelX, String labelY) throws IOException { XYSeriesCollection dataset = new XYSeriesCollection(); for (String label : datasets.keySet()) { XYSeries data = new XYSeries(label); int cnt = 0; for (Double d : datasets.get(label)) { data.add(cnt, d);/* www . j a v a 2 s .c om*/ cnt++; } dataset.addSeries(data); } JFreeChart chart = ChartFactory.createScatterPlot(title, labelX, labelY, dataset, PlotOrientation.VERTICAL, true, true, false); ChartUtilities.saveChartAsPNG(new File(filename), chart, 1024, 768); }
From source file:de.bfs.radon.omsimulation.gui.data.OMCharts.java
/** * Creates a chart displaying the distribution of certain selected statistical * values. Uses red for normal rooms and blue for cellar rooms. * /*from w w w .j av a 2s . c o m*/ * @param title * The headline of the chart. Will be hidden if set to null. * @param statistics * The selected statistics of a campaign containing all needed * values. * @param roomType * The room type to determine the colour of the chart. * @param preview * Will hide annotations, labels and headlines if true. * @return A chart displaying the distribution of certain selected statistical * values. */ public static JFreeChart createDistributionChart(String title, DescriptiveStatistics statistics, OMRoomType roomType, boolean preview) { Color lineColor = new Color(0, 0, 0, 128); Color rangeColor = new Color(222, 222, 222, 128); if (roomType == OMRoomType.Room) { lineColor = new Color(255, 0, 0, 128); rangeColor = new Color(255, 222, 222, 128); } else { if (roomType == OMRoomType.Cellar) { lineColor = new Color(0, 0, 255, 128); rangeColor = new Color(222, 222, 255, 128); } else { lineColor = new Color(0, 128, 0, 255); rangeColor = new Color(222, 255, 222, 128); } } double[] distValues = statistics.getSortedValues(); XYSeriesCollection dataSet = new XYSeriesCollection(); XYSeries distSeries = new XYSeries("Distribution"); for (int i = 0; i < distValues.length; i++) { distSeries.add(distValues[i], (0.5 + (double) i) / (double) distValues.length); } dataSet.addSeries(distSeries); JFreeChart chart = ChartFactory.createXYLineChart(title, "Rn [Bq/m\u00B3]", "F(emp)", dataSet, PlotOrientation.VERTICAL, false, true, false); XYPlot plot = (XYPlot) chart.getPlot(); float[] dash = { 5, 3 }; int pos = 0; double y = (Double) distSeries.getY(pos); XYPointerAnnotation minPointer = new XYPointerAnnotation("MIN=" + (int) distValues[pos], distValues[pos], y, Math.PI * 1.5); plot.addAnnotation(minPointer); pos = (int) (((double) distValues.length / 100. * 5.0) - 1.0); while (pos < 0) { pos++; } if (pos > 0) { y = (Double) distSeries.getY(pos); } else { y = (Double) distSeries.getY(pos + 1); } final double posQ5 = distValues[pos]; XYPointerAnnotation q05Pointer = new XYPointerAnnotation("Q5=" + (int) distValues[pos], distValues[pos], y, Math.PI * 1.5); plot.addAnnotation(q05Pointer); pos = (int) (((double) distValues.length / 2.0) - 1.0); y = (Double) distSeries.getY(pos); XYPointerAnnotation q50Pointer = new XYPointerAnnotation("Q50=" + (int) distValues[pos], distValues[pos], y, Math.PI * 1.5); plot.addAnnotation(q50Pointer); ValueMarker medMarker = new ValueMarker(distValues[pos], lineColor, new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, dash, 0)); plot.addDomainMarker(medMarker); pos = (int) (((double) distValues.length / 100.0 * 95.0) - 1.0); if (pos < distValues.length - 1) { y = (Double) distSeries.getY(pos); } else { y = (Double) distSeries.getY(pos - 1); } final double posQ95 = distValues[pos]; XYPointerAnnotation q95Pointer = new XYPointerAnnotation("Q95=" + (int) distValues[pos], distValues[pos], y, Math.PI * 0.5); plot.addAnnotation(q95Pointer); pos = distValues.length - 1; y = (Double) distSeries.getY(pos); XYPointerAnnotation maxPointer = new XYPointerAnnotation("MAX=" + (int) distValues[pos], distValues[pos], y, Math.PI * 0.5); plot.addAnnotation(maxPointer); IntervalMarker percentiles = new IntervalMarker(posQ5, posQ95); percentiles.setPaint(rangeColor); percentiles.setStroke(new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, dash, 0)); plot.addDomainMarker(percentiles, Layer.BACKGROUND); XYItemRenderer renderer = plot.getRenderer(); renderer.setSeriesPaint(0, lineColor); return chart; }