List of usage examples for org.jfree.data.xy XYSeries add
public void add(XYDataItem item, boolean notify)
From source file:jsdp.app.inventory.univariate.StochasticLotSizing.java
static void plotOptimalPolicyCost(int targetPeriod, BackwardRecursionImpl recursion) { recursion.runBackwardRecursionMonitoring(targetPeriod); XYSeries series = new XYSeries("Optimal policy"); for (double i = StateImpl.getMinState(); i <= StateImpl.getMaxState(); i += StateImpl.getStepSize()) { StateDescriptorImpl stateDescriptor = new StateDescriptorImpl(targetPeriod, i); series.add(i, recursion.getExpectedCost(stateDescriptor)); }// w w w. j a va2 s . c o m XYDataset xyDataset = new XYSeriesCollection(series); JFreeChart chart = ChartFactory.createXYLineChart( "Optimal policy policy - period " + targetPeriod + " expected total cost", "Opening inventory level", "Expected total cost", xyDataset, PlotOrientation.VERTICAL, false, true, false); ChartFrame frame = new ChartFrame("Optimal policy", chart); frame.setVisible(true); frame.setSize(500, 400); }
From source file:lu.lippmann.cdb.datasetview.tabs.ScatterPlotTabView.java
private static ChartPanel buildChartPanel(final Instances dataSet, final int xidx, final int yidx, final int coloridx, final boolean asSerie) { final XYSeriesCollection data = new XYSeriesCollection(); final Map<Integer, List<Instance>> filteredInstances = new HashMap<Integer, List<Instance>>(); final int classIndex = dataSet.classIndex(); if (classIndex < 0) { final XYSeries series = new XYSeries("Serie", false); for (int i = 0; i < dataSet.numInstances(); i++) { series.add(dataSet.instance(i).value(xidx), dataSet.instance(i).value(yidx)); }//from www . ja v a 2 s. co m data.addSeries(series); } else { final Set<String> pvs = WekaDataStatsUtil.getPresentValuesForNominalAttribute(dataSet, classIndex); int p = 0; for (final String pv : pvs) { final XYSeries series = new XYSeries(pv, false); for (int i = 0; i < dataSet.numInstances(); i++) { if (dataSet.instance(i).stringValue(classIndex).equals(pv)) { if (!filteredInstances.containsKey(p)) { filteredInstances.put(p, new ArrayList<Instance>()); } filteredInstances.get(p).add(dataSet.instance(i)); series.add(dataSet.instance(i).value(xidx), dataSet.instance(i).value(yidx)); } } data.addSeries(series); p++; } } final JFreeChart chart = ChartFactory.createScatterPlot("Scatter Plot", // chart title dataSet.attribute(xidx).name(), // x axis label dataSet.attribute(yidx).name(), // y axis label data, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); final XYPlot xyPlot = (XYPlot) chart.getPlot(); final XYToolTipGenerator gen = new XYToolTipGenerator() { @Override public String generateToolTip(final XYDataset dataset, final int series, final int item) { if (classIndex < 0) { return InstanceFormatter.htmlFormat(dataSet.instance(item), true); } else { return InstanceFormatter.htmlFormat(filteredInstances.get(series).get(item), true); } } }; int nbSeries; if (classIndex < 0) { nbSeries = 1; } else { nbSeries = filteredInstances.keySet().size(); } final XYItemRenderer renderer = new XYLineAndShapeRenderer(asSerie, true) { /** */ private static final long serialVersionUID = 1L; @Override public Paint getItemPaint(final int row, final int col) { //System.out.println(row+" "+col); if (classIndex < 0) { final double v = dataSet.instance(col).value(coloridx); final double[] minmax = WekaDataStatsUtil.getMinMaxForAttributeAsArrayOfDoubles(dataSet, coloridx); final double rated = (v - minmax[0]) / (minmax[1] - minmax[0]); System.out.println("rated -> " + rated + " min=" + minmax[0] + "max=" + minmax[1]); final int colorIdx = (int) Math.round((ColorHelper.YlGnBu_9_COLORS.length - 1) * rated); //System.out.println(minmax[0]+" "+minmax[1]+" "+v+" "+rated+" "+colorIdx); return ColorHelper.YlGnBu_9_COLORS[colorIdx]; } else return super.getItemPaint(row, col); } }; xyPlot.setRenderer(renderer); for (int i = 0; i < nbSeries; i++) { renderer.setSeriesToolTipGenerator(i, gen); } return new ChartPanel(chart); }
From source file:org.gephi.ui.utils.ChartsUtils.java
/** * Build new scatter plot from numbers array using a default title and xLabel. * String dataName will be used for yLabel. * Appearance can be changed later with the other methods of ChartsUtils. * @param numbers Numbers for the scatter plot * @param dataName Name of the numbers data * @param useLines Indicates if lines have to be drawn instead of shapes * @param useLinearRegression Indicates if the scatter plot has to have linear regreesion line drawn * @return Scatter plot for the data and appearance options *///from ww w.ja v a 2s. co m public static JFreeChart buildScatterPlot(final Number[] numbers, final String dataName, final boolean useLines, final boolean useLinearRegression) { if (numbers == null || numbers.length == 0) { return null; } XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries(dataName); for (int i = 0; i < numbers.length; i++) { series.add(i, numbers[i]); } dataset.addSeries(series); JFreeChart scatterPlot = buildScatterPlot(dataset, getMessage("ChartsUtils.report.scatter-plot.title"), getMessage("ChartsUtils.report.scatter-plot.xLabel"), dataName, useLines, useLinearRegression); return scatterPlot; }
From source file:PerformanceGraph.java
/** * Plots the performance graph of the best fitness value so far versus the * number of function calls (NFC).//from w ww . ja v a2s .c o m * * @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:de.hs.mannheim.modUro.controller.diagram.SimulationDiagramController.java
/** * Creates Dataset./* w w w . j a v a 2 s.com*/ * * @return */ private static XYDataset createDataset(String simulationName, double[][] fitnessArray) { XYSeries xySerie = new XYSeries(simulationName); double x; double y; for (int i = 0; i < fitnessArray.length; i++) { x = fitnessArray[i][0]; y = fitnessArray[i][1]; xySerie.add(x, y); } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(xySerie); return dataset; }
From source file:logica_controladores.controlador_estadistica.java
public static void grafica_orden(JPanel panel_grafica_orden, Inventario inventario, JLabel lbLinea) { XYSeries serie = null; XYSeries serie_2 = null;// w w w . ja v a2s . c o m JFreeChart linea; serie = new XYSeries("graficas relacion gastos-orden"); Gasto gasto_minimo = valor_minimo(inventario); Gasto gasto_max = valor_maximo(inventario); for (int i = 0; i < inventario.getGastos().size(); i = i + inventario.getReorden_max()) { serie.add(inventario.getGastos().get(i).getOrden_inicial(), inventario.getGastos().get(i).getGastos()); } serie_2 = new XYSeries("graficas relacion gastos-reorden"); for (int i = 0; i < inventario.getGastos().size(); i = i + inventario.getOrden_max()) { serie_2.add(inventario.getGastos().get(i).getReorden(), inventario.getGastos().get(i).getGastos()); } final XYSeriesCollection datos = new XYSeriesCollection(); datos.addSeries(serie); datos.addSeries(serie_2); linea = ChartFactory.createXYLineChart( "grafica representativa de ordenes por corrida, gasto_minimo(orden: " + gasto_minimo.getOrden_inicial() + "reorden: " + gasto_minimo.getReorden() + ")= " + gasto_minimo.getGastos(), "rango", "gastos", datos, PlotOrientation.VERTICAL, true, true, true); final XYPlot plot = (XYPlot) linea.getPlot(); final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); configurarDomainAxis(domainAxis, inventario); configurarRangeAxis(rangeAxis, gasto_minimo.getGastos(), gasto_max.getGastos()); BufferedImage graficoLinea = linea.createBufferedImage(600, 280); lbLinea.setSize(panel_grafica_orden.getSize()); lbLinea.setIcon(new ImageIcon(graficoLinea)); panel_grafica_orden.updateUI(); }
From source file:com.jolbox.benchmark.BenchmarkLaunch.java
/** * @param results/* ww w. j a v a 2 s . co m*/ * @param delay * @param statementBenchmark * @param noC3P0 * @throws IOException */ private static void doPlotLineGraph(long[][] results, int delay, boolean statementBenchmark, boolean noC3P0) throws IOException { String title = "Multi-Thread test (" + delay + "ms delay)"; if (statementBenchmark) { title += "\n(with PreparedStatements tests)"; } String fname = System.getProperty("java.io.tmpdir") + File.separator + "bonecp-multithread-" + delay + "ms-delay"; if (statementBenchmark) { fname += "-with-preparedstatements"; } fname += "-poolsize-" + BenchmarkTests.pool_size + "-threads-" + BenchmarkTests.threads; if (noC3P0) { fname += "-noC3P0"; } PrintWriter out = new PrintWriter(new FileWriter(fname + ".txt")); fname += ".png"; XYSeriesCollection dataset = new XYSeriesCollection(); for (int i = 0; i < ConnectionPoolType.values().length; i++) { // if (!ConnectionPoolType.values()[i].isEnabled() || (noC3P0 && ConnectionPoolType.values()[i].equals(ConnectionPoolType.C3P0))) { continue; } XYSeries series = new XYSeries(ConnectionPoolType.values()[i].toString()); out.println(ConnectionPoolType.values()[i].toString()); for (int j = 1 + BenchmarkTests.stepping; j < results[i].length; j += BenchmarkTests.stepping) { series.add(j, results[i][j]); out.println(j + "," + results[i][j]); } dataset.addSeries(series); } out.close(); // Generate the graph JFreeChart chart = ChartFactory.createXYLineChart(title, // Title "threads", // x-axis Label "time (ns)", // y-axis Label dataset, // Dataset PlotOrientation.VERTICAL, // Plot Orientation true, // Show Legend true, // Use tooltips false // Configure chart to generate URLs? ); XYPlot plot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); plot.setRenderer(renderer); renderer.setSeriesPaint(0, Color.BLUE); renderer.setSeriesPaint(1, Color.YELLOW); renderer.setSeriesPaint(2, Color.BLACK); renderer.setSeriesPaint(3, Color.DARK_GRAY); renderer.setSeriesPaint(4, Color.MAGENTA); renderer.setSeriesPaint(5, Color.RED); renderer.setSeriesPaint(6, Color.LIGHT_GRAY); // renderer.setSeriesShapesVisible(1, true); // renderer.setSeriesShapesVisible(2, true); try { ChartUtilities.saveChartAsPNG(new File(fname), chart, 1024, 768); System.out.println("******* Saved chart to: " + fname); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } }
From source file:jsdp.app.lotsizing.sS_jsdp.java
public static void plotCostFunction(int targetPeriod, double fixedOrderingCost, double proportionalOrderingCost, double holdingCost, double penaltyCost, Distribution[] distributions, double minDemand, double maxDemand, boolean printCostFunctionValues, boolean latexOutput, sS_StateSpaceSampleIterator.SamplingScheme samplingScheme, int maxSampleSize) { sS_BackwardRecursion recursion = new sS_BackwardRecursion(distributions, minDemand, maxDemand, fixedOrderingCost, proportionalOrderingCost, holdingCost, penaltyCost, samplingScheme, maxSampleSize);// ww w . j a v a 2 s. c o m recursion.runBackwardRecursion(targetPeriod); XYSeries series = new XYSeries("(s,S) policy"); for (double i = sS_State.getMinInventory(); i <= sS_State.getMaxInventory(); i += sS_State.getStepSize()) { sS_StateDescriptor stateDescriptor = new sS_StateDescriptor(targetPeriod, sS_State.inventoryToState(i)); series.add(i, recursion.getExpectedCost(stateDescriptor)); if (printCostFunctionValues) System.out.println(i + "\t" + recursion.getExpectedCost(stateDescriptor)); } XYDataset xyDataset = new XYSeriesCollection(series); JFreeChart chart = ChartFactory.createXYLineChart( "(s,S) policy - period " + targetPeriod + " expected total cost", "Opening inventory level", "Expected total cost", xyDataset, PlotOrientation.VERTICAL, false, true, false); ChartFrame frame = new ChartFrame("(s,S) policy", chart); frame.setVisible(true); frame.setSize(500, 400); if (latexOutput) { try { XYLineChart lc = new XYLineChart("(s,S) policy", "Opening inventory level", "Expected total cost", new XYSeriesCollection(series)); File latexFolder = new File("./latex"); if (!latexFolder.exists()) { latexFolder.mkdir(); } Writer file = new FileWriter("./latex/graph.tex"); file.write(lc.toLatex(8, 5)); file.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:playground.johannes.socialnets.GraphStatistics.java
public static JFreeChart makeChart(Histogram1D hist, String title) { final XYSeriesCollection data = new XYSeriesCollection(); final XYSeries wave = new XYSeries(title, false, true); for (int i = 0; i < 100; i++) { wave.add(hist.xAxis().binCentre(i), hist.binHeight(i)); }//from w w w. jav a2s . c om data.addSeries(wave); final JFreeChart chart = ChartFactory.createXYStepChart("title", "x", "y", data, PlotOrientation.VERTICAL, true, // legend false, // tooltips false // urls ); XYPlot plot = chart.getXYPlot(); final CategoryAxis axis1 = new CategoryAxis("x"); axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7)); plot.setDomainAxis(new NumberAxis("y")); return chart; }
From source file:com.comcast.cmb.test.tools.QueueDepthSimulator.java
public static void scatterPlot(Map<String, List<Double>> datasets, String filename, String title, String labelX, String labelY) throws IOException { XYSeriesCollection dataset = new XYSeriesCollection(); for (String label : datasets.keySet()) { XYSeries data = new XYSeries(label); int cnt = 0; for (Double d : datasets.get(label)) { data.add(cnt, d); cnt++;//ww w .ja va 2 s. c om } dataset.addSeries(data); } JFreeChart chart = ChartFactory.createScatterPlot(title, labelX, labelY, dataset, PlotOrientation.VERTICAL, true, true, false); ChartUtilities.saveChartAsPNG(new File(filename), chart, 1024, 768); }