public static ChartPanel getAvgRewardsChart(BotStatistic stats) { XYSeriesCollection ds = new XYSeriesCollection(); LinkedList<BotSeries> series = new LinkedList<BotSeries>(); for (String botName : stats.getAllRewardedBotNames()) { series.add(new BotSeries(new XYSeries(botName), 0, 0, botName)); } String allName = "all RL"; int botsNum = stats.getAllRewardedBotNames().size(); series.add(new BotSeries(new XYSeries(allName), 0, 0, allName)); int segmentSize = stats.rewards.size() / avgRewardsChartSegments; if (segmentSize < 1) { segmentSize = 1; } int i = 0; for (Reward k : stats.rewards) { for (BotSeries s : series) { if (k.botName.equals(s.botName)) { s.d1 += k.reward; } } i++; if (i % segmentSize == 0) { BotSeries as = series.getLast(); for (BotSeries s : series) { if (s.botName.equals(as.botName)) continue; s.series.add(k.time - segmentSize / 2 / 10, s.d1 / segmentSize); as.d1 += s.d1; s.d1 = 0; } as.series.add(k.time - segmentSize / 2 / 10, as.d1 / (botsNum * segmentSize)); as.d1 = 0; } } for (BotSeries s : series) { ds.addSeries(s.series); } JFreeChart c = ChartFactory.createXYLineChart( "avg reward gaining speed", "time [s]", "avg reward gaining speed", ds, PlotOrientation.VERTICAL, true, true, true); ChartPanel cp = new ChartPanel(c); return cp; }
private static JFreeChart createChart(XYDataset dataset, String exp) { JFreeChart chart = ChartFactory.createXYLineChart( "", "", "", dataset, PlotOrientation.VERTICAL, false, false, false); chart.setBorderVisible(false); chart.setAntiAlias(true); chart.setBackgroundPaint(Color.getHSBColor((float) 0, (float) 0, (float) 0.96)); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainPannable(true); plot.setRangePannable(true); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.WHITE); // 网格线颜色 plot.setNoDataMessage("No data!"); plot.setOutlinePaint(Color.WHITE); plot.setRangeGridlinePaint(Color.WHITE); plot.setBackgroundPaint(Color.getHSBColor((float) 0, (float) 0.01, (float) 0.91)); // xylineandshaperenderer.setShapesFilled(true); NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setAutoRange(true); axis.setPositiveArrowVisible(true); axis.setAutoRangeIncludesZero(true); axis.setAutoRangeStickyZero(true); // List axisIndices = Arrays.asList(new Integer[] {new Integer(0), // new Integer(1)}); // plot.mapDatasetToDomainAxes(0, axisIndices); // plot.mapDatasetToRangeAxes(0, axisIndices); // ChartUtilities.applyCurrentTheme(chart); return chart; }
public PlotterXY(String chartTitle) { setLayout(new BorderLayout()); mIdeal = new XYSeries("Ideal Position"); mReal = new XYSeries("Ideal Velocity"); mCollection = new XYSeriesCollection(); mCollection.addSeries(mIdeal); mCollection.addSeries(mReal); final JFreeChart chart = ChartFactory.createXYLineChart( chartTitle, "X (Inches)", "Y (Inches)", mCollection, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); m_chartPanel = new ChartPanel(chart); m_chartPanel.setPreferredSize(new Dimension(400, 300)); m_chartPanel.setBackground(getBackground()); add(m_chartPanel, BorderLayout.CENTER); }
private void crearImagen() { XYSeries serie = new XYSeries("Serie"); Iterator<Double> iterator = ejercicio.getHistoricoSolucion().iterator(); for (int i = 0; i < ejercicio.getHistoricoSolucion().size(); i++) { serie.add(i, iterator.next()); } XYSeriesCollection coleccionSeries = new XYSeriesCollection(); coleccionSeries.addSeries(serie); JFreeChart chart = ChartFactory.createXYLineChart( "Comportamiento Simulated Annealing", "Ciclo", "Solucion", coleccionSeries, PlotOrientation.VERTICAL, false, false, true); ChartPanel panel = new ChartPanel(chart); panel.setMouseZoomable(true); this.add(panel); }
public JFreeChart crearGrafica(XYSeriesCollection dataset) { final JFreeChart chart = ChartFactory.createXYLineChart( "ECG", "Tiempo", "Voltios", dataset, PlotOrientation.VERTICAL, true, // uso de leyenda false, // uso de tooltips false // uso de urls ); // color de fondo de la gráfica chart.setBackgroundPaint(COLOR_FONDO_GRAFICA); final XYPlot plot = (XYPlot) chart.getPlot(); configurarPlot(plot); final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); configurarDomainAxis(domainAxis); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); configurarRangeAxis(rangeAxis); final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); configurarRendered(renderer); return chart; }
@Override protected void setChart() { SeriesManager<Double, Double> sf = new SeriesManager<Double, Double>(intermediateData); List<DataSeries<Double, Double>> seriesList = sf.getSeries(); DataSeries<Double, Double> series = seriesList.get(0); List<SeriesPair<Double, Double>> values = series.getSeriesValues(Double.class, Double.class); XYSeries deltaMassSeries = new XYSeries(series.getIdentifier()); for (SeriesPair<Double, Double> value : values) { deltaMassSeries.add(value.getX(), value.getY()); } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(deltaMassSeries); chart = ChartFactory.createXYLineChart( getChartTitle(), // chart title "Experimental m/z - Theoretical m/z", // x axis label "Relative Frequency", // y axis label dataset, // chartData PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls ); chart.addSubtitle(new TextTitle(getChartSubTitle())); XYPlot plot = chart.getXYPlot(); plot.setDomainZeroBaselineVisible(true); plot.setBackgroundAlpha(0f); plot.setDomainGridlinePaint(Color.red); plot.setRangeGridlinePaint(Color.blue); }
private JFreeChart createChart(final GraphBuilder builder) { final JFreeChart chart = ChartFactory.createXYLineChart( builder.graphTitle(), builder.xAxisLabel(), builder.yAxisLabel(), builder.dataset(), PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); final ValueAxis rangeAxis = plot.getRangeAxis(); // rangeAxis.setRange(0,20); final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseItemLabelsVisible(true); if (builder.yRange0To1()) { chart.getXYPlot().getRangeAxis().setRange(0.0, 1.0); } return chart; }
private static JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createXYLineChart( "Ratings by Age", // Title "Age", // X label "Average Rating", // Y label dataset, // data PlotOrientation.VERTICAL, // Orientation false, // legend false, // tooltips false); // urls chart.setBorderPaint(Color.white); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, true); plot.setRenderer(renderer); // change the auto tick unit selection to integer units only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return chart; }
public void displayWithOtherSignals( ArrayList<GeneralSignal> otherSignals, String title, boolean shapeVisible) { JFreeChart chart; XYSeriesCollection xyDataSet = new XYSeriesCollection(this.data); for (int i = 0; i < otherSignals.size(); i++) { xyDataSet.addSeries(otherSignals.get(i).getData()); } chart = ChartFactory.createXYLineChart( title, // Title "Abscissa", // X axis label "Ordinate", // Y axis label xyDataSet, // dataset PlotOrientation.VERTICAL, // orientation true, // legends true, // tool tips true); // urls if (shapeVisible) { XYPlot plot = (XYPlot) chart.getPlot(); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setSeriesShapesVisible(0, true); renderer.setSeriesShapesFilled(0, true); } } ChartFrame frame = new ChartFrame("Frame Title", chart); frame.setVisible(true); frame.setSize(512, 512); }
public void draw(Configuration conf) throws IOException { List<Pair<Integer, Integer>> list = new ArrayList<Pair<Integer, Integer>>(); SequenceFileDirIterator<IntWritable, IntWritable> iterator = new SequenceFileDirIterator<IntWritable, IntWritable>( inputPath, PathType.LIST, MultipleSequenceOutputFormat.FILTER, null, true, conf); while (iterator.hasNext()) { Pair<IntWritable, IntWritable> writablePair = iterator.next(); Pair<Integer, Integer> pair = new Pair<Integer, Integer>(writablePair.getFirst().get(), writablePair.getSecond().get()); list.add(pair); } iterator.close(); Collections.sort( list, new Comparator<Pair<Integer, Integer>>() { @Override public int compare(Pair<Integer, Integer> o1, Pair<Integer, Integer> o2) { if (o1.getFirst() < o2.getFirst()) { return -1; } return 1; } }); XYDataset dataSet = createDataSet(list); JFreeChart chart = ChartFactory.createXYLineChart( title, "", "count", dataSet, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setNumberFormatOverride(numberFormat); BufferedImage image = chart.createBufferedImage(WIDTH, HEIGHT); ImageIO.write(image, FORMAT, new File(imgFile)); }
private JPanel createChartPanel(XYDataset dataset, TimeInterval ti) { JPanel ret = new JPanel(); BoxLayout retLayout = new BoxLayout(ret, javax.swing.BoxLayout.Y_AXIS); ret.setLayout(retLayout); JFreeChart chart = ChartFactory.createXYLineChart( null, // title "Delay, seconds", "Correlation", dataset, // dataset PlotOrientation.VERTICAL, // orientation true, // legend true, // tooltips false // include URLs ); TextTitle title = new TextTitle( "Start time: " + TimeInterval.formatDate( ti.getStartTime(), TimeInterval.DateFormatType.DATE_FORMAT_NORMAL) + ", Duration: " + ti.convert(), ret.getFont()); chart.setTitle(title); plot = (XYPlot) chart.getPlot(); cp = new TraceViewChartPanel(chart, true); ret.add(cp); ret.add(getOptionP()); return ret; }
/** * Create a chart with the underlying dataset. * * @return The chart. */ protected JFreeChart createChart() { String title = (String) getProperty("title"); String labelx = (String) getProperty("labelx"); String labely = (String) getProperty("labely"); boolean legend = getProperty("legend") == null ? true : ((Boolean) getProperty("legend")).booleanValue(); boolean tooltips = getProperty("tooltips") == null ? true : ((Boolean) getProperty("tooltips")).booleanValue(); boolean urls = getProperty("urls") == null ? false : ((Boolean) getProperty("urls")).booleanValue(); boolean autorepaint = getProperty("autorepaint") == null ? false : ((Boolean) getProperty("autorepaint")).booleanValue(); XYDataset dataset = new VectorSeriesCollection(); JFreeChart chart = ChartFactory.createXYLineChart( title, labelx, labely, dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); chart.setNotify(autorepaint); // chart.setBackgroundPaint(new Color(100,100,100,100)); // chart.getPlot().setBackgroundAlpha(0.5f); String bgimagefn = (String) getProperty("bgimage"); if (bgimagefn != null) { try { IApplication app = getSpace().getContext(); ClassLoader cl = ((ILibraryService) SServiceProvider.getService(app.getServiceProvider(), ILibraryService.class) .get(new ThreadSuspendable())) .getClassLoader(); ResourceInfo rinfo = getResourceInfo(bgimagefn, app.getApplicationType().getAllImports(), cl); Image image = ImageIO.read(rinfo.getInputStream()); rinfo.getInputStream().close(); // chart.setBackgroundImage(image); chart.getPlot().setBackgroundImage(image); } catch (Exception e) { System.out.println("Background image not found: " + bgimagefn); } } // ChartPanel panel = new ChartPanel(chart); // panel.setFillZoomRectangle(true); // JFrame f = new JFrame(); // JPanel content = new JPanel(new BorderLayout()); // content.add(panel, BorderLayout.CENTER); // f.setContentPane(panel); // f.pack(); // f.setVisible(true); return chart; }
/** * Displays a signal (using the JFreeChart package). * * @param useChart if set to true, the signal is displaied as a bar chart (this is used for * histograms). */ public void display(boolean useChart) { JFreeChart chart; int nbSamples = getNbSamples(); if (useChart) { String[] categories = new String[nbSamples]; for (int i = 0; i < nbSamples; i++) { categories[i] = data.getX(i).toString(); } String[] categoryNames = {"Histogram"}; double[][] categoryData = new double[1][nbSamples]; for (int i = 0; i < nbSamples; i++) { categoryData[0][i] = data.getY(i).doubleValue(); } CategoryDataset categoryDataset = DatasetUtilities.createCategoryDataset(categoryNames, categories, categoryData); chart = ChartFactory.createBarChart( "Histogram", // Title "Data Value", // X axis label "Number of Elements", // Y axis label categoryDataset, // dataset PlotOrientation.VERTICAL, // orientation true, // legends true, // tool tips true); } else { XYDataset xyDataSet = new XYSeriesCollection(this.data); chart = ChartFactory.createXYLineChart( "Example Dataset", // Title "Abscissa", // X axis label "Ordinate", // Y axis label xyDataSet, // dataset PlotOrientation.VERTICAL, // orientation true, // legends true, // tool tips true); // urls XYPlot plot = (XYPlot) chart.getPlot(); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setSeriesShapesVisible(0, true); renderer.setSeriesShapesFilled(0, true); } } ChartFrame frame = new ChartFrame("Frame Title", chart); frame.setVisible(true); frame.setSize(512, 512); }
private static JFreeChart makeChart(XYDataset aDataset) { return ChartFactory.createXYLineChart( "Comparing payload tonnage for given speeds", "km/h", "payload tons", aDataset, PlotOrientation.VERTICAL, true, false, false); }
public ChartPanel newChart(XYSeriesCollection datatempcopy) { JFreeChart chart = ChartFactory.createXYLineChart( title, xaxis, yaxis, datatempcopy, PlotOrientation.VERTICAL, true, true, false); chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(this.getWidth(), this.getHeight())); return chartPanel; }
private JFreeChart createChart( final String title, final String xAxis, final String yAxis, final XYDataset dataset) { final JFreeChart chart = ChartFactory.createXYLineChart( title, xAxis, yAxis, dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return chart; }
@Override protected JFreeChart createChart(Map<String, Object> model, HttpServletRequest request) { UsageStatisticsService svc = Context.getService(UsageStatisticsService.class); List<Object[]> stats = svc.getDateRangeStats(null, null, null); String xAxisLabel = ContextProvider.getMessage("usagestatistics.chart.date"); String yAxisLabel = ContextProvider.getMessage("usagestatistics.chart.records"); String seriesUsages = ContextProvider.getMessage("usagestatistics.results.views"); String seriesEncounters = ContextProvider.getMessage("usagestatistics.results.encounters"); String seriesUpdates = ContextProvider.getMessage("usagestatistics.results.updates"); // Get minimum date value in returned statistics Date minDate = (stats.size() > 0) ? (Date) (stats.get(0)[0]) : getFromDate(); if (minDate.getTime() > getFromDate().getTime()) // Min date must be at least a week ago minDate = getFromDate(); // Maximum date defaults to today Date maxDate = (getUntilDate() != null) ? getUntilDate() : new Date(); // Build a zeroized dataset of all dates in range TimeTableXYDataset dataset = new TimeTableXYDataset(); Calendar cal = new GregorianCalendar(); cal.setTime(minDate); while (cal.getTime().getTime() <= maxDate.getTime()) { Date day = cal.getTime(); dataset.add(new Day(day), 0, seriesUsages, false); dataset.add(new Day(day), 0, seriesEncounters, false); dataset.add(new Day(day), 0, seriesUpdates, false); cal.add(Calendar.DATE, 1); } // Update the dates for which we have statistics for (Object[] row : stats) { Date date = (Date) row[0]; int usages = ((Number) row[1]).intValue(); int encounters = ((Number) row[2]).intValue(); int updates = ((Number) row[3]).intValue(); dataset.add(new Day(date), usages, seriesUsages, false); dataset.add(new Day(date), encounters, seriesEncounters, false); dataset.add(new Day(date), updates, seriesUpdates, false); } dataset.setDomainIsPointsInTime(true); JFreeChart chart = ChartFactory.createXYLineChart( null, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, true, false, false); DateAxis xAxis = new DateAxis(xAxisLabel); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainAxis(xAxis); return chart; }
public static HashMap<String, ChartPanel> getGraphs(LinkedList<Game> games) { HashMap<String, XYSeriesCollection> datasets = new HashMap<>(); for (int j = 0; j < games.size(); j++) { Game game = games.get(j); if (game == null) { continue; } for (String key : game.getVarData().keySet()) { if (datasets.containsKey(key)) { try { datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId())); } catch (Exception e) { } } else { datasets.put(key, new XYSeriesCollection()); datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId())); } } } HashMap<String, ChartPanel> chartPanels = new HashMap<>(); for (String key : datasets.keySet()) { JFreeChart chart = ChartFactory.createXYLineChart( key, // chart title "X", // x axis label "Y", // y axis label datasets.get(key), // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls ); XYPlot plot = chart.getXYPlot(); XYItemRenderer rend = plot.getRenderer(); for (int i = 0; i < games.size(); i++) { Game g = games.get(i); if (g.getWinner() == 1) { rend.setSeriesPaint(i, Color.RED); } if (g.getWinner() == 2) { rend.setSeriesPaint(i, Color.BLACK); } if (g.getWinner() == 0) { rend.setSeriesPaint(i, Color.PINK); } } ChartPanel chartPanel = new ChartPanel(chart); chartPanels.put(key, chartPanel); } return chartPanels; }
public static ChartPanel getKillsPerEachDeathByBotType(BotStatistic stats) { XYSeriesCollection ds = new XYSeriesCollection(); LinkedList<BotSeries> series = new LinkedList<BotSeries>(); for (String botName : stats.getAllBotFamilies()) { series.add(new BotSeries(new XYSeries(botName), 0, 0, botName)); } for (BotSeries s : series) { s.series.add(0, 0); s.d1 = StatsTools.countBotsOfGivenFamilly(s.botName, stats); } for (Kill k : stats.kills) { for (BotSeries s : series) { if (k.killer.startsWith(s.botName) || k.victim.startsWith(s.botName)) { if (k.killer.startsWith(s.botName)) { s.int1++; } if (k.victim.startsWith(s.botName)) { s.int2++; } float val = 0; if (s.int2 != 0) { val = (float) s.int1 / (float) s.int2; } s.series.add(k.time / 10, val / s.d1); } } } for (BotSeries s : series) { ds.addSeries(s.series); } JFreeChart c = ChartFactory.createXYLineChart( "Kills per each death by bot type in time", "time [s]", "kills / deaths", ds, PlotOrientation.VERTICAL, true, true, true); ChartPanel cp = new ChartPanel(c); return cp; }
public static void createGraphs(LinkedList<Game> games) { HashMap<String, XYSeriesCollection> datasets = new HashMap<>(); for (Game game : games) { for (String key : game.getVarData().keySet()) { if (datasets.containsKey(key)) { try { datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId())); } catch (Exception e) { } } else { datasets.put(key, new XYSeriesCollection()); datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId())); } } } for (String key : datasets.keySet()) { JFrame f = new JFrame(); JFreeChart chart = ChartFactory.createXYLineChart( key, // chart title "X", // x axis label "Y", // y axis label datasets.get(key), // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls ); XYPlot plot = chart.getXYPlot(); XYItemRenderer rend = plot.getRenderer(); for (int i = 0; i < games.size(); i++) { Game g = games.get(i); if (g.getWinner() == 1) { rend.setSeriesPaint(i, Color.RED); } if (g.getWinner() == 2) { rend.setSeriesPaint(i, Color.BLACK); } if (g.getWinner() == 0) { rend.setSeriesPaint(i, Color.PINK); } } ChartPanel chartPanel = new ChartPanel(chart); f.setContentPane(chartPanel); f.pack(); RefineryUtilities.centerFrameOnScreen(f); f.setVisible(true); } }
/** * Creates a chart. * * @param dataset the data for the chart. * @return a chart. */ private JFreeChart createChart(XYDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createXYLineChart( region + ", flows " + flowlist + " " + baselist, // chart // title "timestamp", getYaxis(), // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); if (subtitle != null) { final TextTitle s = new TextTitle(subtitle); s.setFont(new Font("SansSerif", Font.PLAIN, 12)); s.setPosition(RectangleEdge.TOP); // subtitle.setSpacer(new Spacer(Spacer.RELATIVE, 0.05, 0.05, 0.05, 0.05)); // s.setVerticalAlignment(VerticalAlignment.TOP); chart.addSubtitle(s); } // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // chart.setBackgroundPaint(Color.white); chart.setBackgroundImageAlpha(1.0f); // chart.addSubtitle(new TextTitle(file.getName())); // get a reference to the plot for further customisation... XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.black); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.gray); plot.setRangeGridlinePaint(Color.gray); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setShapesVisible(false); renderer.setShapesFilled(false); // change the auto tick unit selection to integer units only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); ValueAxis va = plot.getDomainAxis(); va.setAutoRangeMinimumSize(1000); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
@Override public String getReport() { // Time series XYSeries dSeries = ChartUtils.createXYSeries(counts, "Nb Edges Time Series"); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(dSeries); JFreeChart chart = ChartFactory.createXYLineChart( "# Edges Time Series", "Time", "# Edges", dataset, PlotOrientation.VERTICAL, true, false, false); chart.removeLegend(); ChartUtils.decorateChart(chart); ChartUtils.scaleChart(chart, dSeries, false); String imageFile = ChartUtils.renderChart(chart, "nb-edges-ts.png"); NumberFormat f = new DecimalFormat("#0.000"); String report = "<HTML> <BODY> <h1>Dynamic Number of Edges Report </h1> " + "<hr>" + "<br> Bounds: from " + f.format(bounds.getLow()) + " to " + f.format(bounds.getHigh()) + "<br> Window: " + window + "<br> Tick: " + tick + "<br><br><h2> Number of edges over time: </h2>" + "<br /><br />" + imageFile; /*for (Interval<Integer> count : counts) { report += count.toString(dynamicModel.getTimeFormat().equals(DynamicModel.TimeFormat.DOUBLE)) + "<br />"; }*/ report += "<br /><br /></BODY></HTML>"; return report; }
/** * Create a GUI that shows a graph for the specified user's payoff history * * @param user The user to show the Payoff history for */ public GraphGUI(User user) { super( user.getUserName() + "'s Payoff History (Over " + user.getPayoffHistory().size() + " Steps)"); this.userInfo = user; this.pack(); // Set size this.setMinimumSize(new Dimension(500, 500)); // Center the graph this.setLocationRelativeTo(null); // Create a series collection xySeriesCollection = new XYSeriesCollection(); // Create (refresh) chart data refreshChartData(); // Create an XY Line Chart chart = ChartFactory.createXYLineChart( "User Payoff Over Time", "Steps (Simulation Iterations)", "User Payoff", xySeriesCollection); chart.getPlot().setBackgroundPaint(Color.WHITE); chart.getPlot().setOutlinePaint(Color.BLACK); // Draw the Initial Chart chart.draw( (Graphics2D) this.getGraphics(), (Rectangle2D) new Rectangle2D.Double(0, 0, this.getWidth(), this.getHeight())); // Set the content pane to a graphics panel for drawing the graph this.setContentPane(new GraphPanel(this)); // Show the frame this.setVisible(true); // Subscribe to the user's UserPayoff events user.addPayoffListener(this); }
public static ChartPanel getKillsInTimeByBot(BotStatistic stats) { XYSeriesCollection ds = new XYSeriesCollection(); LinkedList<BotSeries> series = new LinkedList<BotSeries>(); for (String botName : stats.getAllKillingBotNames()) { series.add(new BotSeries(new XYSeries(botName), 0, 0, botName)); } for (BotSeries s : series) { s.series.add(0, 0); } for (Kill k : stats.kills) { for (BotSeries s : series) { if (s.botName.equals(k.killer)) { s.int1++; s.series.add(k.time / 10, s.int1); } } } for (BotSeries s : series) { ds.addSeries(s.series); } JFreeChart c = ChartFactory.createXYLineChart( "Kills by each bot in time", "time [s]", "kills", ds, PlotOrientation.VERTICAL, true, true, true); // XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) // ((XYPlot)c.getPlot()).getRenderer(); // r.setDrawOutlines(true); // r.setShapesVisible(true); ChartPanel cp = new ChartPanel(c); return cp; }
private static JFreeChart createChart(XYDataset xydataset) { JFreeChart jfreechart = ChartFactory.createXYLineChart( "Line Chart Demo 2", "X", "Y", xydataset, PlotOrientation.VERTICAL, true, true, false); jfreechart.setBackgroundPaint(Color.white); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer(); xylineandshaperenderer.setBaseShapesVisible(true); xylineandshaperenderer.setBaseShapesFilled(true); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return jfreechart; }
/** Creates a chart */ private JFreeChart createChart( XYDataset dataset, String sensorName, String timeUnit, String sensorUnit) { final JFreeChart chart = ChartFactory.createXYLineChart( sensorName, // chart title timeUnit, // x axis label sensorUnit, // y axis label dataset, // data PlotOrientation.VERTICAL, false, // include legend false, // tooltips false // urls ); return chart; }
/** Creates a JFreeChart */ private void setupChart(ChartType type) { this.type = type; // Create a dataset dataset = new XYSeriesCollection(); JFreeChart chart; // Create a chart if (type == ChartType.PIE_CHART) { pieData = new DefaultPieDataset(); chart = ChartFactory.createPieChart(null, pieData, true, false, false); } else { chart = ChartFactory.createXYLineChart( null, "x", "y", dataset, PlotOrientation.VERTICAL, true, false, false); } // Create a chart panel ChartPanel panel = new ChartPanel(chart); panel.setMinimumSize(new Dimension(100, 100)); panel.setPreferredSize(new Dimension(400, 300)); // Create additional control elements JPanel controlPanel = new JPanel(new GridLayout(1, 3)); clearButton = new JButton("Clear"); saveButton = new JButton("Save"); removeButton = new JButton("Remove"); clearButton.setActionCommand(CMD_CLEAR); saveButton.setActionCommand(CMD_SAVE); removeButton.setActionCommand(CMD_REMOVE); clearButton.addActionListener(this); saveButton.addActionListener(this); removeButton.addActionListener(this); // Add controls to the control panel controlPanel.add(clearButton); controlPanel.add(saveButton); controlPanel.add(removeButton); this.add(panel, BorderLayout.CENTER); this.add(controlPanel, BorderLayout.SOUTH); }
/** * @param games the games to graph * @param key the variable to create the graph with * @param start if index, the index at which to start, else the percent in the game at which to * start * @param stop if index, the index at which to end, else the percent in the game at which to end * @param index * @return */ public static ChartPanel getCustomGraph( Game[] games, String key, double start, double stop, boolean index) { XYSeriesCollection dataset = new XYSeriesCollection(); for (Game game : games) { ArrayList<Double> data = game.getVar(key); int begin; int end; if (index) { begin = (int) start; end = (int) stop; } else { begin = (int) (data.size() / start); end = (int) (data.size() / stop); } XYSeries series = GraphUtility.createSeries(data.subList(begin, end), "" + game.getId()); dataset.addSeries(series); } JFreeChart chart = ChartFactory.createXYLineChart( key, // chart title "X", // x axis label "Y", // y axis label dataset, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls ); XYPlot plot = chart.getXYPlot(); XYItemRenderer rend = plot.getRenderer(); for (int i = 0; i < games.length; i++) { Game g = games[i]; if (g.getWinner() == 1) { rend.setSeriesPaint(i, Color.RED); } if (g.getWinner() == 2) { rend.setSeriesPaint(i, Color.BLACK); } if (g.getWinner() == 0) { rend.setSeriesPaint(i, Color.PINK); } } ChartPanel chartPanel = new ChartPanel(chart); return chartPanel; }
private JFreeChart createChart(XYDataset dataset, String title) { // create the chart... final JFreeChart chart = ChartFactory.createXYLineChart( title, // chart title "x", // domain axis label "y", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // final StandardLegend legend = (StandardLegend) chart.getLegend(); // legend.setDisplaySeriesShapes(true); // legend.setShapeScaleX(1.5); // legend.setShapeScaleY(1.5); // legend.setDisplaySeriesLines(true); chart.setBackgroundPaint(Color.white); chart.setAntiAlias(false); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(1, true); renderer.setSeriesShapesVisible(1, false); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, false); plot.setRenderer(renderer); // change the auto tick unit selection to integer units only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
public static void generateXYScatterPlot( String fileName, double[] x, double[] y, String title, String xLabel, String yLabel) { if (x.length != y.length) { DebugLib.stopSystemAndReportInconsistency("dimensions of arrays do not match"); } final XYSeries series1 = new XYSeries(title); for (int i = 0; i < x.length; i++) { series1.add(x[i], y[i]); } final XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series1); final JFreeChart chart = ChartFactory.createXYLineChart( title, xLabel, yLabel, dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShapesVisible(1, false); plot.setRenderer(renderer); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); int width = 500; int height = 300; try { ChartUtilities.saveChartAsPNG(new File(fileName), chart, width, height); } catch (IOException e) { } }