List of usage examples for org.jfree.data.xy XYSeriesCollection addSeries
public void addSeries(XYSeries series)
From source file:org.jfree.data.xy.XYSeriesCollectionTest.java
/** * A check that the dataset prevents renaming a series to the name of an * existing series in the dataset./* w w w .j ava2 s . c o m*/ */ @Test public void testRenameSeries() { XYSeries s1 = new XYSeries("S1"); XYSeries s2 = new XYSeries("S2"); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(s1); dataset.addSeries(s2); try { s2.setKey("S1"); fail("Should have thrown IllegalArgumentException on negative key"); } catch (IllegalArgumentException e) { assertEquals("Duplicate key2", e.getMessage()); } }
From source file:edu.wustl.cab2b.client.ui.visualization.charts.LineChart.java
@Override protected Dataset createColumnWiseData() { List<String> selectedColumnNames = chartModel.getSelectedColumnsNames(); List<String> selectedRowNames = chartModel.getSelectedRowNames(); XYSeries xySeries = null;/*from www . ja v a 2 s .c om*/ XYSeriesCollection xySeriesCollection = new XYSeriesCollection(); for (int i = 0; i < selectedColumnNames.size(); i++) { String seriesName = selectedColumnNames.get(i); xySeries = new XYSeries(seriesName); for (int j = 0; j < selectedRowNames.size(); j++) { Object value = chartModel.getValueAt(j, i); xySeries.add(convertValue(selectedRowNames.get(j)), convertValue(value)); } xySeriesCollection.addSeries(xySeries); } return xySeriesCollection; }
From source file:org.gephi.statistics.plugin.DegreeDistribution.java
/** * * @return The directed version of the report. *//* ww w . j a v a 2s . c om*/ private String getDirectedReport() { double inMax = 0; XYSeries inSeries2 = new XYSeries("Series 2"); for (int i = 1; i < inDistribution[1].length; i++) { if (inDistribution[1][i] > 0) { inSeries2.add((Math.log(inDistribution[0][i]) / Math.log(Math.E)), (Math.log(inDistribution[1][i]) / Math.log(Math.E))); inMax = (float) Math.max((Math.log(inDistribution[0][i]) / Math.log(Math.E)), inMax); } } double inA = inAlpha; double inB = inBeta; String inImageFile = ""; String outImageFile = ""; try { XYSeries inSeries1 = new XYSeries(inAlpha + " "); inSeries1.add(0, inA); inSeries1.add(inMax, inA + inB * inMax); XYSeriesCollection inDataset = new XYSeriesCollection(); inDataset.addSeries(inSeries1); inDataset.addSeries(inSeries2); JFreeChart inChart = ChartFactory.createXYLineChart("In-Degree Distribution", "In-Degree", "Occurrence", inDataset, PlotOrientation.VERTICAL, true, false, false); XYPlot inPlot = (XYPlot) inChart.getPlot(); XYLineAndShapeRenderer inRenderer = new XYLineAndShapeRenderer(); inRenderer.setSeriesLinesVisible(0, true); inRenderer.setSeriesShapesVisible(0, false); inRenderer.setSeriesLinesVisible(1, false); inRenderer.setSeriesShapesVisible(1, true); inRenderer.setSeriesShape(1, new java.awt.geom.Ellipse2D.Double(0, 0, 1, 1)); inPlot.setBackgroundPaint(java.awt.Color.WHITE); inPlot.setDomainGridlinePaint(java.awt.Color.GRAY); inPlot.setRangeGridlinePaint(java.awt.Color.GRAY); inPlot.setRenderer(inRenderer); final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); TempDir tempDir = TempDirUtils.createTempDir(); final String fileName = "inDistribution.png"; final File file1 = tempDir.createFile(fileName); inImageFile = "<IMG SRC=\"file:" + file1.getAbsolutePath() + "\" " + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\"></IMG>"; ChartUtilities.saveChartAsPNG(file1, inChart, 600, 400, info); double outMax = 0; XYSeries outSeries2 = new XYSeries("Series 2"); for (int i = 1; i < outDistribution[1].length; i++) { if (outDistribution[1][i] > 0) { outSeries2.add((Math.log(outDistribution[0][i]) / Math.log(Math.E)), (Math.log(outDistribution[1][i]) / Math.log(Math.E))); outMax = (float) Math.max((Math.log(outDistribution[0][i]) / Math.log(Math.E)), outMax); } } double outA = outAlpha; double outB = outBeta; XYSeries outSeries1 = new XYSeries(outAlpha + " "); outSeries1.add(0, outA); outSeries1.add(outMax, outA + outB * outMax); XYSeriesCollection outDataset = new XYSeriesCollection(); outDataset.addSeries(outSeries1); outDataset.addSeries(outSeries2); JFreeChart outchart = ChartFactory.createXYLineChart("Out-Degree Distribution", "Out-Degree", "Occurrence", outDataset, PlotOrientation.VERTICAL, true, false, false); XYPlot outPlot = (XYPlot) outchart.getPlot(); XYLineAndShapeRenderer outRenderer = new XYLineAndShapeRenderer(); outRenderer.setSeriesLinesVisible(0, true); outRenderer.setSeriesShapesVisible(0, false); outRenderer.setSeriesLinesVisible(1, false); outRenderer.setSeriesShapesVisible(1, true); outRenderer.setSeriesShape(1, new java.awt.geom.Ellipse2D.Double(0, 0, 1, 1)); outPlot.setBackgroundPaint(java.awt.Color.WHITE); outPlot.setDomainGridlinePaint(java.awt.Color.GRAY); outPlot.setRangeGridlinePaint(java.awt.Color.GRAY); outPlot.setRenderer(outRenderer); final ChartRenderingInfo info2 = new ChartRenderingInfo(new StandardEntityCollection()); final String fileName2 = "outDistribution.png"; final File file2 = tempDir.createFile(fileName2); outImageFile = "<IMG SRC=\"file:" + file2.getAbsolutePath() + "\" " + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\"></IMG>"; ChartUtilities.saveChartAsPNG(file2, outchart, 600, 400, info2); } catch (IOException e) { Exceptions.printStackTrace(e); } String report = "<HTML> <BODY> <h1>Degree Distribution Metric Report </h1> " + "<hr>" + "<br>" + "<h2> Parameters: </h2>" + "Network Interpretation: " + (isDirected ? "directed" : "undirected") + "<br>" + "<br> <h2> Results: </h2>" + "In-Degree Power Law: -" + inAlpha + "\n <BR>" + inImageFile + "<br>Out-Degree Power Law: -" + outAlpha + "\n <BR>" + outImageFile + "</BODY> </HTML>"; return report; }
From source file:org.gwaspi.reports.GenericReportGenerator.java
public static XYPlot buildQQPlot(OperationKey testOpKey, int df) throws IOException { if (df != 1 && df != 2) { throw new IllegalArgumentException("Only df = 1 or 2 is supported; it is " + df); }//from w w w . ja va 2 s . c om //<editor-fold defaultstate="expanded" desc="PLOT DEFAULTS"> final Config config = Config.getSingleton(); final Color background = config.getColor(PLOT_QQ_BACKGROUND_CONFIG, PLOT_QQ_BACKGROUND_DEFAULT); final Color actual = config.getColor(PLOT_QQ_ACTUAL_CONFIG, PLOT_QQ_ACTUAL_DEFAULT); final Color sigma = config.getColor(PLOT_QQ_SIGMA_CONFIG, PLOT_QQ_SIGMA_DEFAULT); final Color mu = config.getColor(PLOT_QQ_MU_CONFIG, PLOT_QQ_MU_DEFAULT); //</editor-fold> //<editor-fold defaultstate="expanded" desc="GET X^2"> List<Double> obsChiSqrVals = assembleQQPlotData(testOpKey); int N = obsChiSqrVals.size(); List<Double> expChiSqrDist; if (df == 1) { expChiSqrDist = Chisquare.getChiSquareDistributionDf1(N, 1.0f); } else { // df == 2 expChiSqrDist = Chisquare.getChiSquareDistributionDf2(N, 1.0f); } Collections.sort(expChiSqrDist); //</editor-fold> //<editor-fold defaultstate="expanded" desc="GET CONFIDENCE BOUNDARY"> InputStream boundaryStream = GenericReportGenerator.class .getResourceAsStream("/samples/chisqrboundary-df" + df + ".txt"); InputStreamReader isr = new InputStreamReader(boundaryStream); BufferedReader inputBufferReader = new BufferedReader(isr); Double stopValue = expChiSqrDist.get(N - 1); Double currentValue = 0d; List<Double[]> boundary = new ArrayList<Double[]>(); while (currentValue <= stopValue) { String l = inputBufferReader.readLine(); if (l == null) { break; } String[] cVals = l.split(","); Double[] slice = new Double[3]; slice[0] = Double.parseDouble(cVals[0]); slice[1] = Double.parseDouble(cVals[1]); slice[2] = Double.parseDouble(cVals[2]); currentValue = slice[1]; boundary.add(slice); } inputBufferReader.close(); //</editor-fold> XYSeriesCollection dataSeries = new XYSeriesCollection(); XYSeries seriesData = new XYSeries("X"); XYSeries seriesRef = new XYSeries("Expected"); for (int i = 0; i < obsChiSqrVals.size(); i++) { double obsVal = obsChiSqrVals.get(i); double expVal = expChiSqrDist.get(i); seriesData.add(expVal, obsVal); seriesRef.add(expVal, expVal); } //constant chi-square boundaries XYSeries seriesLower = new XYSeries("2 boundary"); XYSeries seriesUpper = new XYSeries(""); for (Double[] slice : boundary) { seriesUpper.add(slice[1], slice[0]); seriesLower.add(slice[1], slice[2]); } dataSeries.addSeries(seriesData); dataSeries.addSeries(seriesRef); dataSeries.addSeries(seriesUpper); dataSeries.addSeries(seriesLower); final XYDataset data = dataSeries; //create QQ plot final boolean withLegend = true; JFreeChart chart = ChartFactory.createScatterPlot("QQ-plot", "Exp X", "Obs X", data, PlotOrientation.VERTICAL, withLegend, false, false); final XYPlot plot = chart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true); renderer.setSeriesPaint(0, actual); renderer.setSeriesPaint(1, mu); renderer.setSeriesPaint(2, sigma); renderer.setSeriesPaint(3, sigma); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setSeriesShape(0, new Rectangle2D.Double(-1.0, -1.0, 2.0, 2.0)); renderer.setSeriesShape(1, new Rectangle2D.Double(-1.0, -1.0, 2.0, 2.0)); renderer.setSeriesShape(2, new Rectangle2D.Double(-1.0, -1.0, 2.0, 2.0)); renderer.setSeriesShape(3, new Rectangle2D.Double(-1.0, -1.0, 2.0, 2.0)); plot.setRenderer(renderer); // PLOT BACKGROUND COLOR plot.setBackgroundPaint(background); // Hue, saturation, brightness return plot; }
From source file:org.jfree.data.xy.XYSeriesCollectionTest.java
/** * A test to cover bug 3445507. The issue does not affect * XYSeriesCollection./* w ww . j a v a 2 s . co m*/ */ @Test public void testBug3445507() { XYSeries s1 = new XYSeries("S1"); s1.add(1.0, null); s1.add(2.0, null); XYSeries s2 = new XYSeries("S2"); s1.add(1.0, 5.0); s1.add(2.0, 6.0); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(s1); dataset.addSeries(s2); Range r = dataset.getRangeBounds(false); assertEquals(5.0, r.getLowerBound(), EPSILON); assertEquals(6.0, r.getUpperBound(), EPSILON); }
From source file:oct.analysis.application.OCTSelection.java
public JPanel createLRPPanel() { //create the series collection from the LRP data XYSeriesCollection lrp = new XYSeriesCollection(); lrp.addSeries(getLrpSeriesFromOCT(OCTAnalysisManager.getInstance().getOctImage())); // System.out.println("Processing graph " + lrp.getSeriesKey(0).toString()); lrp.addSeries(findMaximums(lrp.getSeries(0), selectionName + " LRP Maximums")); List<XYSeries> fwhm = getFWHMForLRPPeaks(lrp.getSeries(1), lrp.getSeries(0)); fwhm.forEach((fwhmSeries) -> {/*from w w w .ja v a 2s . co m*/ lrp.addSeries(fwhmSeries); }); //create chart panel for LRP JFreeChart chart = ChartFactory.createXYLineChart(lrp.getSeriesKey(0).toString(), "Pixel Height", "Reflectivity", lrp, PlotOrientation.HORIZONTAL, false, true, false); XYPlot plot = chart.getXYPlot(); // plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); // plot.getDomainAxis().setInverted(true); //set up rendering principles XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, false); renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesShapesFilled(1, true); renderer.setSeriesPaint(1, Color.BLUE); for (int i = 2; i < fwhm.size() + 2; i++) { renderer.setSeriesLinesVisible(i, true); renderer.setSeriesShapesVisible(i, false); renderer.setSeriesPaint(i, Color.BLACK); } plot.setRenderer(renderer); //make panel ChartPanel panel = new ChartPanel(chart); panel.setPreferredSize(new Dimension(200, 200)); panel.setFillZoomRectangle(true); panel.setMouseWheelEnabled(true); return panel; }
From source file:playground.christoph.evacuation.analysis.AgentsInEvacuationAreaActivityWriter.java
/** * @return a graphic showing the number of agents in the evacuated area */// w w w. java2s. co m private JFreeChart getGraphic(int[] activities, int[] activitiesParticipatingAtHome, int[] activitiesParticipatingNotAtHome, int[] activitiesNotParticipatingAtHome, int[] activitiesNotParticipatingNotAtHome) { final XYSeriesCollection xyData = new XYSeriesCollection(); XYSeries dataSerie; dataSerie = new XYSeries("total activity performing agents in evacuated area", false, true); for (int i = 0; i < activities.length; i++) { double hour = i * this.binSize / 60.0 / 60.0; dataSerie.add(hour, activities[i]); } xyData.addSeries(dataSerie); dataSerie = new XYSeries("participating agents performing a home activity in evacuated area", false, true); for (int i = 0; i < activitiesParticipatingAtHome.length; i++) { double hour = i * this.binSize / 60.0 / 60.0; dataSerie.add(hour, activitiesParticipatingAtHome[i]); } xyData.addSeries(dataSerie); dataSerie = new XYSeries("participating agents performing an other activity in evacuated area", false, true); for (int i = 0; i < activitiesParticipatingNotAtHome.length; i++) { double hour = i * this.binSize / 60.0 / 60.0; dataSerie.add(hour, activitiesParticipatingNotAtHome[i]); } xyData.addSeries(dataSerie); dataSerie = new XYSeries("not participating agents performing a home activity in evacuated area", false, true); for (int i = 0; i < activitiesNotParticipatingAtHome.length; i++) { double hour = i * this.binSize / 60.0 / 60.0; dataSerie.add(hour, activitiesNotParticipatingAtHome[i]); } xyData.addSeries(dataSerie); dataSerie = new XYSeries("not participating agents performing an other activity in evacuated area", false, true); for (int i = 0; i < activitiesNotParticipatingNotAtHome.length; i++) { double hour = i * this.binSize / 60.0 / 60.0; dataSerie.add(hour, activitiesNotParticipatingNotAtHome[i]); } xyData.addSeries(dataSerie); final JFreeChart chart = ChartFactory.createXYStepChart( "activity performing agents in evacuated area, it." + this.iteration, "time", "# agents", xyData, PlotOrientation.VERTICAL, true, // legend false, // tooltips false // urls ); XYPlot plot = chart.getXYPlot(); final CategoryAxis axis1 = new CategoryAxis("hour"); axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7)); plot.setDomainAxis(new NumberAxis("time")); return chart; }
From source file:edu.wustl.cab2b.client.ui.visualization.charts.LineChart.java
@Override protected Dataset createRowWiseData() { List<String> selectedColumnNames = chartModel.getSelectedColumnsNames(); List<String> selectedRowNames = chartModel.getSelectedRowNames(); XYSeries xySeries = null;/*from ww w . j ava 2s .c om*/ XYSeriesCollection xySeriesCollection = new XYSeriesCollection(); for (int i = 0; i < selectedRowNames.size(); i++) { String seriesName = selectedRowNames.get(i) + ""; xySeries = new XYSeries(seriesName); for (int j = 0; j < selectedColumnNames.size(); j++) { Object value = chartModel.getValueAt(i, j); xySeries.add(convertValue(selectedColumnNames.get(j)), convertValue(value)); } xySeriesCollection.addSeries(xySeries); } return xySeriesCollection; }
From source file:org.jfree.data.xy.XYSeriesCollectionTest.java
/** * Test that a series belonging to a collection can be renamed (in fact, * because of a bug this was not possible in JFreeChart 1.0.14). *///from ww w . j a v a2 s .com @Test public void testSeriesRename() { // first check that a valid renaming works XYSeries series1 = new XYSeries("A"); XYSeries series2 = new XYSeries("B"); XYSeriesCollection collection = new XYSeriesCollection(); collection.addSeries(series1); collection.addSeries(series2); series1.setKey("C"); assertEquals("C", collection.getSeries(0).getKey()); // next, check that setting a duplicate key fails try { series2.setKey("C"); fail("Expected an IllegalArgumentException."); } catch (IllegalArgumentException e) { // expected } assertEquals("B", series2.getKey()); // the series name should not // change because "C" is already the key for the other series in the // collection }
From source file:eu.hydrologis.jgrass.charting.datamodels.MultiXYTimeChartCreator.java
public Dataset chartSeriesToDatasetList(TwoVerticalMultiXYTimeChartModel chartData) { final List<TwoVerticalMultiXYTimeChartItem> _chartsData = chartData.getChartsDataItems(); final List<XYSeries> chartSeries = new ArrayList<XYSeries>(); for (int i = 0; i < _chartsData.size(); i++) { final TwoVerticalMultiXYTimeChartItem tmpCD = _chartsData.get(i); final String title = chartData.getChartTitle(i); final List<double[][]> valuesList = tmpCD.getLowerChartSeriesData(); for (final double[][] values : valuesList) { final XYSeries xySeries = new XYSeries(title); for (int j = 0; j < values[0].length; j++) { // important: the data matrix has to be passed as two rows (not // two columns) xySeries.add(values[0][j], values[1][j]); }/*from ww w . j a v a 2 s . c o m*/ chartSeries.add(xySeries); } } final XYSeriesCollection lineDataset = new XYSeriesCollection(); for (int i = 0; i < chartSeries.size(); i++) { lineDataset.addSeries(chartSeries.get(i)); } return lineDataset; }