List of usage examples for org.jfree.data.xy XYSeries add
public void add(XYDataItem item, boolean notify)
From source file:org.broad.igv.peaks.PeakTrackMenu.java
void openTimeSeriesPlot(TrackClickEvent trackClickEvent) { if (trackClickEvent == null) return;/*from w w w .j a va 2s. co m*/ ReferenceFrame referenceFrame = trackClickEvent.getFrame(); if (referenceFrame == null) return; String chr = referenceFrame.getChrName(); double position = trackClickEvent.getChromosomePosition(); XYSeriesCollection data = new XYSeriesCollection(); List<Color> colors = new ArrayList(); for (SoftReference<PeakTrack> ref : PeakTrack.instances) { PeakTrack track = ref.get(); if (track != null) { Peak peak = track.getFilteredPeakNearest(chr, position); if (peak != null) { XYSeries series = new XYSeries(track.getName()); float[] scores = peak.getTimeScores(); if (scores.length == 4) { float t0 = scores[0] + 10; series.add(0, (scores[0] + 10) / t0); series.add(30, (scores[1] + 10) / t0); series.add(60, (scores[2] + 10) / t0); series.add(120, (scores[3] + 10) / t0); } data.addSeries(series); Color c = track.getName().contains("Pol") ? Color.black : track.getColor(); colors.add(c); } } } final JFreeChart chart = ChartFactory.createXYLineChart("", "Time", "Score", data, PlotOrientation.VERTICAL, true, true, false); NumberAxis axis = (NumberAxis) chart.getXYPlot().getDomainAxis(0); axis.setTickUnit(new NumberTickUnit(30)); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(400, 400)); chartPanel.setSize(new java.awt.Dimension(400, 400)); XYItemRenderer renderer = chart.getXYPlot().getRenderer(); for (int i = 0; i < colors.size(); i++) { renderer.setSeriesPaint(i, colors.get(i)); } chartPanel.setBackground(Color.white); chart.getXYPlot().setBackgroundPaint(Color.white); chart.getXYPlot().setRangeGridlinePaint(Color.black); PeakTimePlotFrame frame = new PeakTimePlotFrame(chartPanel); frame.setVisible(true); }
From source file:XYPlotter.java
/** * //from www. j av a 2 s. c o m * Update data of series1 (function-values) and series2 (markingpoints such like minima, maxima etc.) */ @Override public void updateData(double[] x, double[] y, double[] marksX, double[] marksY) { XYSeries series1 = new XYSeries("f(x)"); XYSeries series2 = new XYSeries("g(x)"); if (x.length == y.length) for (int i = 0; i < x.length; i++) series1.add(x[i], y[i]); else { JOptionPane.showMessageDialog(null, "Array sizes of x1 and y1 are not equal!"); System.err.println("Array sizes of x and y are not equal!"); } if (marksX.length == marksY.length) for (int i = 0; i < marksX.length; i++) series2.add(marksX[i], marksY[i]); else { JOptionPane.showMessageDialog(null, "Array sizes of marking coordinates are not equal!"); System.err.println("Array sizes of marking coordinates are not equal!"); } updateDataset(series1, series2); }
From source file:researchbehaviour.ChangePanel.java
private XYDataset createDataset() throws IOException { XYSeries series1 = new XYSeries("Default"); series1.add(1, 57.87); series1.add(2, 59.842);//ww w . j a v a 2 s. c o m series1.add(3, 68.5); series1.add(4, 74.625); series1.add(5, 79.235); ChangeValues cvv = new ChangeValues(); ArrayList<Double> updateVal1 = new ArrayList<Double>(); updateVal1 = cvv.changedCutOff(); XYSeries series2 = new XYSeries("Current"); series2.add(1, updateVal1.get(0)); series2.add(2, updateVal1.get(1)); series2.add(3, updateVal1.get(2)); series2.add(4, updateVal1.get(3)); series2.add(5, updateVal1.get(4)); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series1); dataset.addSeries(series2); return dataset; }
From source file:com.romraider.logger.ecu.ui.handler.graph.GraphUpdateHandler.java
public synchronized void handleDataUpdate(final Response response) { for (final LoggerData loggerData : response.getData()) { final XYSeries series = seriesMap.get(loggerData); if (series != null && !paused) { SwingUtilities.invokeLater(new Runnable() { public void run() { series.add((response.getTimestamp() - startTime) / 1000.0, response.getDataValue(loggerData)); }//from www .java 2 s .co m }); } } }
From source file:playground.christoph.evacuation.analysis.AgentsInEvacuationAreaWriter.java
/** * @return a graphic showing the number of agents in the evacuated area */// w w w . ja v a 2 s.c o m private JFreeChart getGraphic(String[] modeNames, int inputData[][]) { /* * Write only the number of defined picture bins to the plot. */ int data[][]; data = new int[inputData.length][]; for (int i = 0; i < inputData.length; i++) { if (inputData[i].length > this.nofPictureBins) { data[i] = Arrays.copyOfRange(inputData[i], 0, this.nofPictureBins); } else data[i] = inputData[i]; } final XYSeriesCollection xyData = new XYSeriesCollection(); for (int j = 0; j < modeNames.length; j++) { String modeName = modeNames[j]; int[] d = data[j]; XYSeries dataSerie = new XYSeries(modeName, false, true); for (int i = 0; i < d.length; i++) { double hour = i * this.binSize / 60.0 / 60.0; dataSerie.add(hour, d[i]); } xyData.addSeries(dataSerie); } final JFreeChart chart = ChartFactory.createXYStepChart( "agents in evacuated area, all modes, 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:BaselinePlotGenerator.java
private JFreeChart createChart(String filename, NssBaseline nssBaseline) { XYSeries series = new XYSeries(""); float[] baselineValues = nssBaseline.getBaselineValues(); // plot subband values for (int i = 0; i < baselineValues.length; i++) { series.add(i, baselineValues[i]); }/* www.j a v a2 s. c o m*/ // add a final point at the end with a zero Y value, // to force the y axis to display full scale series.add(baselineValues.length, 0.0); XYDataset data = new XYSeriesCollection(series); String title = "SonATA Baseline"; String xAxisLabel = "Subband"; String yAxisLabel = "Power"; JFreeChart chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, data, PlotOrientation.VERTICAL, false, // legend true, // tooltips false // urls ); String filenameBase = new File(filename).getName(); String subTitle1 = filenameBase; chart.addSubtitle(new TextTitle(subTitle1)); DecimalFormat freqFormatter = new DecimalFormat("0000.000 MHz "); String freqString = freqFormatter.format(nssBaseline.getCenterFreqMhz()); DecimalFormat bandwidthFormatter = new DecimalFormat("0.00 MHz "); String bandwidthString = bandwidthFormatter.format(nssBaseline.getBandwidthMhz()); String subTitle2 = "Center Freq: " + freqString + " Bandwidth: " + bandwidthString; chart.addSubtitle(new TextTitle(subTitle2)); // move the data off of the axes // by extending the minimum axis value XYPlot plot = (XYPlot) ((JFreeChart) chart).getPlot(); double axisMarginPercent = 0.02; NumberAxis valueAxis = (NumberAxis) plot.getRangeAxis(); valueAxis.setLowerBound(-1.0 * valueAxis.getUpperBound() * axisMarginPercent); valueAxis = (NumberAxis) plot.getDomainAxis(); valueAxis.setLowerBound(-1.0 * valueAxis.getUpperBound() * axisMarginPercent); return chart; }
From source file:org.jfree.data.xy.junit.XYSeriesCollectionTest.java
/** * A test to cover bug 3445507. The issue does not affact * XYSeriesCollection./* w w w . jav a 2s .c o m*/ */ 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:org.knime.knip.core.ui.imgviewer.panels.HistogramBC.java
/** * Returns a JFreeChart containing data from the provided histogram. * * @param title/*w ww.j av a 2 s . c om*/ * @param bund * @return */ private JFreeChart getChart(final String title, final HistogramBundle bund) { List<XYSeries> series = new ArrayList<>(); for (int h = 0; h < bund.getHistogramCount(); h++) { final XYSeries xys = new XYSeries("histo" + h); final long total = bund.getHistogram(h).getBinCount(); for (long i = 0; i < total; i++) { xys.add(i, bund.getHistogram(h).frequency(i)); } series.add(xys); } final JFreeChart chart = createChart(title, series); if (bund.getMinBin() != -1) { chart.getXYPlot().addDomainMarker(new ValueMarker(bund.getMinBin(), Color.black, new BasicStroke(1))); } if (bund.getMaxBin() != -1) { chart.getXYPlot().addDomainMarker(new ValueMarker(bund.getMaxBin(), Color.black, new BasicStroke(1))); } if (displaySlopeLine(bund)) { chart.getXYPlot().addAnnotation(slopeLine()); } // set to knime gray chart.setBackgroundPaint(new Color(238, 238, 238)); return chart; }
From source file:org.owasp.benchmark.score.report.Scatter.java
private JFreeChart display(String title, int height, int width, OverallResults or) { JFrame f = new JFrame(title); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Note: this is a little weird, since each point is a separate series XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries("Scores"); for (OverallResult r : or.getResults()) { series.add(r.fpr * 100, r.tpr * 100); }//from ww w . ja va2 s.c om dataset.addSeries(series); chart = ChartFactory.createScatterPlot(title, "False Positive Rate", "True Positive Rate", dataset, PlotOrientation.VERTICAL, true, true, false); String fontName = "Arial"; DecimalFormat pctFormat = new DecimalFormat("0'%'"); theme = (StandardChartTheme) org.jfree.chart.StandardChartTheme.createJFreeTheme(); theme.setExtraLargeFont(new Font(fontName, Font.PLAIN, 24)); // title theme.setLargeFont(new Font(fontName, Font.PLAIN, 20)); // axis-title theme.setRegularFont(new Font(fontName, Font.PLAIN, 16)); theme.setSmallFont(new Font(fontName, Font.PLAIN, 12)); theme.setRangeGridlinePaint(Color.decode("#C0C0C0")); theme.setPlotBackgroundPaint(Color.white); theme.setChartBackgroundPaint(Color.white); theme.setGridBandPaint(Color.red); theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); theme.setBarPainter(new StandardBarPainter()); theme.setAxisLabelPaint(Color.decode("#666666")); theme.apply(chart); XYPlot xyplot = chart.getXYPlot(); NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis(); NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis(); xyplot.setOutlineVisible(true); rangeAxis.setRange(-9.99, 109.99); rangeAxis.setNumberFormatOverride(pctFormat); rangeAxis.setTickLabelPaint(Color.decode("#666666")); rangeAxis.setMinorTickCount(5); rangeAxis.setTickUnit(new NumberTickUnit(10)); rangeAxis.setAxisLineVisible(true); rangeAxis.setMinorTickMarksVisible(true); rangeAxis.setTickMarksVisible(true); rangeAxis.setLowerMargin(10); rangeAxis.setUpperMargin(10); xyplot.setRangeGridlineStroke(new BasicStroke()); xyplot.setRangeGridlinePaint(Color.lightGray); xyplot.setRangeMinorGridlinePaint(Color.decode("#DDDDDD")); xyplot.setRangeMinorGridlinesVisible(true); domainAxis.setRange(-5, 105); domainAxis.setNumberFormatOverride(pctFormat); domainAxis.setTickLabelPaint(Color.decode("#666666")); domainAxis.setMinorTickCount(5); domainAxis.setTickUnit(new NumberTickUnit(10)); domainAxis.setAxisLineVisible(true); domainAxis.setTickMarksVisible(true); domainAxis.setMinorTickMarksVisible(true); domainAxis.setLowerMargin(10); domainAxis.setUpperMargin(10); xyplot.setDomainGridlineStroke(new BasicStroke()); xyplot.setDomainGridlinePaint(Color.lightGray); xyplot.setDomainMinorGridlinePaint(Color.decode("#DDDDDD")); xyplot.setDomainMinorGridlinesVisible(true); chart.setTextAntiAlias(true); chart.setAntiAlias(true); chart.removeLegend(); chart.setPadding(new RectangleInsets(20, 20, 20, 20)); xyplot.getRenderer().setSeriesPaint(0, Color.decode("#4572a7")); // // setup item labels // XYItemRenderer renderer = xyplot.getRenderer(); // Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 7.0f, 7.0f); // for ( int i = 0; i < dataset.getSeriesCount(); i++ ) { // renderer.setSeriesShape(i, circle); // renderer.setSeriesPaint(i, Color.blue); // String letter = "" + ((String)dataset.getSeries(i).getKey()).charAt(0); // StandardXYItemLabelGenerator generator = new StandardXYItemLabelGenerator(letter); // renderer.setSeriesItemLabelGenerator(i, generator); // renderer.setSeriesItemLabelsVisible(i, true); // ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER ); // renderer.setSeriesPositiveItemLabelPosition(i, position); // } makeDataLabels(or, xyplot); makeLegend(or, 57, 48, dataset, xyplot); // put legend inside plot // LegendTitle lt = new LegendTitle(xyplot); // lt.setItemFont(theme.getSmallFont()); // lt.setPosition(RectangleEdge.RIGHT); // lt.setItemFont(theme.getSmallFont()); // XYTitleAnnotation ta = new XYTitleAnnotation(.7, .55, lt, RectangleAnchor.TOP_LEFT); // ta.setMaxWidth(0.48); // xyplot.addAnnotation(ta); // draw guessing line Stroke dashed = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 6, 3 }, 0); XYLineAnnotation guessing = new XYLineAnnotation(-5, -5, 105, 105, dashed, Color.red); xyplot.addAnnotation(guessing); XYPointerAnnotation worse = makePointer(75, 0, "Worse than guessing", TextAnchor.TOP_CENTER, 90); xyplot.addAnnotation(worse); XYPointerAnnotation better = makePointer(25, 100, "Better than guessing", TextAnchor.BOTTOM_CENTER, 270); xyplot.addAnnotation(better); XYTextAnnotation time = new XYTextAnnotation("Tool run time: " + or.getTime(), 12, -5.6); time.setTextAnchor(TextAnchor.TOP_LEFT); time.setFont(theme.getRegularFont()); time.setPaint(Color.red); xyplot.addAnnotation(time); XYTextAnnotation stroketext = new XYTextAnnotation(" Random Guess", 88, 107); stroketext.setTextAnchor(TextAnchor.CENTER_RIGHT); stroketext.setBackgroundPaint(Color.white); stroketext.setPaint(Color.red); stroketext.setFont(theme.getRegularFont()); xyplot.addAnnotation(stroketext); XYLineAnnotation strokekey = new XYLineAnnotation(58, 107, 68, 107, dashed, Color.red); xyplot.setBackgroundPaint(Color.white); xyplot.addAnnotation(strokekey); ChartPanel cp = new ChartPanel(chart, height, width, 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:com.comcast.cmb.common.controller.EndpointServlet.java
private byte[] generateChart(EndpointMetrics metric, String id) throws IOException { XYSeries series = new XYSeries("Test Run"); for (int i = 0; i < metric.timeSeries.size(); i++) { series.add(i, metric.timeSeries.get(i)); }/*from w w w. j a v a2s. com*/ XYSeriesCollection dataset = new XYSeriesCollection(series); JFreeChart chart = ChartFactory.createXYBarChart( "Start: " + metric.startTime + " End: " + metric.endTime + " Message Count: " + metric.messageCount, "Test Second", false, "Number of Messages", dataset, PlotOrientation.VERTICAL, true, true, false); //File file = new File(getServletContext().getRealPath("WEB-INF" + "/" + id + ".jpeg")); //ChartUtilities.saveChartAsJPEG(file, chart, 1600, 400); //byte b[] = Files.toByteArray(file); //return b; ByteArrayOutputStream bos = new ByteArrayOutputStream(); ChartUtilities.writeChartAsJPEG(bos, chart, 2400, 400); return bos.toByteArray(); }