List of usage examples for org.jfree.data.xy XYSeriesCollection XYSeriesCollection
public XYSeriesCollection()
From source file:lu.lippmann.cdb.lab.mds.MDSViewBuilder.java
/** * //from w w w . j a v a2s. c o m */ public static JXPanel buildMDSViewFromDataSet(final Instances instances, final MDSResult mdsResult, final int maxInstances, final Listener<Instances> listener, final String... attrNameToUseAsPointTitle) throws Exception { final XYSeriesCollection dataset = new XYSeriesCollection(); final JFreeChart chart = ChartFactory.createScatterPlot("", // title "X", "Y", // axis labels dataset, // dataset PlotOrientation.VERTICAL, attrNameToUseAsPointTitle.length == 0, // legend? true, // tooltips? yes false // URLs? no ); final XYPlot xyPlot = (XYPlot) chart.getPlot(); xyPlot.setBackgroundPaint(Color.WHITE); xyPlot.getDomainAxis().setTickLabelsVisible(false); xyPlot.getRangeAxis().setTickLabelsVisible(false); //FIXME : should be different for Shih if (!mdsResult.isNormalized()) { String stress = FormatterUtil.DECIMAL_FORMAT .format(ClassicMDS.getKruskalStressFromMDSResult(mdsResult)); chart.setTitle(mdsResult.getCInstances().isCollapsed() ? "Collapsed MDS(Instances=" + maxInstances + ",Stress=" + stress + ")" : "MDS(Stress=" + stress + ")"); } else { chart.setTitle(mdsResult.getCInstances().isCollapsed() ? "Collapsed MDS(Instances=" + maxInstances + ")" : "MDS"); } final SimpleMatrix coordinates = mdsResult.getCoordinates(); buildFilteredSeries(mdsResult, xyPlot, attrNameToUseAsPointTitle); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setMouseWheelEnabled(true); chartPanel.setPreferredSize(new Dimension(1200, 900)); chartPanel.setBorder(new TitledBorder("MDS Projection")); chartPanel.setBackground(Color.WHITE); final JButton selectionButton = new JButton("Select data"); selectionButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final org.jfree.data.Range XDomainRange = xyPlot.getDomainAxis().getRange(); final org.jfree.data.Range YDomainRange = xyPlot.getRangeAxis().getRange(); final Instances cInstances = mdsResult.getCollapsedInstances(); final Instances selectedInstances = new Instances(cInstances, 0); List<Instances> clusters = null; if (mdsResult.getCInstances().isCollapsed()) { clusters = mdsResult.getCInstances().getCentroidMap().getClusters(); } for (int i = 0; i < cInstances.numInstances(); i++) { final Instance centroid = instances.instance(i); if (XDomainRange.contains(coordinates.get(i, 0)) && YDomainRange.contains(coordinates.get(i, 1))) { if (mdsResult.getCInstances().isCollapsed()) { if (clusters != null) { final Instances elementsOfCluster = clusters.get(i); final int nbElements = elementsOfCluster.numInstances(); for (int k = 0; k < nbElements; k++) { selectedInstances.add(elementsOfCluster.get(k)); } } } else { selectedInstances.add(centroid); } } } if (listener != null) { listener.onAction(selectedInstances); } } }); final JXPanel allPanel = new JXPanel(); allPanel.setLayout(new BorderLayout()); allPanel.add(chartPanel, BorderLayout.CENTER); final JXPanel southPanel = new JXPanel(); southPanel.add(selectionButton); allPanel.add(southPanel, BorderLayout.SOUTH); return allPanel; }
From source file:de.cebitec.readXplorer.plotting.CreatePlots.java
public synchronized static ChartPanel createPlot(Map<PersistentFeature, Pair<Double, Double>> data, String xName, String yName, XYToolTipGenerator toolTip) { XYSeriesCollection normal = new XYSeriesCollection(); XYSeries nor = new XYSeries("Normal"); for (Iterator<PersistentFeature> it = data.keySet().iterator(); it.hasNext();) { PersistentFeature key = it.next(); Pair<Double, Double> pair = data.get(key); Double X = pair.getFirst(); Double Y = pair.getSecond(); nor.add(new PlotDataItem(key, X, Y)); }//w w w.j av a2s . c o m normal.addSeries(nor); // create subplot 1... final XYItemRenderer renderer1 = new XYShapeRenderer(); renderer1.setBaseToolTipGenerator(toolTip); final NumberAxis domainAxis1 = new NumberAxis(xName); final NumberAxis rangeAxis1 = new NumberAxis(yName); final XYPlot subplot1 = new XYPlot(normal, domainAxis1, rangeAxis1, renderer1); JFreeChart chart = new JFreeChart(subplot1); chart.removeLegend(); ChartPanel panel = new ChartPanel(chart, true, false, true, true, true); panel.setInitialDelay(0); panel.setMaximumDrawHeight(1080); panel.setMaximumDrawWidth(1920); panel.setMouseWheelEnabled(true); panel.setMouseZoomable(true); MouseActions mouseAction = new MouseActions(); panel.addChartMouseListener(mouseAction); ChartPanelOverlay overlay = new ChartPanelOverlay(mouseAction); panel.addOverlay(overlay); return panel; }
From source file:loadmaprenderer.ChartTest.java
private XYSeriesCollection makeCollection(List<ResultDataPair> data) { XYSeriesCollection collection = new XYSeriesCollection(); XYSeries seriesA = new XYSeries("Cost/Year"); XYSeries seriesB = new XYSeries("Average"); Double average = GetAverage(data); for (int i = 0; i < data.size(); i++) { seriesA.add(data.get(i).getYear(), data.get(i).getData()); seriesB.add(data.get(i).getYear(), average); }// w w w. j av a2s . c o m collection.addSeries(seriesA); collection.addSeries(seriesB); return collection; }
From source file:org.matsim.contrib.drt.analysis.DensityScatterPlots.java
public static JFreeChart createPlot(String title, String xAxisLabel, String yAxisLabel, XYSeries series, Pair<Double, Double> lineCoeffs) { XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series);/*from ww w. jav a 2 s .com*/ double maxValue = Math.max(series.getMaxX(), series.getMaxY()); // y=x XYSeries lineXY = new XYSeries("y = x"); lineXY.add(0, 0); lineXY.add(maxValue, maxValue); dataset.addSeries(lineXY); if (lineCoeffs != null) { // a*y+b=x double a = lineCoeffs.getLeft(); double b = lineCoeffs.getRight(); String namePrefix = a == 0 ? "" : (a + " * y + "); XYSeries lineABXY = new XYSeries(namePrefix + b + " = x"); lineABXY.add(b, 0); if (a == 0) { lineABXY.add(b, maxValue); } else { lineABXY.add(maxValue, (maxValue - b) / a); } dataset.addSeries(lineABXY); } final JFreeChart chart = ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, dataset); XYPlot xyPlot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyPlot.getRenderer(0); renderer.setSeriesPaint(0, new Color(255, 0, 0, 50)); renderer.setSeriesShape(0, CIRCLE); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShapesVisible(0, true); renderer.setSeriesVisibleInLegend(0, false); for (int i = 1; i < dataset.getSeriesCount(); i++) { renderer.setSeriesPaint(i, new Color(0, 0, 0)); renderer.setSeriesLinesVisible(i, true); renderer.setSeriesShapesVisible(i, false); renderer.setSeriesVisibleInLegend(i, false); } xyPlot.getDomainAxis().setUpperBound(maxValue); xyPlot.getRangeAxis().setUpperBound(maxValue); xyPlot.getDomainAxis().setLowerBound(0); xyPlot.getRangeAxis().setLowerBound(0); return chart; }
From source file:convexaenvolvente.Grafico.java
public Grafico() { dataset = new XYSeriesCollection(); initComponents(); dtm = (DefaultTableModel) jTable1.getModel(); }
From source file:MonteCarloWindowLogic.java
static void drawPointsOnChart(JPanel panelWhenInside, ArrayList<Point2D> convexHull, ArrayList<Point2D> hits, ArrayList<Point2D> miss) { panelWhenInside.removeAll();/*from www . j a v a 2s.c o m*/ panelWhenInside.setLayout(new java.awt.BorderLayout()); XYSeries seriersHits = new XYSeries("Hits"); convertArrayListToXYSeries(seriersHits, hits); XYSeries seriersMiss = new XYSeries("Miss"); convertArrayListToXYSeries(seriersMiss, miss); //TODO refactor this, to handling hits, miss and than convex hull int pairsNumber = 0; if (convexHull != null) pairsNumber = convexHull.size() - 1; XYSeries covnexHullDivideOnPiars[] = new XYSeries[pairsNumber]; for (int i = 0; i < covnexHullDivideOnPiars.length; i++) { covnexHullDivideOnPiars[i] = new XYSeries("Convex hull pair " + i); } if (convexHull != null) { divideOnPairsAndConvertConvexHullIntoSeries(covnexHullDivideOnPiars, convexHull); } // Add the seriersAllPoints to your data set XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(seriersHits); dataset.addSeries(seriersMiss); for (int i = 0; i < covnexHullDivideOnPiars.length; i++) { dataset.addSeries(covnexHullDivideOnPiars[i]); } // Generate the graph JFreeChart chart = ChartFactory.createXYLineChart(null, // Title null, // x-axis Label null, // y-axis Label dataset, // Dataset PlotOrientation.VERTICAL, // Plot Orientation false, // Show Legend false, // Use tooltips false // Configure chart to generate URLs? ); final XYPlot plot = chart.getXYPlot(); ChartPanel chartPanel = new ChartPanel(chart); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesPaint(0, Color.GREEN); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShape(0, ShapeUtilities.createDiamond(3)); renderer.setSeriesPaint(1, Color.RED); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShape(1, ShapeUtilities.createDiamond(3)); for (int i = 2; i <= covnexHullDivideOnPiars.length + 1; i++) { renderer.setSeriesPaint(i, Color.black); renderer.setSeriesLinesVisible(i, true); renderer.setSeriesStroke(i, new BasicStroke(1.0f)); } plot.setRenderer(renderer); panelWhenInside.add(chartPanel, BorderLayout.CENTER); panelWhenInside.validate(); }
From source file:org.jfree.chart.demo.XYLine3DRendererDemo1.java
private static XYDataset createDataset() { XYSeries xyseries = new XYSeries("Series 1"); xyseries.add(1.0D, 3.2999999999999998D); xyseries.add(2D, 4.4000000000000004D); xyseries.add(3D, 1.7D);//from ww w. j a v a2 s . c o m XYSeries xyseries1 = new XYSeries("Series 2"); xyseries1.add(1.0D, 7.2999999999999998D); xyseries1.add(2D, 0.0D); xyseries1.add(3D, 9.5999999999999996D); xyseries1.add(4D, 5.5999999999999996D); XYSeriesCollection xyseriescollection = new XYSeriesCollection(); xyseriescollection.addSeries(xyseries); xyseriescollection.addSeries(xyseries1); return xyseriescollection; }
From source file:iad_zad3.gui.Charts.java
private static XYDataset createDataset(final List<double[]> data, final List<double[]> centroids) { XYSeries dataSeries = new XYSeries("data"); for (double[] v : data) { dataSeries.add(v[0], v[1]);//from w ww .j av a 2 s .co m } XYSeries centroidsSeries = new XYSeries("centroids"); for (double[] v : centroids) { centroidsSeries.add(v[0], v[1]); } XYSeriesCollection coll = new XYSeriesCollection(); coll.addSeries(centroidsSeries); coll.addSeries(dataSeries); return coll; }
From source file:FindHullWindowLogic.java
static void drawPointsOnChart(JPanel panelWhenInside, ArrayList<Point2D> convexHull) { panelWhenInside.removeAll();// ww w. ja v a 2 s .c om panelWhenInside.setLayout(new java.awt.BorderLayout()); XYSeries seriersAllPoints = new XYSeries("All points"); addPointsToSeries(seriersAllPoints); int pairsNumber = 0; if (convexHull != null) pairsNumber = convexHull.size() - 1; XYSeries covnexHullDivideOnPiars[] = new XYSeries[pairsNumber]; for (int i = 0; i < covnexHullDivideOnPiars.length; i++) { covnexHullDivideOnPiars[i] = new XYSeries("Convex hull pair " + i); } if (convexHull != null) { divideOnPairsAndConvertConvexHullIntoSeries(covnexHullDivideOnPiars, convexHull); } // Add the seriersAllPoints to your data set XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(seriersAllPoints); for (int i = 0; i < covnexHullDivideOnPiars.length; i++) { dataset.addSeries(covnexHullDivideOnPiars[i]); } // Generate the graph JFreeChart chart = ChartFactory.createXYLineChart(null, // Title null, // x-axis Label null, // y-axis Label dataset, // Dataset PlotOrientation.VERTICAL, // Plot Orientation false, // Show Legend false, // Use tooltips false // Configure chart to generate URLs? ); final XYPlot plot = chart.getXYPlot(); ChartPanel chartPanel = new ChartPanel(chart); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesPaint(0, Color.BLACK); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShape(0, ShapeUtilities.createDiamond(3)); for (int i = 1; i <= covnexHullDivideOnPiars.length; i++) { renderer.setSeriesPaint(i, Color.red); renderer.setSeriesLinesVisible(i, true); renderer.setSeriesStroke(i, new BasicStroke(1.0f)); } plot.setRenderer(renderer); panelWhenInside.add(chartPanel, BorderLayout.CENTER); panelWhenInside.validate(); }
From source file:org.chocosolver.gui.panels.ObjectivePanel.java
public ObjectivePanel(GUI frame) { super(frame); isOpt = solver.getObjectiveManager().getPolicy() != ResolutionPolicy.SATISFACTION; isMax = solver.getObjectiveManager().getPolicy() == ResolutionPolicy.MAXIMIZE; objective = new XYSeries("Best value"); bounds = new XYSeries(isMax ? "Upper bound" : "Lower bound"); XYSeriesCollection coll = new XYSeriesCollection(); coll.addSeries(objective);//from www .ja va 2s . c om coll.addSeries(bounds); JFreeChart dchart = ChartFactory.createXYLineChart("Objective", "Nodes", "Objective", coll); this.setChart(dchart); if (isOpt) { solver.plugMonitor(this); } }