List of usage examples for org.jfree.data.xy XYSeriesCollection XYSeriesCollection
public XYSeriesCollection()
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 ww w.j av a2s . 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:com.ivli.roim.controls.ChartView.java
protected void initChart() { if (null != iPlot) { ((XYSeriesCollection) iPlot.getDataset()).removeAllSeries(); } else {/*from www. ja v a 2 s.c om*/ iPlot = new XYPlot(); iPlot.setRenderer(new StandardXYItemRenderer()); iPlot.setDomainAxis(new NumberAxis(java.util.ResourceBundle.getBundle("com/ivli/roim/Bundle") .getString("ROI_CHART.TIME_SERIES_VALUES"))); iPlot.setRangeAxis(0, new NumberAxis(java.util.ResourceBundle.getBundle("com/ivli/roim/Bundle") .getString("ROI_CHART.ROI_INTDEN_VALUES"))); iPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); iPlot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_LEFT); iJfc = new JFreeChart( java.util.ResourceBundle.getBundle("com/ivli/roim/Bundle").getString("ROI_CHART.CHART_TITLE"), iPlot); iChart = new ChartControl(iJfc); iPlot.setDataset(new XYSeriesCollection()); iChart.setPreferredSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)); iChart.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)); setLayout(new BorderLayout()); this.add(iChart); } iChart.setMouseZoomable(false); iChart.setMouseWheelEnabled(true); }
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 w ww . j a v a2s. c o m*/ 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:regression.gui.RegressionChart.java
/** * Creates a sample dataset./*from w w w. ja v a 2s .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:br.prof.salesfilho.oci.image.GraphicBuilder.java
public void createCombinedChart(Map<String, double[]> mapSeries, String legendTitle) { XYSeriesCollection xds;/* w w w. j a va2 s .c o m*/ final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis(legendTitle)); plot.setGap(10.0); for (Map.Entry<String, double[]> entrySet : mapSeries.entrySet()) { String serieName = entrySet.getKey(); double[] values = entrySet.getValue(); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); final XYSeries series = new XYSeries(serieName); for (int i = 0; i < values.length; i++) { series.add(i, Precision.round(values[i], 2)); renderer.setSeriesVisible(i, true, true); renderer.setSeriesShapesVisible(i, true); } xds = new XYSeriesCollection(); xds.addSeries(series); final NumberAxis rangeAxis = new NumberAxis(serieName); final XYPlot subplot = new XYPlot(xds, null, rangeAxis, renderer); subplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); plot.add(subplot); } this.chart = new JFreeChart(this.title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); chartPanel.setChart(chart); }
From source file:com.artnaseef.jmeter.report.ResultCodesPerSecondReport.java
@Override public void onFeedStart(String uri, Properties reportProperties) throws Exception { this.feedUri = uri; this.extractReportProperties(reportProperties); this.chartSeries = new LinkedList<>(); this.samplesByReportCode = new TreeMap<>(); this.dataset = new XYSeriesCollection(); if (this.detailOutputFile != null) { this.detailFileWriter = new PrintStream(this.detailOutputFile); }/*from ww w. j a v a2 s .c o m*/ }
From source file:P251.graphPanel.java
/** Constructor/* ww w .j av a 2 s. c o m*/ @param width width of the graph in the applet @param height height of the graph in the applet @param legend to include a legend */ public graphPanel(int width, int height, Boolean legend) { // setLayout( new FlowLayout()); dataset = new XYSeriesCollection(); chart = new ChartPanel(ChartFactory.createScatterPlot("XY Chart", // Title "x-axis", // x-axis Label "y-axis", // y-axis Label dataset, legend)); chart.getChart().getXYPlot().setRenderer(new XYDotRenderer()); ; setBackgroudColor(Color.white); setGridColor(Color.black); chart.setPreferredSize(new Dimension(width - 10, height - 10)); add(chart); setPreferredSize(new Dimension(width, height)); }
From source file:evaluation.simulator.gui.results.LineJFreeChartCreator.java
private static XYDataset createDataset() { final XYSeries series1 = new XYSeries("AVG"); series1.add(1.0, 1.0);//from w w w . j av a 2 s . c o m 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); final XYSeries series2 = new XYSeries("Min AVG"); series2.add(1.0, 0.5); series2.add(2.0, 2.0); series2.add(3.0, 1.5); series2.add(4.0, 2.5); series2.add(5.0, 2.5); series2.add(6.0, 3.5); series2.add(7.0, 3.5); series2.add(8.0, 4.0); final XYSeries series3 = new XYSeries("Max AVG"); series3.add(1.0, 2.0); series3.add(2.0, 8.0); series3.add(3.0, 6.0); series3.add(4.0, 10.0); series3.add(5.0, 10.0); series3.add(6.0, 14.0); series3.add(7.0, 14.0); series3.add(8.0, 16.0); final XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series1); dataset.addSeries(series2); dataset.addSeries(series3); return dataset; }
From source file:ip.ui.plot.PlotGenerator.java
public void generateResultsChart(ResultsPlotData data, String fileName) throws IOException { XYSeries expectedData = new XYSeries("Expected output"); XYSeries networkData = new XYSeries("Network output"); List<double[]> inputs = new ArrayList(data.getInputs().size()); data.getInputs().stream().forEach((InputRow row) -> { inputs.add(row.getValues());//from w w w . ja v a2 s . c o m }); List<double[]> expectedOutputs = new ArrayList(data.getInputs().size()); data.getInputs().stream().forEach((InputRow row) -> { expectedOutputs.add(row.getExpectedOutput()); }); List<double[]> outputs = data.getOutputs(); for (int i = 0; i < inputs.size(); ++i) { expectedData.add(inputs.get(i)[0], expectedOutputs.get(i)[0]); networkData.add(inputs.get(i)[0], outputs.get(i)[0]); } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(expectedData); dataset.addSeries(networkData); JFreeChart chart = ChartFactory.createXYLineChart(data.getPlotName(), data.getxAxisLabel(), data.getyAxisLabel(), dataset, PlotOrientation.VERTICAL, true, true, true); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesLinesVisible(1, false); chart.getXYPlot().setRenderer(renderer); File XYChart = new File(fileName); ChartUtilities.saveChartAsJPEG(XYChart, chart, chartWidth, chartHeight); }
From source file:org.physionet.wfdb.examples.PlotECGQRSDemo2.java
public static XYDataset createDataset() { XYSeriesCollection result = new XYSeriesCollection(); XYSeries ecgSignal = new XYSeries(1); XYSeries ecgAnnotation = new XYSeries(2); String recordName = "mitdb/100"; int N = 5000; Double mxEcg = (double) 0; //Get ECG data from WFDB in number of samples Rdsamp rdsampexec = new Rdsamp(); rdsampexec.setArgumentValue(Rdsamp.Arguments.stopTime, "s" + N); //Print time in second and values in high precision rdsampexec.setArgumentValue(Rdsamp.PrintTimeFormatLabel.P); rdsampexec.setArgumentValue(Rdsamp.Arguments.recordName, recordName); ArrayList[] results = rdsampexec.execTo2DString(); //Insert data into plotting series Double ecgSamp;/*from w w w .ja v a 2 s . com*/ for (int n = 0; n < results[1].size(); n++) { ecgSamp = Double.valueOf((String) results[1].get(n)); ecgSignal.add(n, ecgSamp); mxEcg = (mxEcg > ecgSamp) ? mxEcg : ecgSamp; } result.addSeries(ecgSignal); //Get the QRS annotations Wqrs wqrsExec = new Wqrs(); wqrsExec.setArgumentValue(Wqrs.Arguments.recordName, recordName); wqrsExec.setArgumentValue(Wqrs.Arguments.stopTime, "s" + N); wqrsExec.execToString(); //The annotation file will be stored at the current directory (./mitdb/100.wqrs) //Use RDANN to read the annotation file and store values in memory Rdann rdannExec = new Rdann(); rdannExec.setArgumentValue(Rdann.Arguments.annotator, "wqrs"); rdannExec.setArgumentValue(Rdann.Arguments.recordName, recordName); ArrayList<String> annotations = rdannExec.execToStringList(); String[] tmpArr; for (String temp : annotations) { tmpArr = temp.split("\\s+"); ecgAnnotation.add(Double.valueOf(tmpArr[2]), mxEcg); } result.addSeries(ecgAnnotation); return result; }