List of usage examples for org.jfree.data.xy XYSeriesCollection addSeries
public void addSeries(XYSeries series)
From source file:regression.gui.RegressionChart.java
/** * Creates a sample dataset./*ww w . j ava2 s . co m*/ * * @return a sample dataset. */ private XYDataset createDataset(Function function, List<Point> points) { List<Point> functionPoints = createFunction(function, points); final XYSeries series1 = new XYSeries("Funkcja regresji"); for (Iterator<Point> it = functionPoints.iterator(); it.hasNext();) { Point point = it.next(); series1.add(point.getX(), point.getY()); } final XYSeries series2 = new XYSeries("Punkty Klasy A"); final XYSeries series3 = new XYSeries("Punkty Klasy B"); for (Iterator<Point> it = points.iterator(); it.hasNext();) { Point point = it.next(); if (checkIfPointAboveLine(function, point)) { series2.add(point.getX(), point.getY()); } else { series3.add(point.getX(), point.getY()); } } final XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series2); dataset.addSeries(series1); dataset.addSeries(series3); return dataset; }
From source file:signalviewer.SignalViewer.java
private void getPlot() { update_data();// ww w . j a v a 2s . c o m // ChartPanel[] panels = new ChartPanel[max_plots]; for (int j = 0; j < max_plots; j++) { XYSeries series = new XYSeries("Planned"); for (int i = 0; i < max_bins; i++) { series.add((double) i, D[j][i]); } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); JFreeChart chart = ChartFactory.createXYLineChart("Line Chart Demo", "X", "Y", dataset); chart.setTitle(""); chart.removeLegend(); XYPlot plot = (XYPlot) chart.getPlot(); // draw a horizontal line across the chart at y == 0 // plot.addRangeMarker(new Marker(0, Color.red, new BasicStroke(1), Color.red, 1f)); // ChartPanel panel = new ChartPanel(chart); if (panels[j] == null) { panels[j] = new ChartPanel(chart); } else { panels[j].setChart(chart); // panels[j].setMaximumDrawHeight(200); panels[j].revalidate(); panels[j].repaint(); } // panels[j] = panel; } // return panels; }
From source file:org.drugis.addis.gui.ConvergencePlotsDialog.java
private JPanel createPanel() { FormLayout layout = new FormLayout("pref:grow:fill", "p, 3dlu, p, 3dlu, p"); PanelBuilder builder = new PanelBuilder(layout); builder.setDefaultDialogBorder();//from w w w . j a v a2s . co m CellConstraints cc = new CellConstraints(); final XYSeriesCollection datasetRhat = new XYSeriesCollection(); final XYSeriesCollection datasetVhatVsW = new XYSeriesCollection(); datasetRhat.addSeries(d_rHatSeries); datasetVhatVsW.addSeries(d_vHatSeries); datasetVhatVsW.addSeries(d_wSeries); final JFreeChart rHatChart = createRhatChart(datasetRhat); final JFreeChart vHatvsWChart = createVhatVsWChart(datasetVhatVsW); final ChartPanel chartPanelRhat = new ChartPanel(rHatChart); final ChartPanel chartPanelVhatVsW = new ChartPanel(vHatvsWChart); chartPanelRhat.setVisible(true); chartPanelVhatVsW.setVisible(true); JProgressBar bar = new TaskProgressBar(d_task); builder.add(bar, cc.xy(1, 1)); builder.add(chartPanelRhat, cc.xy(1, 3)); builder.add(chartPanelVhatVsW, cc.xy(1, 5)); return builder.getPanel(); }
From source file:org.signserver.client.cli.performance.PerformanceTestPDFServlet.java
License:asdf
/** * Create and write diagrams to disk.// w w w. j av a2 s.c om */ private void createDiagram(String statisticsDirectory, ArrayList<String> explanationRow, ArrayList<ArrayList<Double>> processedData, int xRow, int y1Row, int y2Row) { final XYSeries s1 = new XYSeries(explanationRow.get(y1Row)); final XYSeries s2 = new XYSeries(explanationRow.get(y2Row)); for (ArrayList<Double> currentRow : processedData) { s1.add(currentRow.get(xRow), currentRow.get(y1Row)); s2.add(currentRow.get(xRow), currentRow.get(y2Row)); } final XYSeriesCollection dataset1 = new XYSeriesCollection(); dataset1.addSeries(s1); final XYSeriesCollection dataset2 = new XYSeriesCollection(); dataset2.addSeries(s2); final JFreeChart chart = ChartFactory.createXYLineChart("Test result " + xRow + "" + y1Row + "" + y2Row, explanationRow.get(xRow), explanationRow.get(y1Row), dataset1, PlotOrientation.VERTICAL, true, true, false); final XYPlot plot = chart.getXYPlot(); if (y1Row == COLUMN_INVOCATIONS_PER_SECOND) { final NumberAxis axis1 = new LogarithmicAxis(explanationRow.get(y1Row)); plot.setRangeAxis(0, axis1); } final NumberAxis axis2 = new NumberAxis(explanationRow.get(y2Row)); axis2.setAutoRangeIncludesZero(false); plot.setRangeAxis(1, axis2); plot.setDataset(1, dataset2); plot.mapDatasetToRangeAxis(1, 1); final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer(); renderer2.setSeriesPaint(0, Color.BLUE); plot.setRenderer(1, renderer2); final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file = new File( statisticsDirectory + "PDF Signatures" + "-" + xRow + "" + y1Row + "" + y2Row + ".png"); int imageWidth = 800; int imageHeight = 600; try { System.out.println("Writing diagram to " + file.getName()); System.out.flush(); ChartUtilities.saveChartAsPNG(file, chart, imageWidth, imageHeight, info); } catch (IOException e) { e.printStackTrace(); } }
From source file:playground.dgrether.analysis.charts.DgAvgDeltaUtilsQuantilesChart.java
private XYSeriesCollection createDatasets(String runId1, String runId2) { XYSeriesCollection ds = new XYSeriesCollection(); Tuple<XYSeries, List<String>> seriesLabels = this.createXYSeries("Mean " + '\u0394' + "Utility", this.ana, runId1, runId2);//from w w w . ja v a 2 s .c om ds.addSeries(seriesLabels.getFirst()); this.labelGenerator.setLabels(0, seriesLabels.getSecond()); return ds; }
From source file:ch.zhaw.ias.dito.ui.AnalysisPanel.java
private JFreeChart createEigenvaluesChart(String title, EigenvalueDecomposition decomp) { double[] values = decomp.getSortedEigenvalues(); XYSeries series = new XYSeries("Series 1"); for (int i = 0; i < values.length; i++) { series.add((i + 1), values[i]);//w ww . j a v a 2s .com } XYSeriesCollection collection = new XYSeriesCollection(); collection.addSeries(series); XYBarDataset dataset = new XYBarDataset(collection, 0.9); return ChartFactory.createXYBarChart(title, null, false, null, dataset, PlotOrientation.VERTICAL, false, true, false); }
From source file:cs.register.geraGrafico.java
private XYSeriesCollection datakda(List<partida> list1) { XYSeriesCollection data = new XYSeriesCollection(); XYSeries ser = new XYSeries("kda"); for (partida p : list1) { ser.add(list1.indexOf(p) + 1, (p.getKill() / p.getDeath())); }/*from ww w . ja v a 2 s .c om*/ data.addSeries(ser); return data; }
From source file:edu.ucla.stat.SOCR.chart.demo.QQData2DataDemo.java
/** * Creates a sample dataset.//from w ww . j a v a 2 s . c o m * * @return a sample dataset. */ protected XYDataset createDataset(boolean isDemo) { if (isDemo) { larger_row_count = 10; x_row_count = 10; y_row_count = 8; raw_x = new String[x_row_count]; raw_y = new String[y_row_count]; raw_x[0] = "95"; raw_x[1] = "104"; raw_x[2] = "99"; raw_x[3] = "102"; raw_x[4] = "95"; raw_x[5] = "106"; raw_x[6] = "100"; raw_x[7] = "108"; raw_x[8] = "104"; raw_x[9] = "97"; raw_y[0] = "97"; raw_y[1] = "98"; raw_y[2] = "92"; raw_y[3] = "94"; raw_y[4] = "93"; raw_y[5] = "106"; raw_y[6] = "94"; raw_y[7] = "109"; do_dd(); XYSeries series1 = new XYSeries("QQ"); //for (int i=0; i<row_count; i++){ int len = normalQuantiles.length; for (int i = 0; i < len; i++) { //System.out.println("i="+i+" x="+normalQuantiles[i]+" y="+stdResiduals[i]); series1.add(normalQuantiles[i], stdResiduals[i]); } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series1); try { XYSeries series2 = new XYSeries("Reference Line"); RegressionLine refLine = new RegressionLine(normalQuantiles, stdResiduals); double intercept = refLine.getIntercept(); double slope = refLine.getSlope(); min_x = Math.min(normalQuantiles[0], stdResiduals[0]); double min_y = slope * min_x + intercept; max_x = Math.max(normalQuantiles[len - 1], stdResiduals[len - 1]); //max_x = Math.max (normalQuantiles[row_count-1],stdResiduals[row_count-1]); double max_y = slope * max_x + intercept; series2.add(min_x, min_y); series2.add(max_x, max_y); dataset.addSeries(series2); } catch (DataException e) { System.out.println("cought dataException"); e.printStackTrace(); } return dataset; } else return super.createDataset(false); }
From source file:GeMSE.Visualization.ElbowPlot.java
public void Plot(ArrayList<Double[]> pvData, ArrayList<Double[]> dData, int cut) { double maxY = 0; float[] secYColor = new float[3]; Color.RGBtoHSB(153, 245, 255, secYColor); float[] priYColor = new float[3]; Color.RGBtoHSB(255, 255, 255, priYColor); float[] cutColor = new float[3]; Color.RGBtoHSB(255, 255, 0, cutColor); //create the series - add some dummy data XYSeries pvSeries = new XYSeries("Percentage of variance "); for (int i = 1; i < pvData.size(); i++) { pvSeries.add(pvData.get(i)[0], pvData.get(i)[1]); maxY = Math.max(maxY, pvData.get(i)[1]); }//from w w w.j a va 2 s . c o m XYSeries dSeries = new XYSeries("Percentage of differences between slopes "); for (int i = 0; i < dData.size(); i++) dSeries.add(dData.get(i)[0], dData.get(i)[1]); XYSeries cutSeries = new XYSeries("Cut "); cutSeries.add(cut, 0.0); cutSeries.add(cut, maxY); //create the datasets XYSeriesCollection pvDataSeries = new XYSeriesCollection(); pvDataSeries.addSeries(pvSeries); XYSeriesCollection cutDataSeries = new XYSeriesCollection(); cutDataSeries.addSeries(cutSeries); XYSeriesCollection dDataSeries = new XYSeriesCollection(); dDataSeries.addSeries(dSeries); //construct the plot XYPlot plot = new XYPlot(); plot.setDataset(0, pvDataSeries); plot.setDataset(1, cutDataSeries); plot.setDataset(2, dDataSeries); // use XYSplineRenderer if you want to smooth the lines. XYLineAndShapeRenderer pvRenderer = new XYLineAndShapeRenderer(); pvRenderer.setSeriesPaint(0, Color.getHSBColor(priYColor[0], priYColor[1], priYColor[2])); BasicStroke dstroke = new BasicStroke(2.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 1.0f, 10.0f }, 0.0f); XYLineAndShapeRenderer dRenderer = new XYLineAndShapeRenderer(); dRenderer.setSeriesPaint(0, Color.getHSBColor(secYColor[0], secYColor[1], secYColor[2])); dRenderer.setSeriesStroke(0, dstroke); BasicStroke cutStoke = new BasicStroke(4); // use XYSplineRenderer if you want to smooth the lines. //XYSplineRenderer cutRenderer = new XYSplineRenderer(); XYLineAndShapeRenderer cutRenderer = new XYLineAndShapeRenderer(); cutRenderer.setSeriesPaint(0, Color.getHSBColor(cutColor[0], cutColor[1], cutColor[2])); cutRenderer.setSeriesStroke(0, cutStoke); plot.setRenderer(0, pvRenderer); plot.setRenderer(1, cutRenderer); plot.setRenderer(2, dRenderer); plot.setRangeAxis(0, new NumberAxis("\n\nPercentage of Variance")); plot.setRangeAxis(1, new NumberAxis("Percentage of Difference Between Slopes")); plot.setDomainAxis(new NumberAxis("Number of Clusters\n\n")); //Map the data to the appropriate axis plot.mapDatasetToRangeAxis(0, 0); plot.mapDatasetToRangeAxis(1, 0); plot.mapDatasetToRangeAxis(2, 1); float[] hsbValues = new float[3]; Color.RGBtoHSB(16, 23, 67, hsbValues); plot.setBackgroundPaint(Color.getHSBColor(hsbValues[0], hsbValues[1], hsbValues[2])); Font axisLabelFont = new Font("Dialog", Font.PLAIN, 14); Font axisTickLabelFont = new Font("Dialog", Font.PLAIN, 12); Font legendFont = new Font("Dialog", Font.PLAIN, 14); plot.setDomainGridlinePaint(Color.gray); plot.setRangeGridlinePaint(Color.gray); plot.getDomainAxis().setTickLabelPaint(Color.white); plot.getDomainAxis().setLabelPaint(Color.white); plot.getDomainAxis().setLabelFont(axisLabelFont); plot.getDomainAxis().setTickLabelFont(axisTickLabelFont); plot.getRangeAxis().setTickLabelPaint(Color.getHSBColor(priYColor[0], priYColor[1], priYColor[2])); plot.getRangeAxis().setLabelPaint(Color.getHSBColor(priYColor[0], priYColor[1], priYColor[2])); plot.getRangeAxis().setLabelFont(axisLabelFont); plot.getRangeAxis().setTickLabelFont(axisTickLabelFont); plot.getRangeAxis(1).setTickLabelPaint(Color.getHSBColor(secYColor[0], secYColor[1], secYColor[2])); plot.getRangeAxis(1).setLabelPaint(Color.getHSBColor(secYColor[0], secYColor[1], secYColor[2])); plot.getRangeAxis(1).setLabelFont(axisLabelFont); plot.getRangeAxis(1).setTickLabelFont(axisTickLabelFont); //generate the chart JFreeChart chart = new JFreeChart("\nSuggested number of clusters determined using Elbow method", getFont(), plot, true); chart.getTitle().setPaint(Color.white); chart.getLegend().setBackgroundPaint(Color.black); chart.getLegend().setItemPaint(Color.white); chart.getLegend().setPosition(RectangleEdge.BOTTOM); chart.getLegend().setItemFont(legendFont); float[] hsbValues2 = new float[3]; Color.RGBtoHSB(36, 43, 87, hsbValues2); chart.setBackgroundPaint(Color.getHSBColor(hsbValues2[0], hsbValues2[1], hsbValues2[2])); JPanel chartPanel = new ChartPanel(chart); GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); chartPanel.setPreferredSize( new java.awt.Dimension((int) Math.round((gd.getDisplayMode().getWidth() * 1.5) / 3.0), (int) Math.round((gd.getDisplayMode().getHeight() * 1.5) / 3.0))); setContentPane(chartPanel); }
From source file:org.gephi.statistics.plugin.WeightedDegree.java
public String getReport() { String report = ""; if (isDirected) { report = getDirectedReport();// ww w . j a v a 2 s . co m } else { //Distribution series XYSeries dSeries = ChartUtils.createXYSeries(degreeDist, "Degree Distribution"); XYSeriesCollection dataset1 = new XYSeriesCollection(); dataset1.addSeries(dSeries); JFreeChart chart1 = ChartFactory.createXYLineChart("Degree Distribution", "Value", "Count", dataset1, PlotOrientation.VERTICAL, true, false, false); chart1.removeLegend(); ChartUtils.decorateChart(chart1); ChartUtils.scaleChart(chart1, dSeries, false); String degreeImageFile = ChartUtils.renderChart(chart1, "w-degree-distribution.png"); NumberFormat f = new DecimalFormat("#0.000"); report = "<HTML> <BODY> <h1>Weighted Degree Report </h1> " + "<hr>" + "<br> <h2> Results: </h2>" + "Average Weighted Degree: " + f.format(avgWDegree) + "<br /><br />" + degreeImageFile + "</BODY></HTML>"; } return report; }