List of usage examples for org.jfree.data.xy XYSeriesCollection XYSeriesCollection
public XYSeriesCollection()
From source file:playground.artemc.socialCost.MeanTravelTimeWriter.java
/** * @return a graphic showing the number of agents in the evacuated area *//*from ww w . j a v a 2 s . co m*/ private JFreeChart getGraphic(String[] modeNames, double data[][]) { final XYSeriesCollection xyData = new XYSeriesCollection(); for (int j = 0; j < modeNames.length; j++) { String modeName = modeNames[j]; double[] d = data[j]; XYSeries dataSerie = new XYSeries(modeName, false, true); for (int i = 0; i < d.length; i++) { dataSerie.add(i, d[i]); } xyData.addSeries(dataSerie); } // final JFreeChart chart = ChartFactory.createXYStepChart( final JFreeChart chart = ChartFactory.createXYLineChart("mean trip travel time, all transport modes modes", "iteration", "travel time", 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:org.owasp.benchmark.score.report.ScatterVulns.java
private JFreeChart display(String title, int height, String category, Set<Report> toolResults) { JFrame f = new JFrame(title); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // averages//www. java 2s .co m ArrayList<Double> averageFalseRates = new ArrayList<Double>(); ArrayList<Double> averageTrueRates = new ArrayList<Double>(); int commercialToolCount = 0; XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries("Scores"); for (Report toolReport : toolResults) { if (!toolReport.isCommercial()) { OverallResult overallResult = toolReport.getOverallResults().getResults(category); series.add(overallResult.falsePositiveRate * 100, overallResult.truePositiveRate * 100); } } for (Report toolReport : toolResults) { if (toolReport.isCommercial()) { OverallResult overallResult = toolReport.getOverallResults().getResults(category); if (!BenchmarkScore.showAveOnlyMode) { series.add(overallResult.falsePositiveRate * 100, overallResult.truePositiveRate * 100); } commercialToolCount++; averageFalseRates.add(overallResult.falsePositiveRate); averageTrueRates.add(overallResult.truePositiveRate); } } for (double d : averageFalseRates) { afr += d; } afr = afr / averageFalseRates.size(); for (double d : averageTrueRates) { atr += d; } atr = atr / averageTrueRates.size(); if (commercialToolCount > 1 || (BenchmarkScore.showAveOnlyMode && commercialToolCount == 1)) { series.add(afr * 100, atr * 100); } dataset.addSeries(series); chart = ChartFactory.createScatterPlot(title, "False Positive Rate", "True Positive Rate", dataset, PlotOrientation.VERTICAL, true, true, false); theme.apply(chart); XYPlot xyplot = chart.getXYPlot(); initializePlot(xyplot); makeDataLabels(category, toolResults, xyplot); makeLegend(category, toolResults, 103, 100.5, dataset, xyplot); for (XYDataItem item : (List<XYDataItem>) series.getItems()) { double x = item.getX().doubleValue(); double y = item.getY().doubleValue(); double z = (x + y) / 2; XYLineAnnotation score = new XYLineAnnotation(x, y, z, z, dashed, Color.blue); xyplot.addAnnotation(score); } ChartPanel cp = new ChartPanel(chart, height, height, 400, 400, 1200, 1200, false, false, false, false, false, false); f.add(cp); f.pack(); f.setLocationRelativeTo(null); // f.setVisible(true); return chart; }
From source file:br.ufrgs.enq.jcosmo.test.VLEdiagramsGAMESS.java
public JPanel calcAcetoneWater() throws Exception { super.setTitle("P vs x1"); double T = 298.15; setLayout(new BorderLayout()); COSMOSACDataBase db = COSMOSACDataBase.getInstance(); COSMOSACCompound c1 = db.getComp("ethyl-acetate"); COSMOSACCompound c2 = db.getComp("water"); double[] cavityVolume = new double[2]; cavityVolume[0] = c1.Vcosmo;/*from ww w. j a v a2 s . c o m*/ cavityVolume[1] = c2.Vcosmo; double[][] sigma = new double[2][]; sigma[0] = c1.sigma; sigma[1] = c2.sigma; SigmaProfileGenerator c1Sigma = new SigmaProfileGenerator(SigmaProfileGenerator.FileType.GAMESS, c1.name.toLowerCase() + ".log"); SigmaProfileGenerator c2Sigma = new SigmaProfileGenerator(SigmaProfileGenerator.FileType.GAMESS, c2.name.toLowerCase() + ".log"); sigma[0] = c1Sigma.getSigmaProfile(); sigma[1] = c2Sigma.getSigmaProfile(); COSMOSAC cosmosac = new COSMOSAC(); cosmosac.setParameters(cavityVolume, c1.charge, sigma); cosmosac.setIgnoreSG(true); cosmosac.setSigmaHB(COSMOSAC.SIGMAHB * 1.2); cosmosac.setTemperature(T); double[] x1 = new double[n]; double[] x2 = new double[n]; double[] gamma1 = new double[n]; double[] gamma2 = new double[n]; double[] z = new double[2]; double[] lnGamma = new double[2]; z[0] = 0.00; int j = 0; while (z[0] < 1.0001) { z[1] = 1 - z[0]; x1[j] = z[0]; x2[j] = z[1]; cosmosac.setComposition(z); cosmosac.activityCoefficient(lnGamma); gamma1[j] = Math.exp(lnGamma[0]); gamma2[j] = Math.exp(lnGamma[1]); z[0] += 0.05; j++; } double[] Psat = new double[2]; Psat[0] = 13000; Psat[1] = 3000; double[] P = calcPx(x1, x2, gamma1, gamma2, Psat); double[] y1 = calcY(x1, gamma1, Psat, P); XYPlot plot1; XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries liq = new XYSeries("liquid"); XYSeries vap = new XYSeries("vapor"); XYSeries raoult = new XYSeries("Raoult's Law"); for (int i = 0; i < n; i++) { liq.add(x1[i], P[i]); vap.add(y1[i], P[i]); } raoult.add(0, Psat[1]); raoult.add(1, Psat[0]); dataset.addSeries(liq); dataset.addSeries(vap); dataset.addSeries(raoult); JFreeChart chart = ChartFactory.createXYLineChart(null, "Mole Fraction: x1, y1", "P/KPa", null, PlotOrientation.VERTICAL, true, true, false); plot1 = (XYPlot) chart.getPlot(); plot1.getDomainAxis().setRange(new Range(0.0, 1.0)); plot1.setDataset(dataset); // XYSplineRenderer r = new XYSplineRenderer(); // BasicStroke stroke = new BasicStroke(2f); // r.setStroke(stroke); // plot1.setRenderer(r); // r.setBaseShapesVisible(false); ChartPanel chartPanel = new ChartPanel(chart); JPanel jp1 = new JPanel(new BorderLayout()); jp1.add(chartPanel); add(jp1, BorderLayout.CENTER); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(400, 500); return jp1; }
From source file:edu.ucla.stat.SOCR.chart.demo.IndexChart.java
/** * Creates a sample dataset.//from w w w. java2 s . c om * * @return a sample dataset. */ protected XYDataset createDataset1(boolean isDemo) { if (isDemo) { row_count = 10; raw_x = new String[row_count]; raw_x[0] = "1.0"; raw_x[1] = "2.0"; raw_x[2] = "3.0"; raw_x[3] = "4.0"; raw_x[4] = "5.0"; raw_x[5] = "6.0"; raw_x[6] = "76.0"; raw_x[7] = "78.0"; raw_x[8] = "7.0"; raw_x[9] = "8.0"; XYSeries series1 = new XYSeries("Data"); series1.add(1, 1.0); series1.add(2, 2.0); series1.add(3, 3.0); series1.add(4, 4.0); series1.add(5, 5.0); series1.add(6, 6.0); series1.add(7, 76.0); series1.add(8, 78.0); series1.add(9, 7.0); series1.add(10, 8.0); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series1); return dataset; } else return super.createDataset(false); }
From source file:org.jfree.data.xy.junit.XYSeriesCollectionTest.java
/** * Confirm that the equals method can distinguish all the required fields. *//* www . j a va 2 s . c o m*/ public void testEquals() { XYSeries s1 = new XYSeries("Series"); s1.add(1.0, 1.1); XYSeriesCollection c1 = new XYSeriesCollection(); c1.addSeries(s1); XYSeries s2 = new XYSeries("Series"); s2.add(1.0, 1.1); XYSeriesCollection c2 = new XYSeriesCollection(); c2.addSeries(s2); assertTrue(c1.equals(c2)); assertTrue(c2.equals(c1)); c1.addSeries(new XYSeries("Empty Series")); assertFalse(c1.equals(c2)); c2.addSeries(new XYSeries("Empty Series")); assertTrue(c1.equals(c2)); c1.setIntervalWidth(5.0); assertFalse(c1.equals(c2)); c2.setIntervalWidth(5.0); assertTrue(c1.equals(c2)); c1.setIntervalPositionFactor(0.75); assertFalse(c1.equals(c2)); c2.setIntervalPositionFactor(0.75); assertTrue(c1.equals(c2)); c1.setAutoWidth(true); assertFalse(c1.equals(c2)); c2.setAutoWidth(true); assertTrue(c1.equals(c2)); }
From source file:maltcms.ui.fileHandles.csv.CSV2JFCLoader.java
@Override public void run() { CSV2TableLoader tl = new CSV2TableLoader(this.ph, this.is); DefaultTableModel dtm;// w w w .j a v a 2s .c o m try { dtm = tl.call(); if (this.mode == CHART.XY) { XYSeriesCollection cd = new XYSeriesCollection(); for (int j = 0; j < dtm.getColumnCount(); j++) { XYSeries xys = new XYSeries(dtm.getColumnName(j)); for (int i = 0; i < dtm.getRowCount(); i++) { Object o = dtm.getValueAt(i, j); try { double d = Double.parseDouble(o.toString()); xys.add(i, d); Logger.getLogger(getClass().getName()).log(Level.INFO, "Adding {0} {1} {2}", new Object[] { i, d, dtm.getColumnName(j) }); } catch (Exception e) { } } cd.addSeries(xys); } XYLineAndShapeRenderer d = new XYLineAndShapeRenderer(true, false); XYPlot xyp = new XYPlot(cd, new NumberAxis("category"), new NumberAxis("value"), d); JFreeChart jfc = new JFreeChart(this.title, xyp); jtc.setChart(jfc); Logger.getLogger(getClass().getName()).info("creating chart done"); } else if (this.mode == CHART.MATRIX) { DefaultXYZDataset cd = new DefaultXYZDataset(); Logger.getLogger(getClass().getName()).log(Level.INFO, "Name of column 0: {0}", dtm.getColumnName(0)); if (dtm.getColumnName(0).isEmpty()) { Logger.getLogger(getClass().getName()).info("Removing column 0"); dtm = removeColumn(dtm, 0); } if (dtm.getColumnName(dtm.getColumnCount() - 1).equalsIgnoreCase("filename")) { dtm = removeColumn(dtm, dtm.getColumnCount() - 1); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < dtm.getRowCount(); i++) { for (int j = 0; j < dtm.getColumnCount(); j++) { sb.append(dtm.getValueAt(i, j) + " "); } sb.append("\n"); } Logger.getLogger(getClass().getName()).log(Level.INFO, "Table before sorting: {0}", sb.toString()); // dtm = sort(dtm); StringBuilder sb2 = new StringBuilder(); for (int i = 0; i < dtm.getRowCount(); i++) { for (int j = 0; j < dtm.getColumnCount(); j++) { sb2.append(dtm.getValueAt(i, j) + " "); } sb2.append("\n"); } Logger.getLogger(getClass().getName()).log(Level.INFO, "Table after sorting: {0}", sb2.toString()); int rows = dtm.getRowCount(); int columns = dtm.getColumnCount(); Logger.getLogger(getClass().getName()).log(Level.INFO, "Storing {0} * {1} elements, {2} total!", new Object[] { columns, rows, rows * columns }); double[][] data = new double[3][(columns * rows)]; ArrayDouble.D1 dt = new ArrayDouble.D1((columns) * rows); double min = Double.POSITIVE_INFINITY; double max = Double.NEGATIVE_INFINITY; EvalTools.eqI(rows, columns, this); int k = 0; for (int i = 0; i < dtm.getRowCount(); i++) { for (int j = 0; j < dtm.getColumnCount(); j++) { Object o = dtm.getValueAt(i, j); try { double d = Double.parseDouble(o.toString()); if (d < min) { min = d; } if (d > max) { max = d; } data[0][k] = (double) i; data[1][k] = (double) j; data[2][k] = d; dt.set(k, d); k++; //System.out.println("Adding "+i+" "+d+" "+dtm.getColumnName(j)); } catch (Exception e) { } } //cd.addSeries(xys); } cd.addSeries(this.title, data); XYBlockRenderer xyb = new XYBlockRenderer(); GradientPaintScale ps = new GradientPaintScale(ImageTools.createSampleTable(256), min, max, ImageTools .rampToColorArray(new ColorRampReader().readColorRamp("res/colorRamps/bcgyr.csv"))); xyb.setPaintScale(ps); final String[] colnames = new String[dtm.getColumnCount()]; for (int i = 0; i < colnames.length; i++) { colnames[i] = dtm.getColumnName(i); } NumberAxis na1 = new SymbolAxis("category", colnames); na1.setVerticalTickLabels(false); NumberAxis na2 = new SymbolAxis("category", colnames); na1.setVerticalTickLabels(true); XYPlot xyp = new XYPlot(cd, na1, na2, xyb); xyb.setSeriesToolTipGenerator(0, new XYToolTipGenerator() { @Override public String generateToolTip(XYDataset xyd, int i, int i1) { return "[" + colnames[xyd.getX(i, i1).intValue()] + ":" + colnames[xyd.getY(i, i1).intValue()] + "] = " + ((XYZDataset) xyd).getZValue(i, i1) + ""; } }); JFreeChart jfc = new JFreeChart(this.title, xyp); NumberAxis values = new NumberAxis("value"); values.setAutoRange(false); values.setRangeWithMargins(min, max); PaintScaleLegend psl = new PaintScaleLegend(ps, values); psl.setBackgroundPaint(jfc.getBackgroundPaint()); jfc.addSubtitle(psl); psl.setStripWidth(50); psl.setPadding(20, 20, 20, 20); psl.setHeight(200); psl.setPosition(RectangleEdge.RIGHT); jtc.setChart(jfc); } } catch (Exception ex) { Exceptions.printStackTrace(ex); } ph.finish(); }
From source file:playground.dgrether.analysis.charts.DgAvgDeltaMoneyQuantilesChart.java
protected XYSeriesCollection createDatasets(String runId1, String runId2) { XYSeriesCollection ds = new XYSeriesCollection(); Tuple<XYSeries, List<String>> seriesLabels = this.createXYSeries("Mean " + '\u0394' + " Chf", this.ana, runId1, runId2);/*w w w . jav a2s. c o m*/ ds.addSeries(seriesLabels.getFirst()); this.labelGenerator.setLabels(0, seriesLabels.getSecond()); return ds; }
From source file:edu.ucla.stat.SOCR.chart.demo.CrosshairDemo4.java
/** * Creates a sample dataset.// w w w . j a va2 s. c om * * @return a sample dataset. */ protected XYDataset createDataset(boolean isDemo) { if (isDemo) { XYSeries series1 = new XYSeries("First"); series1.add(1.0, 1.0); series1.add(2.0, 4.0); series1.add(3.0, 3.0); series1.add(4.0, 5.0); series1.add(5.0, 5.0); series1.add(6.0, 7.0); series1.add(7.0, 7.0); series1.add(8.0, 8.0); XYSeries series2 = new XYSeries("Second"); series2.add(1.0, 5.0); series2.add(2.0, 7.0); series2.add(3.0, 6.0); series2.add(4.0, 8.0); series2.add(5.0, 4.0); series2.add(6.0, 4.0); series2.add(7.0, 2.0); series2.add(8.0, 1.0); XYSeries series3 = new XYSeries("Third"); series3.add(3.0, 4.0); series3.add(4.0, 3.0); series3.add(5.0, 2.0); series3.add(6.0, 3.0); series3.add(7.0, 6.0); series3.add(8.0, 3.0); series3.add(9.0, 4.0); series3.add(10.0, 3.0); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series1); dataset.addSeries(series2); dataset.addSeries(series3); return dataset; } else return super.createDataset(false); }
From source file:no.ntnu.mmfplanner.ui.graph.NpvChart.java
/** * Updates the chart with data from the model. *///from w w w . j a v a 2s .c o m private void updateModel() { modelValid = true; XYSeriesCollection dataset = new XYSeriesCollection(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setLegendLine(new Rectangle2D.Double(0.0, 0.0, 6.0, 0.0)); renderer.setUseFillPaint(true); // the x=0 line addLineX(dataset, renderer); // rolling npv line (iterative) ProjectRoi projectRoi = ProjectRoi.getRoiTable(project, project.getInterestRate(), false); addNpvLine(projectRoi, "NPV Iterative", chartColor[0], dataset, renderer); // rolling npv line (waterfall) if (waterfall) { ProjectRoi projectRoiWaterfall = ProjectRoi.getRoiTable(project, project.getInterestRate(), true); addNpvLine(projectRoiWaterfall, "NPV Waterfall", chartColor[1], dataset, renderer); } // legend (break even and self funding) addLegendElements(dataset, renderer); XYPlot plot = ((XYPlot) getChart().getPlot()); plot.setDataset(dataset); plot.setRenderer(renderer); plot.setDomainGridlinesVisible(false); }
From source file:org.jfree.chart.demo.XYLineAndShapeRendererDemo2.java
private static XYDataset createDataset(int i, double d) { XYSeries xyseries = new XYSeries("Series " + i); xyseries.add(1.0D, d);// w w w . j a v a 2s .c o m xyseries.add(2D, d); xyseries.add(3D, d); XYSeriesCollection xyseriescollection = new XYSeriesCollection(); xyseriescollection.addSeries(xyseries); return xyseriescollection; }