List of usage examples for org.jfree.data.xy XYSeriesCollection addSeries
public void addSeries(XYSeries series)
From source file:org.matsim.analysis.LegHistogramChart.java
static JFreeChart getGraphic(final LegHistogram.DataFrame dataFrame, final String mode, int iteration) { final XYSeriesCollection xyData = new XYSeriesCollection(); final XYSeries departuresSerie = new XYSeries("departures", false, true); final XYSeries arrivalsSerie = new XYSeries("arrivals", false, true); final XYSeries onRouteSerie = new XYSeries("en route", false, true); int onRoute = 0; for (int i = 0; i < dataFrame.countsDep.length; i++) { onRoute = onRoute + dataFrame.countsDep[i] - dataFrame.countsArr[i] - dataFrame.countsStuck[i]; double hour = i * dataFrame.binSize / 60.0 / 60.0; departuresSerie.add(hour, dataFrame.countsDep[i]); arrivalsSerie.add(hour, dataFrame.countsArr[i]); onRouteSerie.add(hour, onRoute); }/* w w w .j ava2 s .c o m*/ xyData.addSeries(departuresSerie); xyData.addSeries(arrivalsSerie); xyData.addSeries(onRouteSerie); final JFreeChart chart = ChartFactory.createXYStepChart("Leg Histogram, " + mode + ", it." + iteration, "time", "# persons", 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")); plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f)); plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f)); plot.getRenderer().setSeriesStroke(2, new BasicStroke(2.0f)); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.gray); plot.setDomainGridlinePaint(Color.gray); return chart; }
From source file:org.xapagy.ui.tempdyn.GraphEvolution.java
/** * Returns a chart of the evolution of the memory component tdc * /*w w w .j a v a2s . c o m*/ * @param tdc * @param label * @param database * @param agent * @param index * @param ged * @return */ public static JFreeChart chartMemoryEvolution(tdComponent tdc, String label, tdDataBase database, Agent agent, List<Double> index, GraphEvolutionDescriptor ged) { List<String> memoryColors = null; if (tdc.getType() == tdComponentType.INSTANCE) { memoryColors = ged.memoryInstanceEnergyColors; } else { memoryColors = ged.memoryViEnergyColors; } // create a general purpose xy collection for jfreechart XYSeriesCollection xysc = new XYSeriesCollection(); // memory energy values (if needed) if (ged.graphMemoryEnergy) { for (String ec : memoryColors) { xysc.addSeries(new XYSeries("MemoryEnergy_" + ec)); } } // memory salience values (if needed) if (ged.graphMemorySalience) { for (String ec : memoryColors) { xysc.addSeries(new XYSeries("MemorySalience_" + ec)); } } // // Fill in the values into the xysc // for (Double time : index) { double dtime = time; // memory energy values (if needed) if (ged.graphMemoryEnergy) { for (String ec : memoryColors) { double value = database.getEnergy(tdc.getIdentifier(), ec, time); xysc.getSeries("MemoryEnergy_" + ec).add(dtime, value); } } // memory salience values (if needed) if (ged.graphMemorySalience) { for (String ec : memoryColors) { double value = database.getSalience(tdc.getIdentifier(), ec, time); xysc.getSeries("MemorySalience_" + ec).add(dtime, value); } } } // // the chart with the memory values // JFreeChart chart = ChartFactory.createXYLineChart(label + " - memory", "Time", "Value", xysc, PlotOrientation.VERTICAL, true, false, false); GraphEvolution.setChartProperties(chart, GraphEvolution.lineStylesConservative); return chart; }
From source file:org.xapagy.ui.tempdyn.GraphEvolution.java
/** * // w w w .jav a2s . c o m * Returns a chart of the evolution of the focus component tdc * * @param tdc * @param label * @param database * @param agent * @param index * @param ged * @return */ public static JFreeChart chartFocusEvolution(tdComponent tdc, String label, tdDataBase database, Agent agent, List<Double> index, GraphEvolutionDescriptor ged) { List<String> focusEnergyColors = null; switch (tdc.getType()) { case INSTANCE: focusEnergyColors = ged.focusInstanceEnergyColors; break; case VI: focusEnergyColors = ged.focusViEnergyColors; break; case CHOICE: focusEnergyColors = null; break; } // create a general purpose xy collection for jfreechart XYSeriesCollection xysc = new XYSeriesCollection(); // focus energy values (if needed) if (ged.graphFocusEnergy) { for (String ec : focusEnergyColors) { xysc.addSeries(new XYSeries("FocusEnergy_" + ec)); } } // focus salience values (if needed) if (ged.graphFocusSalience) { for (String ec : focusEnergyColors) { xysc.addSeries(new XYSeries("FocusSalience_" + ec)); } } // // Fill in the values into the xysc // for (Double time : index) { double dtime = time; if (ged.graphFocusEnergy) { for (String ec : focusEnergyColors) { double value = database.getEnergy(tdc.getIdentifier(), ec, time); xysc.getSeries("FocusEnergy_" + ec).add(dtime, value); } } // focus salience values (if needed) if (ged.graphFocusSalience) { for (String ec : focusEnergyColors) { double value = database.getSalience(tdc.getIdentifier(), ec, time); xysc.getSeries("FocusSalience_" + ec).add(dtime, value); } } } JFreeChart chart = ChartFactory.createXYLineChart(label + " - Focus", "Time", "Value", xysc, PlotOrientation.VERTICAL, true, false, false); GraphEvolution.setChartProperties(chart, GraphEvolution.lineStylesConservative); return chart; }
From source file:org.xapagy.ui.tempdyn.GraphEvolution.java
/** * Returns a chart for the evolution of the shadowing of the component tdc with sh. * /*from w w w . j a v a 2 s. c om*/ * @param tdc * @param sh * @param database * @param agent * @param index * @param shadowRange * @param ged * @return */ public static JFreeChart chartShadowEvolution(tdComponent tdc, String sh, tdDataBase database, Agent agent, List<Double> index, double shadowRange, GraphEvolutionDescriptor ged) { List<String> shadowColors = null; if (tdc.getType() == tdComponentType.INSTANCE) { shadowColors = ged.shadowInstanceEnergyColors; } else { shadowColors = ged.shadowViEnergyColors; } // create a general purpose xy collection for jfreechart XYSeriesCollection xysc = new XYSeriesCollection(); // shadow energy values (if needed) if (ged.graphShadowEnergy) { for (String ec : shadowColors) { xysc.addSeries(new XYSeries("ShadowEnergy_" + ec + "_" + sh)); } } // shadow salience values (if needed) if (ged.graphShadowSalience) { for (String ec : shadowColors) { xysc.addSeries(new XYSeries("ShadowSalience_" + ec + "_" + sh)); } } // // Fill in the values into the xysc // for (Double time : index) { double dtime = time; // shadow energy values (if needed) if (ged.graphShadowEnergy) { for (String ec : shadowColors) { double value = database.getEnergy(tdc.getIdentifier(), sh, ec, time); xysc.getSeries("ShadowEnergy_" + ec + "_" + sh).add(dtime, value); } } // shadow salience values (if needed) if (ged.graphShadowSalience) { for (String ec : shadowColors) { double value = database.getSalience(tdc.getIdentifier(), sh, ec, time); xysc.getSeries("ShadowSalience_" + ec + "_" + sh).add(dtime, value); } } } XYSeriesCollection xysSH = new XYSeriesCollection(); // shadow energy (if needed) if (ged.graphShadowEnergy) { for (String ec : shadowColors) { xysSH.addSeries(xysc.getSeries("ShadowEnergy_" + ec + "_" + sh)); } } // shadow salience (if needed) if (ged.graphShadowSalience) { for (String ec : shadowColors) { xysSH.addSeries(xysc.getSeries("ShadowSalience_" + ec + "_" + sh)); } } // FIND a label String shadowLabel = "Shadow:" + sh; if (tdc.getType() == tdComponentType.INSTANCE) { Instance instance = agent.getAutobiographicalMemory().getInstance(sh); shadowLabel += " - " + SpInstance.spc(instance, agent); } else { VerbInstance vi = agent.getAutobiographicalMemory().getVerbInstance(sh); shadowLabel += " - " + XapiPrint.ppsViXapiForm(vi, agent); } JFreeChart chart = ChartFactory.createXYLineChart(shadowLabel, "Time", "Value", xysSH, PlotOrientation.VERTICAL, true, false, false); GraphEvolution.setChartProperties(chart, GraphEvolution.lineStylesConservative); XYPlot plot = chart.getXYPlot(); plot.getRangeAxis(0).setRange(0, shadowRange); return chart; }
From source file:com.griddynamics.jagger.reporting.chart.ChartHelper.java
public static Pair<String, XYSeriesCollection> adjustTime(XYSeriesCollection chartsCollection, Collection<IntervalMarker> markers) { int maxTime = 0; for (int i = 0; i < chartsCollection.getSeriesCount(); i++) { XYSeries series = chartsCollection.getSeries(i); for (int j = 0; j < series.getItemCount(); j++) { int x = series.getX(j).intValue(); if (x > maxTime) { maxTime = x;//from w w w .j a v a 2s. co m } } } String type = "ms"; int div = 1; if (maxTime > 10 * 60 * 1000) { div = 60 * 1000; type = "min"; } if (maxTime > 30 * 1000) { div = 1000; type = "sec"; } XYSeriesCollection result = new XYSeriesCollection(); for (int i = 0; i < chartsCollection.getSeriesCount(); i++) { XYSeries old = chartsCollection.getSeries(i); XYSeries series = new XYSeries(old.getKey(), old.getAutoSort(), old.getAllowDuplicateXValues()); for (int j = 0; j < old.getItemCount(); j++) { Number x = old.getX(j).doubleValue() / div; Number y = old.getY(j); series.add(x, y); } result.addSeries(series); } if (markers != null) { for (IntervalMarker marker : markers) { marker.setStartValue(marker.getStartValue() / div); marker.setEndValue(marker.getEndValue() / div); } } return Pair.of(type, result); }
From source file:cn.InstFS.wkr.NetworkMining.UIs.TimeSeriesChart1.java
public static XYDataset createNormalDataset(DataItems normal, String protocol1) { // ???/*ww w . j a v a 2 s . c o m*/ int length = normal.getLength(); int time[] = new int[length]; XYSeries xyseries = new XYSeries(protocol1); XYSeriesCollection xyseriescollection = new XYSeriesCollection(); // ?? for (int i = 0; i < length; i++) { DataItem temp = new DataItem(); temp = normal.getElementAt(i); //System.out.println("DataItem.time=" + temp.getTime().getTime()); xyseries.add(i, Double.parseDouble(temp.getData())); // } xyseriescollection.addSeries(xyseries); return xyseriescollection; }
From source file:org.xapagy.ui.tempdyn.GraphEvolution.java
/** * Graphs the evolution of the links of all types (PRED, SUCC, SUMMARY, * CONTEXT etc) between two Vis.//www. j a v a 2 s . co m * * @param fromVi * @param toVi * @param tdb * @param agent * @param index * - a list of time points which will be plotted on the x axis */ public static void graphLinksBetweenVis(tdComponent fromVi, tdComponent toVi, tdDataBase tdb, Agent agent, List<Double> index) { String label = "Links between " + fromVi.getIdentifier() + " and " + toVi.getIdentifier(); // create a general purpose xy collection for jfreechart XYSeriesCollection xysc = new XYSeriesCollection(); // add a series for each link type for (String linkName : agent.getLinks().getLinkTypeNames()) { XYSeries linkSeries = new XYSeries(linkName); xysc.addSeries(linkSeries); // now fill in the series with values for (Double time : index) { double dtime = time; double linkValue = tdb.getLinkValue(fromVi.getIdentifier(), toVi.getIdentifier(), linkName, time); linkSeries.add(dtime, linkValue); } } // // ok, now let us create a graph // JPanel panel = new JPanel(); // create a layout GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); SequentialGroup sgv = layout.createSequentialGroup(); layout.setVerticalGroup(sgv); ParallelGroup pgh = layout.createParallelGroup(); layout.setHorizontalGroup(pgh); JFreeChart chart = ChartFactory.createXYLineChart(label, "Time", "Value", xysc, PlotOrientation.VERTICAL, true, false, false); GraphEvolution.setChartProperties(chart, GraphEvolution.lineStylesColorful); ChartPanel cp = new ChartPanel(chart); sgv.addComponent(cp); pgh.addComponent(cp); JFrame frame = new JFrame(); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:logica.LGraficapeso.java
public static void logicaBtnGraficar(JRadioButton jRLinea) { ChartPanel panel;// w w w . j ava 2 s .c om JFreeChart chart = null; if (jRLinea.isSelected()) { // ejecuto linea XYSplineRenderer graficoLinea = new XYSplineRenderer(); XYSeriesCollection dataset = new XYSeriesCollection(); ValueAxis x = new NumberAxis(); ValueAxis y = new NumberAxis(); XYSeries serie = new XYSeries("Datos"); XYPlot plot; graficoLinea.setSeriesPaint(0, Color.YELLOW); VGraficaPeso.getPanelLinea().removeAll(); for (int i = 0; i < VGraficaPeso.getjTable1().getRowCount(); i++) { float valor1 = Float.parseFloat(String.valueOf(VGraficaPeso.getjTable1().getValueAt(i, 0))); float valor2 = Float.parseFloat(String.valueOf(VGraficaPeso.getjTable1().getValueAt(i, 1))); System.out.println("valores " + valor1 + " " + valor2); serie.add(valor1, valor2); } dataset.addSeries(serie); x.setLabel("MES"); y.setLabel("peso"); plot = new XYPlot(dataset, x, y, graficoLinea); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setRange(10, 15); chart = new JFreeChart(plot); chart.setTitle("grafico"); panel = new ChartPanel(chart); panel.setBounds(5, 10, 410, 350); VGraficaPeso.getPanelLinea().add(panel); VGraficaPeso.getPanelLinea().repaint(); } }
From source file:audio.cords.old.RegressionDemo.java
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;//from w w w. jav a 2s . c o m } 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:eu.cassandra.utils.Utils.java
/** * This function is used for the visualization of a Line Diagram. * /* w w w . j ava2s. c o m*/ * @param title * The title of the chart. * @param x * The unit on the X axis of the chart. * @param y * The unit on the Y axis of the chart. * @param data * The array of values. * @return a chart panel with the graphical representation. */ public static void createLineDiagram(String title, String x, String y, ArrayList<Double> data) { XYSeries series1 = new XYSeries("Active Power"); for (int i = 0; i < data.size(); i++) { series1.add(i, data.get(i)); } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series1); PlotOrientation orientation = PlotOrientation.VERTICAL; boolean show = true; boolean toolTips = false; boolean urls = false; JFreeChart chart = ChartFactory.createXYLineChart(title, x, y, dataset, orientation, show, toolTips, urls); int width = 1024; int height = 768; try { ChartUtilities.saveChartAsPNG(new File(Constants.chartFolder + title + ".PNG"), chart, width, height); } catch (IOException e) { } }