List of usage examples for org.jfree.data.xy XYSeriesCollection XYSeriesCollection
public XYSeriesCollection()
From source file:org.encog.workbench.dialogs.activation.EquationPanel.java
/** * Creates a dataset with sample values from the normal distribution * function./*from ww w . j a v a 2 s . c o m*/ * * @return A dataset. */ public static XYDataset createDataset(ActivationFunction activation, boolean normal) { XYSeriesCollection dataset = new XYSeriesCollection(); if (normal) { Function2D n1 = new ActivationFunction2D(activation);// //new NormalDistributionFunction2D(0.0, 1.0); XYSeries s1 = DatasetUtilities.sampleFunction2DToSeries(n1, -5.1, 5.1, 121, "Activation Function"); dataset.addSeries(s1); } else { if (activation.hasDerivative()) { Function2D n2 = new DerivativeFunction2D(activation); XYSeries s2 = DatasetUtilities.sampleFunction2DToSeries(n2, -5.1, 5.1, 121, "Derivative Function"); dataset.addSeries(s2); } } return dataset; }
From source file:PerformanceGraph.java
/** * Plots the performance graph of the best fitness value so far versus the * number of function calls (NFC)./*from ww w. j a v a2s . com*/ * * @param bestFitness A linked hashmap mapping the NFC to the best fitness value * found so far. * @param fitnessFunction The name of the fitness function, used for the title and the * name of the file that is saved, e.g. "De Jong". */ public static void plot(LinkedHashMap<Integer, Double> bestFitness, String fitnessFunction) { /* Create an XYSeries plot */ XYSeries series = new XYSeries("Best Fitness Value Vs. Number of Function Calls"); /* Add the NFC and best fitness value data to the series */ for (Integer NFC : bestFitness.keySet()) { /* Jfreechart crashes if double values are too large! */ if (bestFitness.get(NFC) <= 10E12) { series.add(NFC.doubleValue(), bestFitness.get(NFC).doubleValue()); } } /* Add the x,y series data to the dataset */ XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); /* Plot the data as an X,Y line chart */ JFreeChart chart = ChartFactory.createXYLineChart("Best Fitness Value Vs. Number of Function Calls", "Number of Function Calls (NFC)", "Best Fitness Value", dataset, PlotOrientation.VERTICAL, false, true, false); /* Configure the chart settings such as anti-aliasing, background colour */ chart.setAntiAlias(true); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); plot.setDomainGridlinePaint(Color.black); /* Set the domain range from 0 to NFC */ NumberAxis domain = (NumberAxis) plot.getDomainAxis(); domain.setRange(0.0, ControlVariables.MAX_FUNCTION_CALLS.doubleValue()); /* Logarithmic range axis */ plot.setRangeAxis(new LogAxis()); /* Set the thickness and colour of the lines */ XYItemRenderer renderer = plot.getRenderer(); BasicStroke thickLine = new BasicStroke(3.0f); renderer.setSeriesStroke(0, thickLine); renderer.setPaint(Color.BLACK); /* Display the plot in a JFrame */ ChartFrame frame = new ChartFrame(fitnessFunction + " Best Fitness Value", chart); frame.setVisible(true); frame.setSize(1000, 600); /* Save the plot as an image named after fitness function try { ChartUtilities.saveChartAsJPEG(new File("plots/" + fitnessFunction + ".jpg"), chart, 1600, 900); } catch (IOException e) { e.printStackTrace(); }*/ }
From source file:FreeMemoryViewer.java
private XYDataset createDataset() { used = new XYSeries("Used"); total = new XYSeries("Total"); free = new XYSeries("Free"); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(used);//from w w w . j a v a 2s . c om dataset.addSeries(total); dataset.addSeries(free); return dataset; }
From source file:org.ensor.robots.apps.pidcallibrator.MainPanel.java
/** * Creates new form MainPanel//from ww w .j a va 2 s .co m */ public MainPanel() { initComponents(); XYSeriesCollection collection = new XYSeriesCollection(); XYSeries setPoints = new XYSeries("Set Points"); setPoints.add(10, 0); setPoints.add(20, 10); setPoints.add(30, 5); setPoints.add(40, 20); collection.addSeries(setPoints); XYSeries actualPoints = new XYSeries("Actual Points"); actualPoints.add(5, 0); actualPoints.add(15, 5); actualPoints.add(40, 50); collection.addSeries(actualPoints); JFreeChart scatterPlot = ChartFactory.createScatterPlot("Angle PID tracking", "Time", "Angle", collection); ChartPanel cp = new ChartPanel(scatterPlot); mChart.setLayout(new BorderLayout()); mChart.add(cp, BorderLayout.CENTER); mChart.validate(); cp.setSize(mChart.getSize()); }
From source file:netplot.BarPlotPanel.java
private JFreeChart createChart() { collection = new XYSeriesCollection(); collection.addSeries(series);// ww w . ja v a2 s.c o m dataset = new XYBarDataset(collection, 0.9); chart = ChartFactory.createXYBarChart(plotTitle, "", false, "", dataset, PlotOrientation.VERTICAL, enableLegend, true, true); plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.DARK_GRAY); plot.setRangeGridlinePaint(Color.DARK_GRAY); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); renderer = (XYBarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(true); return chart; }
From source file:org.azrul.langmera.LineChart.java
/** * Creates a sample dataset./*from www.ja v a2 s .c om*/ * * @return a sample dataset. */ public XYDataset createDataset(Map<String, List<Double>> dataList) { final XYSeriesCollection dataset = new XYSeriesCollection(); for (String key : dataList.keySet()) { final XYSeries series = new XYSeries(key); int maxT = dataList.get(key).size(); for (int j = 0; j < (maxT - 1); j++) { Double v = dataList.get(key).get(j) * 100.0; series.add((double) j, (double) (v)); } dataset.addSeries(series); } return dataset; }
From source file:Graphing.graphXY.java
private XYDataset getDataSet() { XYSeriesCollection dataSet = new XYSeriesCollection(); XYSeries series = new XYSeries(this.name); for (int i = 0; i < this.x.length; i++) { series.add(this.x[i], this.y[i]); }//from w ww . j a v a2 s. c om dataSet.addSeries(series); return dataSet; }
From source file:adept.utilities.Grapher.java
/** * Make time vs size graph.// w w w .ja v a 2 s.com * * @param timevalues the timevalues * @param sizevalues the sizevalues * @param filename the filename * @param linelabel the linelabel * @param Xlabel the xlabel * @param Ylabel the ylabel * @param title the title */ public static void makeTimeVsSizeGraph(ArrayList<Double> timevalues, ArrayList<Double> sizevalues, File filename, String linelabel, String Xlabel, String Ylabel, String title) { try { XYSeriesCollection scatter_plot_dataset = new XYSeriesCollection(); XYSeries data = new XYSeries(linelabel); for (int i = 0; i < sizevalues.size(); i++) { data.add(sizevalues.get(i), timevalues.get(i)); } scatter_plot_dataset.addSeries(data); /* Step -2:Define the JFreeChart object to create line chart */ JFreeChart scatterPlotObject = ChartFactory.createScatterPlot(Ylabel, Xlabel, title, scatter_plot_dataset, PlotOrientation.VERTICAL, true, true, false); /* Step -3 : Write line chart to a file */ int width = 640; /* Width of the image */ int height = 480; /* Height of the image */ ChartUtilities.saveChartAsPNG(filename, scatterPlotObject, width, height); } catch (Exception e) { e.printStackTrace(); } }
From source file:gda.util.SavePNGPlot.java
/** * //from w w w. j ava 2s. co m * @param imageFile * @param scan * @param width * @param height * @param chartTitle * @throws IOException */ public static void save(String imageFile, ScanFileHolder scan, int width, int height, String chartTitle) throws IOException { final XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series; IDataset x_axis = scan.getAxis(0); String[] headings = scan.getHeadings(); String yAxisName; if (headings.length == 2) yAxisName = headings[1]; else yAxisName = "various"; for (int seriesNum = 1; seriesNum < headings.length; seriesNum++) { series = new XYSeries(""); for (int point = 0, max = x_axis.getSize(); point < max - 1; point++) series.add(x_axis.getDouble(point), scan.getAxis(seriesNum).getDouble(point)); series.setKey(headings[seriesNum]); dataset.addSeries(series); } final JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart // title headings[0], // x axis label yAxisName, // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend false, // tool tips false // url's ); ChartUtilities.saveChartAsPNG(new File(imageFile), chart, width, height); }
From source file:org.uncommons.maths.demo.GraphPanel.java
public void generateGraph(String title, Map<Double, Double> observedValues, Map<Double, Double> expectedValues, double expectedMean, double expectedStandardDeviation, boolean discrete) { XYSeriesCollection dataSet = new XYSeriesCollection(); XYSeries observedSeries = new XYSeries("Observed"); dataSet.addSeries(observedSeries);/*from w w w . ja v a 2s. c o m*/ XYSeries expectedSeries = new XYSeries("Expected"); dataSet.addSeries(expectedSeries); for (Map.Entry<Double, Double> entry : observedValues.entrySet()) { observedSeries.add(entry.getKey(), entry.getValue()); } for (Map.Entry<Double, Double> entry : expectedValues.entrySet()) { expectedSeries.add(entry.getKey(), entry.getValue()); } JFreeChart chart = ChartFactory.createXYLineChart(title, "Value", "Probability", dataSet, PlotOrientation.VERTICAL, true, false, false); XYPlot plot = (XYPlot) chart.getPlot(); if (discrete) { // Render markers at each data point (these discrete points are the // distibution, not the lines between them). plot.setRenderer(new XYLineAndShapeRenderer()); } else { // Render smooth lines between points for a continuous distribution. XYSplineRenderer renderer = new XYSplineRenderer(); renderer.setBaseShapesVisible(false); plot.setRenderer(renderer); } chartPanel.setChart(chart); }