List of usage examples for org.jfree.data.xy XYSeriesCollection getSeries
public XYSeries getSeries(Comparable key)
From source file:com.griddynamics.jagger.reporting.chart.ChartHelper.java
public static JFreeChart createStackedAreaChart(String title, XYSeriesCollection areaData, XYSeriesCollection lineData, String xLabel, String yLabel, ColorTheme theme) { final ValueAxis xAxis = new NumberAxis(xLabel); final ValueAxis yAxis = new NumberAxis(yLabel); XYPlot mainPlot = new XYPlot(); mainPlot.setDomainAxis(xAxis);// ww w. ja va 2s . c o m mainPlot.setRangeAxis(yAxis); mainPlot.setForegroundAlpha(0.9f); //[ stacked area DefaultTableXYDataset areaDs = new DefaultTableXYDataset(); for (int i = 0; i < areaData.getSeriesCount(); i++) { areaDs.addSeries(areaData.getSeries(i)); } XYItemRenderer stackedRenderer = new StackedXYAreaRenderer2(); mainPlot.setDataset(areaDs); mainPlot.setRenderer(stackedRenderer); Color[] colors = generateJetSpectrum(areaData.getSeriesCount()); for (int i = 0; i < areaData.getSeriesCount(); i++) { stackedRenderer.setSeriesPaint(i, colors[i]); } //] //[ lines if (lineData != null) { XYItemRenderer lineRenderer = new StandardXYItemRenderer(); DefaultTableXYDataset lineDs = new DefaultTableXYDataset(); for (int i = 0; i < lineData.getSeriesCount(); i++) { lineDs.addSeries(lineData.getSeries(i)); } mainPlot.setDataset(1, lineDs); mainPlot.setRenderer(1, lineRenderer); colors = new Color[] { Color.black, Color.red, Color.darkGray }; for (int i = 0; i < lineData.getSeriesCount(); i++) { lineRenderer.setSeriesPaint(i, colors[i % colors.length]); lineRenderer.setSeriesStroke(i, new BasicStroke(2f)); } } //] mainPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, mainPlot, true); formatColorTheme(chart, theme); return chart; }
From source file:de.cebitec.readXplorer.differentialExpression.plot.ToolTip.java
@Override public String generateToolTip(XYDataset xyd, int seriesIndex, int itemIndex) { XYSeriesCollection dataset = (XYSeriesCollection) xyd; PlotDataItem clickedItem = (PlotDataItem) dataset.getSeries(seriesIndex).getDataItem(itemIndex); PersistentFeature feature = clickedItem.getFeature(); StringBuilder sb = new StringBuilder("<html>"); sb.append("Type: ").append(feature.getType()).append("<br>"); sb.append("Locus: ").append(feature.getLocus()).append("<br>"); sb.append("Gene: ").append(feature.toString()).append("<br>"); sb.append("Start: ").append(feature.getStart()).append("<br>"); sb.append("Stop: ").append(feature.getStop()).append("<br>"); sb.append("EC number: ").append(feature.getEcNumber()).append("</html>"); return sb.toString(); }
From source file:org.xapagy.ui.tempdyn.GraphEvolution.java
/** * Generates the graph which plots the three choice scores (independent, * dependent and mood) for the evolution of a choice in time. * /*from w ww . j a va 2 s. c o m*/ * @param tdc * - encompasses the selected choice * @param database * - the database of values collected * @param agent * @param index * - a list of time points which will be plotted on the x axis * @param choiceRange * - the y axis will be [0, choiceRange] */ public static void graphChoiceEvolution(tdComponent tdc, tdDataBase database, Agent agent, List<Double> index, double choiceRange) { String label = PpChoice.ppConcise(tdc.getChoice(), agent); // create a general purpose xy collection for jfreechart XYSeriesCollection xysc = new XYSeriesCollection(); // focus and memory xysc.addSeries(new XYSeries("ChoiceScoreIndependent")); xysc.addSeries(new XYSeries("ChoiceScoreDependent")); xysc.addSeries(new XYSeries("ChoiceScoreMood")); // Fill in the values for (Double time : index) { double dtime = time; double valueChoiceScoreIndependent = database.getChoiceScoreDependent(tdc.getIdentifier(), time); xysc.getSeries("ChoiceScoreIndependent").add(dtime, valueChoiceScoreIndependent); double valueChoiceScoreDependent = database.getChoiceScoreDependent(tdc.getIdentifier(), time); xysc.getSeries("ChoiceScoreDependent").add(dtime, valueChoiceScoreDependent); double valueChoiceScoreMood = database.getChoiceScoreDependent(tdc.getIdentifier(), time); xysc.getSeries("ChoiceScoreMood").add(dtime, valueChoiceScoreMood); } // // 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); // // the graph with the focus and the memory // XYSeriesCollection xysFM = new XYSeriesCollection(); xysFM.addSeries(xysc.getSeries("ChoiceScoreIndependent")); xysFM.addSeries(xysc.getSeries("ChoiceScoreDependent")); xysFM.addSeries(xysc.getSeries("ChoiceScoreMood")); JFreeChart chart = ChartFactory.createXYLineChart(label + " - Choice", "Time", "Value", xysFM, 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:GUI.PlotHere.java
public void PutPoint(int key, double x, double y) { Component[] a = GraphHerePanel.getComponents(); ChartPanel chartpanel = (ChartPanel) a[0]; JFreeChart chart = chartpanel.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); XYSeriesCollection data = (XYSeriesCollection) plot.getDataset(); XYSeries XYseries = data.getSeries(key); XYseries.add(x, y);//w ww . j a va 2 s .c om this.revalidate(); this.repaint(); }
From source file:examples.monalisa.gui.EvolutionRunnable.java
public void run() { try {/*from w ww . j ava 2 s .co m*/ JFreeChart chart = m_view.getChart(); XYSeriesCollection sc = (XYSeriesCollection) chart.getXYPlot().getDataset(); XYSeries series = sc.getSeries(0); series.clear(); if (m_genotype == null) { int populationSize = m_conf.getPopulationSize(); Population pop = new Population(m_conf, populationSize); for (int i = 0; i < populationSize; i++) { pop.addChromosome(GAInitialChromosomeFactory.create(m_conf)); } m_genotype = new Genotype(m_conf, pop); } // while (m_view.isEvolutionActivated()) { m_genotype.evolve(); if (m_conf.getGenerationNr() % 25 == 0) { IChromosome best = m_genotype.getFittestChromosome(); series.add(m_conf.getGenerationNr(), best.getFitnessValue()); BufferedImage image = m_conf.getPhenotypeExpresser().express(best); Graphics g = m_view.getFittestDrawingView().getMainPanel().getGraphics(); g.drawImage(image, 0, 0, m_view.getFittestDrawingView()); } } } catch (InvalidConfigurationException e) { e.printStackTrace(); System.exit(-1); } }
From source file:edu.turtlekit2.tools.chart.ChartWindow.java
/** * Update data of the charts by adding values in the series of the chart. * yValues are given in the creation order for every series. * @param chartName - the name of the chart. * @param xValue - the x-value for the added data (usually the step of simulation). * @param yValues - an array of value for every data of the series. (i.e. {num_of_red; num_of_blue; average_age}). * @see GasObserver/* w w w . j ava 2 s . c o m*/ */ public void update(String chartName, double xValue, double... yValues) { XYSeriesCollection set = sets.get(chartName); for (int i = 0; i < yValues.length; i++) { set.getSeries(i).add(xValue, yValues[i]); } }
From source file:org.locationtech.udig.processingtoolbox.tools.ChartComposite2.java
@SuppressWarnings("rawtypes") @Override/*ww w . j a v a2 s . c o m*/ public void zoom(Rectangle selection) { if (map == null || layer == null) { return; } Set<FeatureId> selected = new HashSet<FeatureId>(); try { XYSeriesCollection ds = (XYSeriesCollection) getChart().getXYPlot().getDataset(2); XYSeries selectionSeries = ds.getSeries(0); selectionSeries.clear(); EntityCollection entities = this.getChartRenderingInfo().getEntityCollection(); Iterator iter = entities.iterator(); while (iter.hasNext()) { ChartEntity entity = (ChartEntity) iter.next(); if (entity instanceof XYItemEntity) { XYItemEntity item = (XYItemEntity) entity; if (item.getSeriesIndex() != 0) { continue; } java.awt.Rectangle bound = item.getArea().getBounds(); if (selection.intersects(bound.x, bound.y, bound.width, bound.height)) { XYSeriesCollection dataSet = (XYSeriesCollection) item.getDataset(); XYSeries xySeries = dataSet.getSeries(item.getSeriesIndex()); XYDataItem xyDataItem = xySeries.getDataItem(item.getItem()); if (xyDataItem instanceof XYDataItem2) { XYDataItem2 dataItem = (XYDataItem2) xyDataItem; selectionSeries.add(dataItem); selected.add(ff.featureId(dataItem.getFeature().getID())); } } } } } catch (Exception e) { // skip } finally { if (selected.size() > 0) { map.select(ff.id(selected), layer); } else { map.select(Filter.EXCLUDE, layer); } this.forceRedraw(); } }
From source file:examples.gp.monalisa.gui.EvolutionRunnable.java
public void run() { Configuration.reset();/* www. j a v a2 s . c o m*/ try { final DrawingGPConfiguration conf = new DrawingGPConfiguration(m_view.getTargetImage()); JFreeChart chart = m_view.getChart(); XYSeriesCollection sc = (XYSeriesCollection) chart.getXYPlot().getDataset(); XYSeries series = sc.getSeries(0); series.clear(); IEventManager eventManager = conf.getEventManager(); eventManager.addEventListener(GeneticEvent.GPGENOTYPE_EVOLVED_EVENT, new GeneticEventListener() { /** * Updates the chart in the main view. * * @param a_firedEvent the event */ public void geneticEventFired(GeneticEvent a_firedEvent) { GPGenotype genotype = (GPGenotype) a_firedEvent.getSource(); int evno = genotype.getGPConfiguration().getGenerationNr(); if (evno % 25 == 0) { double bestFitness = genotype.getFittestProgram().getFitnessValue(); JFreeChart chart = m_view.getChart(); XYSeriesCollection sc = (XYSeriesCollection) chart.getXYPlot().getDataset(); XYSeries series = sc.getSeries(0); series.add(evno, bestFitness); } } }); eventManager.addEventListener(GeneticEvent.GPGENOTYPE_NEW_BEST_SOLUTION, new GeneticEventListener() { private transient Logger LOGGER2 = Logger.getLogger(EvolutionRunnable.class); private DrawingGPProgramRunner gpProgramRunner = new DrawingGPProgramRunner(conf); /** * Display best solution in fittestChromosomeView's mainPanel. * * @param a_firedEvent the event */ public void geneticEventFired(GeneticEvent a_firedEvent) { GPGenotype genotype = (GPGenotype) a_firedEvent.getSource(); IGPProgram best = genotype.getAllTimeBest(); ApplicationData data = (ApplicationData) best.getApplicationData(); LOGGER2.info("Num Points / Polygons: " + data.numPoints + " / " + data.numPolygons); BufferedImage image = gpProgramRunner.run(best); Graphics g = m_view.getFittestDrawingView().getMainPanel().getGraphics(); if (!initView) { m_view.getFittestDrawingView().setSize(204, 200 + 30); m_view.getFittestDrawingView().getMainPanel().setSize(200, 200); initView = true; } g.drawImage(image, 0, 0, m_view.getFittestDrawingView()); if (m_view.isSaveToFile()) { int fitness = (int) best.getFitnessValue(); String filename = "monalisa_" + NumberKit.niceNumber(fitness, 5, '_') + ".png"; java.io.File f = new java.io.File(filename); try { javax.imageio.ImageIO.write(image, "png", f); } catch (java.io.IOException iex) { iex.printStackTrace(); } } } }); GPProblem problem = new DrawingProblem(conf); GPGenotype gp = problem.create(); gp.setVerboseOutput(true); while (m_view.isEvolutionActivated()) { gp.evolve(); gp.calcFitness(); if (gp.getGPConfiguration().getGenerationNr() % 25 == 0) { String freeMB = SystemKit.niceMemory(SystemKit.getFreeMemoryMB()); LOGGER.info("Evolving gen. " + (gp.getGPConfiguration().getGenerationNr()) + ", mem free: " + freeMB + " MB"); } } // Create graphical tree from currently fittest image. // --------------------------------------------------- IGPProgram best = gp.getAllTimeBest(); int fitness = (int) best.getFitnessValue(); String filename = "monalisa_" + NumberKit.niceNumber(fitness, 5, '_') + ".png"; problem.showTree(best, filename); } catch (InvalidConfigurationException e) { e.printStackTrace(); System.exit(-1); } }
From source file:de.cebitec.readXplorer.plotting.MouseActions.java
@Override public void chartMouseClicked(ChartMouseEvent cme) { if (cme.getEntity() instanceof XYItemEntity) { XYItemEntity xyitem = (XYItemEntity) cme.getEntity(); // get clicked entity XYSeriesCollection dataset = (XYSeriesCollection) xyitem.getDataset(); // get data set int itemIndex = xyitem.getItem(); int seriesIndex = xyitem.getSeriesIndex(); PlotDataItem clickedItem = (PlotDataItem) dataset.getSeries(seriesIndex).getDataItem(itemIndex); showPosition(clickedItem.getFeature()); selectedItem = clickedItem;// ww w. j a v a 2 s. com selectedPoint = cme.getTrigger().getPoint(); } }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.explore.EnclosingBallController.java
public void plotXYBalls(TrackDataHolder trackDataHolder) { int selectedIndexRadius = exploreTrackController.getExploreTrackPanel().getEnclosingBallRadiusCombobox() .getSelectedIndex();//from w w w. j a v a2 s . c o m List<List<EnclosingBall>> enclosingBallsList = trackDataHolder.getStepCentricDataHolder() .getxYEnclosingBalls(); List<EnclosingBall> enclosingBalls = enclosingBallsList.get(selectedIndexRadius); // get the coordinates matrix Double[][] coordinatesMatrix = trackDataHolder.getStepCentricDataHolder().getCoordinatesMatrix(); XYSeries xYSeries = JFreeChartUtils.generateXYSeries(coordinatesMatrix); String seriesKey = "track " + trackDataHolder.getTrack().getTrackNumber() + ", well " + trackDataHolder.getTrack().getWellHasImagingType().getWell(); xYSeries.setKey(seriesKey); XYSeriesCollection ySeriesCollection = new XYSeriesCollection(xYSeries); JFreeChart chart = ChartFactory.createXYLineChart(seriesKey + " - enclosing balls", "x (m)", "y (m)", ySeriesCollection, PlotOrientation.VERTICAL, false, true, false); XYPlot xyPlot = chart.getXYPlot(); JFreeChartUtils.setupXYPlot(xyPlot); JFreeChartUtils.setupSingleTrackPlot(chart, exploreTrackController.getExploreTrackPanel().getTracksList().getSelectedIndex(), true); XYSeriesCollection dataset = (XYSeriesCollection) xyPlot.getDataset(0); double minY = dataset.getSeries(0).getMinY(); double maxY = dataset.getSeries(0).getMaxY(); xyPlot.getRangeAxis().setRange(minY - 10, maxY + 10); xYBallsChartPanel.setChart(chart); enclosingBalls.stream().forEach((ball) -> { xyPlot.addAnnotation(new XYShapeAnnotation(ball.getShape(), JFreeChartUtils.getDashedLine(), GuiUtils.getDefaultColor())); }); }