List of usage examples for org.jfree.data.xy XYSeries add
public void add(XYDataItem item, boolean notify)
From source file:eu.cassandra.csn.gui.Stats.java
/** * // w w w . ja va 2 s. com * @param instInfo */ public static void updateTableModelSelected(Vector<InstallationInfo> instInfos) { for (int i = tableModelSelected.getRowCount() - 1; i >= 0; i--) { tableModelSelected.removeRow(i); } for (int i = 0; i < instInfos.size(); i++) { InstallationInfo instInfo = instInfos.get(i); String[] rowData = new String[5]; rowData[0] = (instInfo.getInstallationName() != null ? instInfo.getInstallationName() : ""); rowData[1] = (instInfo.getInstallationType() != null ? instInfo.getInstallationType() : ""); rowData[2] = String.valueOf( (instInfo.getTotalConsumption() != 0.0 ? instInfo.getTotalConsumption() : "")) + " kWh"; rowData[3] = String .valueOf((instInfo.getPeakComsumption() != 0.0 ? instInfo.getPeakComsumption() : "") + " W"); rowData[4] = String .valueOf((instInfo.getAvgConsumption() != 0.0 ? instInfo.getAvgConsumption() : "") + " W"); tableModelSelected.addRow(rowData); } Double[] data; if (instInfos.size() == 1) { String inst_id = instInfos.get(0).getID(); data = MongoQueries.getInstallationResults(inst_id); } else { data = new Double[0]; } XYSeries series1 = new XYSeries("First"); for (int i = 0; i < data.length / 15; i++) { double d = 0; for (int j = 0; j < 60; j++) { d += data[j * 60 + i]; } series1.add(i, d); } final XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series1); chartPanel.getChart().getXYPlot().setDataset(dataset); }
From source file:com.joey.software.plottingToolkit.PlotingToolkit.java
public static XYSeriesCollection getCollection(double[] xData, double[] yData, String name) { if (xData.length != yData.length) { throw new InvalidParameterException("X and Y must be same length"); }/* w ww . j av a2 s .co m*/ XYSeries series = new XYSeries(name); for (int i = 0; i < xData.length; i++) { series.add(xData[i], yData[i]); } XYSeriesCollection result = new XYSeriesCollection(series); return result; }
From source file:com.joey.software.plottingToolkit.PlotingToolkit.java
public static XYSeriesCollection getCollection(float[] xData, float[] yData, String name) { if (xData.length != yData.length) { throw new InvalidParameterException("X and Y must be same length"); }/* w w w . j av a 2 s . co m*/ XYSeries series = new XYSeries(name); for (int i = 0; i < xData.length; i++) { series.add(xData[i], yData[i]); } XYSeriesCollection result = new XYSeriesCollection(series); return result; }
From source file:com.joey.software.plottingToolkit.PlotingToolkit.java
public static XYSeriesCollection getCollection(int[] xData, int[] yData, String name) { if (xData.length != yData.length) { throw new InvalidParameterException("X and Y must be same length"); }/*from w w w . j ava 2s .com*/ XYSeries series = new XYSeries(name); for (int i = 0; i < xData.length; i++) { series.add(xData[i], yData[i]); } XYSeriesCollection result = new XYSeriesCollection(series); return result; }
From source file:org.gephi.ui.utils.ChartsUtils.java
/** * Calculates linear regression points from a XYSeriesCollection data set * Code obtained from http://pwnt.be/2009/08/17/simple-linear-regression-with-jfreechart *///from w ww . jav a 2 s. c o m private static XYDataset regress(XYSeriesCollection data) { // Determine bounds double xMin = Double.MAX_VALUE, xMax = 0; for (int i = 0; i < data.getSeriesCount(); i++) { XYSeries ser = data.getSeries(i); for (int j = 0; j < ser.getItemCount(); j++) { double x = ser.getX(j).doubleValue(); if (x < xMin) { xMin = x; } if (x > xMax) { xMax = x; } } } // Create 2-point series for each of the original series XYSeriesCollection coll = new XYSeriesCollection(); for (int i = 0; i < data.getSeriesCount(); i++) { XYSeries ser = data.getSeries(i); int n = ser.getItemCount(); double sx = 0, sy = 0, sxx = 0, sxy = 0, syy = 0; for (int j = 0; j < n; j++) { double x = ser.getX(j).doubleValue(); double y = ser.getY(j).doubleValue(); sx += x; sy += y; sxx += x * x; sxy += x * y; syy += y * y; } double b = (n * sxy - sx * sy) / (n * sxx - sx * sx); double a = sy / n - b * sx / n; XYSeries regr = new XYSeries(ser.getKey()); regr.add(xMin, a + b * xMin); regr.add(xMax, a + b * xMax); coll.addSeries(regr); } return coll; }
From source file:jsdp.app.inventory.univariate.CapacitatedStochasticLotSizing.java
static void plotOptimalPolicyAction(int targetPeriod, BackwardRecursionImpl recursion) { 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.getOptimalAction(stateDescriptor).getAction()); }// w w w . ja v a 2s . c o m XYDataset xyDataset = new XYSeriesCollection(series); JFreeChart chart = ChartFactory.createXYLineChart( "Optimal policy - period " + targetPeriod + " order quantity", "Opening inventory level", "Order quantity", xyDataset, PlotOrientation.VERTICAL, false, true, false); ChartFrame frame = new ChartFrame("Optimal policy", chart); frame.setVisible(true); frame.setSize(500, 400); }
From source file:jsdp.app.inventory.univariate.CapacitatedStochasticLotSizing.java
static void plotOptimalPolicyCost(int targetPeriod, BackwardRecursionImpl recursion) { recursion.runBackwardRecursion(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)); }/*from ww w . ja v a2 s.com*/ 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:org.radargun.reporting.BarPlotGenerator.java
/** * @param operation Name of the plotted operation * @param ranges ranges[0] = min, ranges[ranges.length - 1] = max * @param counts counts[i] is number of entries with value >= ranges[i - 1] and < ranges[i] * @param reportDir/*from w ww .ja v a 2 s . c om*/ * @param filename * @throws IOException */ public static void generate(String operation, long[] ranges, long[] counts, String reportDir, String filename) throws IOException { XYSeries series = new XYSeries(operation + " response times"); long totalCount = 0; for (long count : counts) { totalCount += count; } double left = Math.log10(ranges[0]); double right = Math.log10(ranges[ranges.length - 1]); for (int i = 0; i < counts.length; i++) { series.add(Math.log10(ranges[i]), (double) counts[i] / totalCount); } series.add(right, 0d); XYDataset dataset = new XYSeriesCollection(series); JFreeChart chart = ChartFactory.createXYStepAreaChart(operation + " response time histogram", "Response time", "Percentage", dataset, PlotOrientation.VERTICAL, false, false, false); XYPlot plot = (XYPlot) chart.getPlot(); NumberAxis d = (NumberAxis) plot.getDomainAxis(); d.setRange(left, right); d.setStandardTickUnits(new HistoTickUnitSource()); plot.setDomainAxis(d); FileOutputStream output = new FileOutputStream(new File(reportDir + File.separator + filename)); ChartUtilities.writeChartAsPNG(output, chart, 1024, 768); output.close(); }
From source file:mt.DisplayHistogram.java
public static IntervalXYDataset createDataset(final List<Double> values, final int numBins, final String title) { final XYSeries series = new XYSeries(title); final ValuePair<Double, Double> minmax = getMinMax(values); min = minmax.getA();/* www . j a va 2 s.co m*/ max = minmax.getB(); final List<ValuePair<Double, Integer>> hist = binData(values, min, max, numBins); for (final ValuePair<Double, Integer> pair : hist) series.add(pair.getA(), pair.getB()); final XYSeriesCollection dataset = new XYSeriesCollection(series); dataset.setAutoWidth(true); return dataset; }
From source file:simulador.controle.GraficoCategorias.java
private static XYSeriesCollection criarDataset(Map<String, Map<Float, Float>> dadosRadios) { if (DEBUG) {/* w ww . ja va 2s. c o m*/ System.out.println("GraficoRadiais.criarDataset"); } XYSeriesCollection colecaoParesXY = new XYSeriesCollection(); for (Map.Entry<String, Map<Float, Float>> parDadosRadios : dadosRadios.entrySet()) { Map<Float, Float> dadosRadio = parDadosRadios.getValue(); XYSeries paresXY = new XYSeries(parDadosRadios.getKey()); for (Map.Entry<Float, Float> parDadosRadio : dadosRadio.entrySet()) { float d = parDadosRadio.getKey(); float p = parDadosRadio.getValue(); //System.out.println("d = "+d); //System.out.println("p = "+p); paresXY.add(parDadosRadio.getKey(), parDadosRadio.getValue()); } colecaoParesXY.addSeries(paresXY); } return colecaoParesXY; }