List of usage examples for org.jfree.chart JFreeChart getXYPlot
public XYPlot getXYPlot()
From source file:com.romraider.logger.ecu.ui.handler.graph.GraphUpdateHandler.java
private JFreeChart createXYLineChart(LoggerData loggerData, XYDataset dataset, boolean combined) { String title = combined ? "Combined Data" : loggerData.getName(); String rangeAxisTitle = combined ? "Data" : buildRangeAxisTitle(loggerData); JFreeChart chart = ChartFactory.createXYLineChart(title, "Time (sec)", rangeAxisTitle, dataset, VERTICAL, false, true, false);/*from w w w . j av a 2 s . co m*/ chart.setBackgroundPaint(BLACK); chart.getTitle().setPaint(WHITE); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(BLACK); plot.getDomainAxis().setLabelPaint(WHITE); plot.getRangeAxis().setLabelPaint(WHITE); plot.getDomainAxis().setTickLabelPaint(LIGHT_GREY); plot.getRangeAxis().setTickLabelPaint(LIGHT_GREY); plot.setDomainGridlinePaint(DARK_GREY); plot.setRangeGridlinePaint(DARK_GREY); plot.setOutlinePaint(DARK_GREY); return chart; }
From source file:org.jfree.chart.demo.MarkerDemo1.java
/** * Creates a sample chart.// w w w . j ava 2s. co m * * @param data the sample data. * * @return A configured chart. */ private JFreeChart createChart(final XYDataset data) { final JFreeChart chart = ChartFactory.createScatterPlot("Marker Demo 1", "X", "Y", data, PlotOrientation.VERTICAL, true, true, false); // chart.getLegend().setAnchor(Legend.EAST); // customise... final XYPlot plot = chart.getXYPlot(); plot.getRenderer().setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); // set axis margins to allow space for marker labels... final DateAxis domainAxis = new DateAxis("Time"); domainAxis.setUpperMargin(0.50); plot.setDomainAxis(domainAxis); final ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setUpperMargin(0.30); rangeAxis.setLowerMargin(0.50); // add a labelled marker for the bid start price... final Marker start = new ValueMarker(200.0); start.setPaint(Color.green); start.setLabel("Bid Start Price"); start.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); start.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addRangeMarker(start); // add a labelled marker for the target price... final Marker target = new ValueMarker(175.0); target.setPaint(Color.red); target.setLabel("Target Price"); target.setLabelAnchor(RectangleAnchor.TOP_RIGHT); target.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); plot.addRangeMarker(target); // add a labelled marker for the original closing time... final Hour hour = new Hour(2, new Day(22, 5, 2003)); double millis = hour.getFirstMillisecond(); final Marker originalEnd = new ValueMarker(millis); originalEnd.setPaint(Color.orange); originalEnd.setLabel("Original Close (02:00)"); originalEnd.setLabelAnchor(RectangleAnchor.TOP_LEFT); originalEnd.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addDomainMarker(originalEnd); // add a labelled marker for the current closing time... final Minute min = new Minute(15, hour); millis = min.getFirstMillisecond(); final Marker currentEnd = new ValueMarker(millis); currentEnd.setPaint(Color.red); currentEnd.setLabel("Close Date (02:15)"); currentEnd.setLabelAnchor(RectangleAnchor.TOP_RIGHT); currentEnd.setLabelTextAnchor(TextAnchor.TOP_LEFT); plot.addDomainMarker(currentEnd); // **************************************************************************** // * JFREECHART DEVELOPER GUIDE * // * The JFreeChart Developer Guide, written by David Gilbert, is available * // * to purchase from Object Refinery Limited: * // * * // * http://www.object-refinery.com/jfreechart/guide.html * // * * // * Sales are used to provide funding for the JFreeChart project - please * // * support us so that we can continue developing free software. * // **************************************************************************** // label the best bid with an arrow and label... final Hour h = new Hour(2, new Day(22, 5, 2003)); final Minute m = new Minute(10, h); millis = m.getFirstMillisecond(); final CircleDrawer cd = new CircleDrawer(Color.red, new BasicStroke(1.0f), null); final XYAnnotation bestBid = new XYDrawableAnnotation(millis, 163.0, 11, 11, cd); plot.addAnnotation(bestBid); final XYPointerAnnotation pointer = new XYPointerAnnotation("Best Bid", millis, 163.0, 3.0 * Math.PI / 4.0); pointer.setBaseRadius(35.0); pointer.setTipRadius(10.0); pointer.setFont(new Font("SansSerif", Font.PLAIN, 9)); pointer.setPaint(Color.blue); pointer.setTextAnchor(TextAnchor.HALF_ASCENT_RIGHT); plot.addAnnotation(pointer); return chart; }
From source file:de.suse.swamp.modules.scheduledjobs.Statistics.java
/** * Generating the graphs that show the amount of running finished wfs over the time. *//* www . ja v a 2 s . com*/ protected void generateWorkflowGraph(String templateName, Date startDate, Date endDate) throws Exception { List stats = StatisticStorage.loadStats(templateName, startDate, endDate); // only generate if we have stats: if (stats != null && stats.size() > 0) { TimeSeriesCollection dataset = new TimeSeriesCollection(); TimeSeriesCollection avgdataset = new TimeSeriesCollection(); TimeSeries serie = new TimeSeries("running workflows", Day.class); TimeSeries avgserie = new TimeSeries("average age", Day.class); for (Iterator datait = stats.iterator(); datait.hasNext();) { Dbstatistics statisticItem = (Dbstatistics) datait.next(); serie.addOrUpdate(new Day(statisticItem.getDate()), statisticItem.getRunningcount()); avgserie.addOrUpdate(new Day(statisticItem.getDate()), statisticItem.getAvgage() / (3600 * 24)); } dataset.addSeries(serie); avgdataset.addSeries(avgserie); JFreeChart chart = ChartFactory.createTimeSeriesChart("Running " + templateName + " workflows", "Date", "running workflows", dataset, false, false, false); // modify chart appearance chart.setBackgroundImageAlpha(0.5f); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.getRangeAxis().setLabelPaint(Color.blue); // add the second line: final NumberAxis axis2 = new NumberAxis("Avg. age in days"); axis2.setLabelPaint(Color.red); plot.setRangeAxis(1, axis2); plot.setDataset(1, avgdataset); plot.mapDatasetToRangeAxis(1, 1); final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(); renderer2.setDrawOutlines(false); renderer2.setDrawSeriesLineAsPath(true); renderer2.setBaseShapesVisible(false); plot.setRenderer(1, renderer2); File image = new File(statPath + fs + templateName + ".png"); if (image.exists()) image.delete(); try { ChartUtilities.saveChartAsPNG(image, chart, 750, 200); } catch (Exception e) { Logger.ERROR("Error generating graph for " + templateName + ", e: " + e.getMessage()); e.printStackTrace(); throw e; } } }
From source file:beadAnalyzer.DrawPoints.java
protected JFreeChart createChart(final IntervalXYDataset dataset, final String title, final String units) { final JFreeChart chart = ChartFactory.createXYBarChart(title, "Pixel [" + units + "]", false, "Count", dataset, PlotOrientation.VERTICAL, false, // legend false, false);/*from w w w . j a va 2s . com*/ NumberAxis range = (NumberAxis) chart.getXYPlot().getDomainAxis(); range.setRange(getMin(), getMax()); XYPlot plot = chart.getXYPlot(); XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, Color.red); renderer.setDrawBarOutline(true); renderer.setSeriesOutlinePaint(0, Color.black); renderer.setBarPainter(new StandardXYBarPainter()); return chart; }
From source file:org.jfree.chart.demo.XYTickLabelDemo.java
/** * Creates the demo chart./* ww w. j av a2 s . com*/ * * @return The chart. */ private JFreeChart createChart() { // create some sample data final XYSeries series1 = new XYSeries("Something"); series1.add(0.0, 30.0); series1.add(1.0, 10.0); series1.add(2.0, 40.0); series1.add(3.0, 30.0); series1.add(4.0, 50.0); series1.add(5.0, 50.0); series1.add(6.0, 70.0); series1.add(7.0, 70.0); series1.add(8.0, 80.0); final XYSeriesCollection dataset1 = new XYSeriesCollection(); dataset1.addSeries(series1); final XYSeries series2 = new XYSeries("Something else"); series2.add(0.0, 5.0); series2.add(1.0, 4.0); series2.add(2.0, 1.0); series2.add(3.0, 5.0); series2.add(4.0, 0.0); final XYSeriesCollection dataset2 = new XYSeriesCollection(); dataset2.addSeries(series2); // create the chart final JFreeChart result = ChartFactory.createXYLineChart("Tick Label Demo", "Domain Axis 1", "Range Axis 1", dataset1, PlotOrientation.VERTICAL, false, true, false); result.setBackgroundPaint(Color.white); final XYPlot plot = result.getXYPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer(); renderer.setPaint(Color.black); // DOMAIN AXIS 2 final NumberAxis xAxis2 = new NumberAxis("Domain Axis 2"); xAxis2.setAutoRangeIncludesZero(false); plot.setDomainAxis(1, xAxis2); // RANGE AXIS 2 final DateAxis yAxis1 = new DateAxis("Range Axis 1"); plot.setRangeAxis(yAxis1); final DateAxis yAxis2 = new DateAxis("Range Axis 2"); plot.setRangeAxis(1, yAxis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); plot.setDataset(1, dataset2); plot.mapDatasetToDomainAxis(1, 1); plot.mapDatasetToRangeAxis(1, 1); return result; }
From source file:fr.ign.cogit.simplu3d.rjmcmc.generic.visitor.StatsVisitor.java
/** * Creates a sample chart./* ww w . j a va2 s . c o m*/ * * @param dataset * the dataset. * @return A sample chart. */ private JFreeChart createChart(final XYDataset dataset) { final JFreeChart result = ChartFactory.createXYLineChart("volution de l'nergie", "Itration", "nergie", dataset, PlotOrientation.VERTICAL, true, true, true); result.setBorderPaint(Color.white); result.setBackgroundPaint(Color.white); final XYPlot plot = result.getXYPlot(); Font font = new Font("Verdana", Font.PLAIN, 32); Font font2 = new Font("Verdana", Font.PLAIN, 28); // axe x ValueAxis axis = plot.getDomainAxis(); axis.setLabelFont(font); axis.setTickLabelFont(font2); axis.setAutoRange(true); // axis.setFixedAutoRange(60000.0); // 60 seconds axis = plot.getRangeAxis(); // axe y ValueAxis axis2 = plot.getRangeAxis(); axis2.setLabelFont(font); axis2.setTickLabelFont(font2); axis2.setAutoRange(true); // axis.setFixedAutoRange(60000.0); // 60 seconds axis2 = plot.getRangeAxis(); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setBackgroundPaint(Color.white); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, new Color(255, 0, 0)); renderer.setSeriesStroke(0, new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f)); renderer.setLegendTextFont(0, font2); renderer.setSeriesPaint(1, new Color(2, 157, 116)); renderer.setSeriesStroke(1, new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f)); renderer.setLegendTextFont(1, font2); renderer.setSeriesPaint(2, new Color(112, 147, 219)); renderer.setSeriesStroke(2, new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f)); renderer.setLegendTextFont(2, font2); renderer.setSeriesPaint(3, new Color(140, 23, 23)); renderer.setSeriesStroke(3, new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 6.0f, 6.0f }, 0.0f)); renderer.setLegendTextFont(3, font2); // axis.setRange(0.0, 200.0); return result; }
From source file:org.infoglue.deliver.util.charts.TimeSeriesDiagram.java
/** * Creates a chart./*from www. j a v a 2 s . c om*/ * * @param dataset a dataset. * * @return A chart. */ private JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart(header, axisXHeader, axisYHeader, dataset, true, true, false); chart.setBackgroundPaint(Color.white); LegendTitle legend = chart.getLegend(); //legend.set .setDisplaySeriesShapes(true); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(UnitType.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); XYItemRenderer renderer = plot.getRenderer(); if (renderer instanceof StandardXYItemRenderer) { StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer; //rr.setPlotShapes(true); rr.setShapesFilled(true); } DateAxis axis = (DateAxis) plot.getDomainAxis(); if (this.timeGranulariry.equalsIgnoreCase("Week")) { DateTickUnit unit = new DateTickUnit(DateTickUnit.DAY, 7, new SimpleDateFormat(this.dateFormat)); axis.setTickUnit(unit); axis.setTickMarkPosition(DateTickMarkPosition.START); axis.setDateFormatOverride(new SimpleDateFormat(this.dateFormat)); } else { axis.setDateFormatOverride(new SimpleDateFormat(this.dateFormat)); } /* DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat(this.dateFormat)); */ return chart; }
From source file:sturesy.votinganalysis.TimeChart.java
/** * Creates an XYSeries-ChartPanel/*from w ww .jav a2s . c o m*/ * * @param votes * votes to use * @return ChartPanel */ private ChartPanel getXYSeriesChart(Set<Vote> votes) { final XYSeries series = new XYSeries(Localize.getString("label.votes.over.time")); if (votes.size() != 0) { double[] dubble = createArrayOfVotes(votes); for (int i = 0; i < dubble.length; i++) { series.add(i, dubble[i]); } } final XYSeriesCollection data = new XYSeriesCollection(series); final JFreeChart chart = ChartFactory.createXYLineChart(Localize.getString("label.votes.over.time"), Localize.getString("label.time.seconds"), Localize.getString("label.amount.votes"), data, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(_background); chart.getPlot().setNoDataMessage("NO DATA"); chart.getXYPlot().getRenderer().setSeriesStroke(0, new BasicStroke(3.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f)); chart.getXYPlot().getRenderer().setSeriesPaint(0, new Color(255, 140, 0)); chart.getXYPlot().getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); chart.getXYPlot().getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); ChartPanel chartpanel = new ChartPanel(chart); return chartpanel; }
From source file:com.googlecode.psiprobe.controllers.RenderChartController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { final int SERIES_NUM = 9; // the max number of series ////from w ww.j a v a 2 s . co m // get Series Color from the request // int[] seriesColor = new int[SERIES_NUM]; seriesColor[0] = Utils.toIntHex(request.getParameter("s1c"), 0x9bd2fb); seriesColor[1] = Utils.toIntHex(request.getParameter("s2c"), 0xFF0606); for (int i = 2; i < SERIES_NUM; i++) { seriesColor[i] = Utils.toIntHex(request.getParameter("s" + (i + 1) + "c"), -1); } // // get Series Outline Color from the request // int[] seriesOutlineColor = new int[SERIES_NUM]; seriesOutlineColor[0] = Utils.toIntHex(request.getParameter("s1o"), 0x0665aa); seriesOutlineColor[1] = Utils.toIntHex(request.getParameter("s2o"), 0x9d0000); for (int i = 2; i < SERIES_NUM; i++) { seriesOutlineColor[i] = Utils.toIntHex(request.getParameter("s" + (i + 1) + "o"), -1); } // // background color // int backgroundColor = Utils.toIntHex(request.getParameter("bc"), 0xFFFFFF); // // grid color // int gridColor = Utils.toIntHex(request.getParameter("gc"), 0); // // X axis title // String xLabel = ServletRequestUtils.getStringParameter(request, "xl", ""); // // Y axis title // String yLabel = ServletRequestUtils.getStringParameter(request, "yl", ""); // // image width // int width = ServletRequestUtils.getIntParameter(request, "xz", 800); // // image height // int height = ServletRequestUtils.getIntParameter(request, "yz", 400); // // show legend? // boolean showLegend = ServletRequestUtils.getBooleanParameter(request, "l", true); // // Series provider // String provider = ServletRequestUtils.getStringParameter(request, "p", null); // // Chart type // String chartType = ServletRequestUtils.getStringParameter(request, "ct", "area"); DefaultTableXYDataset ds = new DefaultTableXYDataset(); if (provider != null) { Object o = getApplicationContext().getBean(provider); if (o instanceof SeriesProvider) { ((SeriesProvider) o).populate(ds, statsCollection, request); } else { logger.error("SeriesProvider \"" + provider + "\" does not implement " + SeriesProvider.class); } } // // Build series data from the give statistic // JFreeChart chart = null; if ("area".equals(chartType)) { chart = ChartFactory.createXYAreaChart("", xLabel, yLabel, ds, PlotOrientation.VERTICAL, showLegend, false, false); ((XYAreaRenderer) chart.getXYPlot().getRenderer()).setOutline(true); } else if ("stacked".equals(chartType)) { chart = ChartFactory.createStackedXYAreaChart("", xLabel, yLabel, ds, PlotOrientation.VERTICAL, showLegend, false, false); } else if ("line".equals(chartType)) { chart = ChartFactory.createXYLineChart("", xLabel, yLabel, ds, PlotOrientation.VERTICAL, showLegend, false, false); final XYLine3DRenderer renderer = new XYLine3DRenderer(); renderer.setDrawOutlines(true); renderer.setLinesVisible(true); renderer.setShapesVisible(true); renderer.setStroke(new BasicStroke(2)); renderer.setXOffset(1); renderer.setYOffset(1); chart.getXYPlot().setRenderer(renderer); } if (chart != null) { chart.setAntiAlias(true); chart.setBackgroundPaint(new Color(backgroundColor)); for (int i = 0; i < SERIES_NUM; i++) { if (seriesColor[i] >= 0) { chart.getXYPlot().getRenderer().setSeriesPaint(i, new Color(seriesColor[i])); } if (seriesOutlineColor[i] >= 0) { chart.getXYPlot().getRenderer().setSeriesOutlinePaint(i, new Color(seriesOutlineColor[i])); } } chart.getXYPlot().setDomainGridlinePaint(new Color(gridColor)); chart.getXYPlot().setRangeGridlinePaint(new Color(gridColor)); chart.getXYPlot().setDomainAxis(0, new DateAxis()); chart.getXYPlot().setDomainAxis(1, new DateAxis()); chart.getXYPlot().setInsets(new RectangleInsets(-15, 0, 0, 10)); response.setHeader("Content-type", "image/png"); response.getOutputStream().write(ChartUtilities.encodeAsPNG(chart.createBufferedImage(width, height))); } return null; }
From source file:com.romraider.logger.ecu.ui.tab.dyno.DynoChartPanel.java
private void configurePlot(JFreeChart chart) { plot = chart.getXYPlot(); plot.setOutlinePaint(DARK_GREY);/* w w w . j a v a 2s . co m*/ plot.setBackgroundPaint(BLACK); // X axis settings plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); plot.getDomainAxis().setLabelPaint(WHITE); plot.getDomainAxis().setTickLabelPaint(LIGHT_GREY); plot.setDomainGridlinePaint(DARK_GREY); // Y1 axis (left) settings hpAxis.setLabel(labelY1); hpAxis.setLabelPaint(BLUE); hpAxis.setTickLabelPaint(LIGHT_GREY); hpAxis.setAutoRangeIncludesZero(false); hpAxis.setAutoRange(true); plot.setRangeAxis(0, hpAxis); plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT); plot.mapDatasetToRangeAxis(0, 0); plot.mapDatasetToRangeAxis(2, 0); // Y2 axis (right) settings tqAxis.setLabel(labelY2); tqAxis.setLabelPaint(YELLOW); tqAxis.setTickLabelPaint(LIGHT_GREY); tqAxis.setAutoRangeIncludesZero(false); tqAxis.setAutoRange(true); plot.setRangeAxis(1, tqAxis); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); plot.mapDatasetToRangeAxis(1, 1); plot.mapDatasetToRangeAxis(3, 1); plot.setRangeGridlinePaint(DARK_GREY); refStat.setPaint(WHITE); refStat.setTextAnchor(TextAnchor.TOP_LEFT); refStat.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 12)); }