List of usage examples for org.jfree.chart.axis DateAxis setLowerMargin
public void setLowerMargin(double margin)
From source file:org.projectforge.statistics.TimesheetDisciplineChartBuilder.java
private JFreeChart create(final TimeSeries series1, final TimeSeries series2, final Shape shape, final Stroke stroke, final boolean showAxisValues, final String valueAxisUnitKey) { final TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series1);// w w w . j a v a 2 s . c o m dataset.addSeries(series2); final JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, dataset, PlotOrientation.VERTICAL, true, true, false); final XYDifferenceRenderer renderer = new XYDifferenceRenderer(new Color(238, 176, 176), new Color(135, 206, 112), true); renderer.setSeriesPaint(0, new Color(222, 23, 33)); renderer.setSeriesPaint(1, new Color(64, 169, 59)); if (shape != null) { renderer.setSeriesShape(0, shape); renderer.setSeriesShape(1, shape); } else { final Shape none = new Rectangle(); renderer.setSeriesShape(0, none); renderer.setSeriesShape(1, none); } renderer.setSeriesStroke(0, stroke); renderer.setSeriesStroke(1, stroke); renderer.setSeriesVisibleInLegend(0, false); renderer.setSeriesVisibleInLegend(1, false); final XYPlot plot = chart.getXYPlot(); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); final DateAxis xAxis = new DateAxis(); xAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); xAxis.setLowerMargin(0.0); xAxis.setUpperMargin(0.0); xAxis.setVisible(showAxisValues); plot.setDomainAxis(xAxis); final NumberAxis yAxis; if (showAxisValues == true) { yAxis = new NumberAxis(PFUserContext.getLocalizedString(valueAxisUnitKey)); } else { yAxis = new NumberAxis(); } yAxis.setVisible(showAxisValues); plot.setRangeAxis(yAxis); plot.setOutlineVisible(false); return chart; }
From source file:de.uniol.ui.tsv.ui.LineChartDialog.java
/** * @return the resulting chart object//from w w w . ja va2 s . co m */ protected JFreeChart createChart() { JFreeChart chart = ChartFactory.createTimeSeriesChartFast(title, xTitle, yTitle, xy, true, false, false); chart.setBackgroundPaint(Color.white); chart.getLegend().setBackgroundPaint(new Color(224, 224, 224)); FastXYPlot plot = (FastXYPlot) chart.getPlot(); // plot.setBackgroundPaint(new Color(224, 224, 224)); plot.setBackgroundPaint(new Color(77, 77, 77)); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); StandardXYItemRendererFast r = new StandardXYItemRendererFast(StandardXYItemRendererFast.LINES, null, null); plot.setRenderer(r); for (int i : seriesStrokes.keySet()) { r.setSeriesStroke(i, seriesStrokes.get(i)); } for (int i : seriesColors.keySet()) { r.setSeriesPaint(i, seriesColors.get(i)); } DateAxis da = new DateAxis(xTitle); if (useRelativeHourFormat) { da.setDateFormatOverride(new RelativeHourFormat()); } da.setLowerMargin(0.03); plot.setDomainAxis(da); if (minRange != 0.0 && maxRange != 0.0) { ValueAxis yaxis = plot.getRangeAxis(); yaxis.setRange(new Range(minRange, maxRange)); } return chart; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.blockcharts.TimeBlockChart.java
@Override public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); super.createChart(datasets); DefaultXYZDataset dataset = (DefaultXYZDataset) datasets.getDatasets().get("1"); DateAxis xAxis = new DateAxis(yLabel); xAxis.setLowerMargin(0.0); xAxis.setUpperMargin(0.0);/*from w w w . j a v a2 s .c o m*/ xAxis.setInverted(false); xAxis.setDateFormatOverride(new SimpleDateFormat("dd/MM/yyyy")); if (dateAutoRange) { xAxis.setAutoRange(true); } else { DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); DateTickUnit unit = new DateTickUnit(DateTickUnit.DAY, 1, formatter); xAxis.setTickUnit(unit); } if (dateMin != null && dateMax != null) { xAxis.setRange(dateMin, addDay(dateMax)); } else { xAxis.setRange(minDateFound, addDay(maxDateFound)); } // Calendar c=new GregorianCalendar(); // c.set(9 + 2000, Calendar.JANUARY, 1); // java.util.Date minima=c.getTime(); // Calendar c1=new GregorianCalendar(); // c1.set(9 + 2000, Calendar.FEBRUARY, 1); // java.util.Date massima=c1.getTime(); NumberAxis yAxis = new NumberAxis(xLabel); yAxis.setUpperMargin(0.0); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); yAxis.setRange(hourMin, hourMax); XYBlockRenderer renderer = new XYBlockRenderer(); renderer.setBlockWidth(BLOCK_HEIGHT); // one block for each minute! renderer.setBlockHeight(0.017); //renderer.setBlockWidth(1); renderer.setBlockAnchor(RectangleAnchor.BOTTOM_LEFT); // MyXYItemLabelGenerator my=new MyXYItemLabelGenerator(); // renderer.setItemLabelsVisible(null); // renderer.setSeriesItemLabelGenerator(0, my); // renderer.setSeriesItemLabelsVisible(0, true); // XYTextAnnotation annotation1 = new XYTextAnnotation( // "P_",1.2309372E12, 14.3); // XYTextAnnotation annotation2 = new XYTextAnnotation( // "P_",1.2308508E12, 16.3); for (Iterator iterator = annotations.keySet().iterator(); iterator.hasNext();) { String annotationCode = (String) iterator.next(); AnnotationBlock annotationBlock = annotations.get(annotationCode); XYTextAnnotation xyAnnotation = new XYTextAnnotation(annotationBlock.getAnnotation(), annotationBlock.getXPosition() + ANNOTATION_HEIGHT, annotationBlock.getYPosition()); if (styleAnnotation != null) { xyAnnotation.setFont(new Font(styleAnnotation.getFontName(), Font.BOLD, styleAnnotation.getSize())); xyAnnotation.setPaint(styleAnnotation.getColor()); } else { xyAnnotation.setFont(new Font("Nome", Font.BOLD, 8)); xyAnnotation.setPaint(Color.BLACK); } xyAnnotation.setTextAnchor(TextAnchor.BOTTOM_LEFT); renderer.addAnnotation(xyAnnotation); } logger.debug("Annotation set"); LookupPaintScale paintScale = new LookupPaintScale(0.5, ranges.size() + 0.5, color); String[] labels = new String[ranges.size() + 1]; labels[0] = ""; // ******************** SCALE **************************** for (Iterator iterator = ranges.iterator(); iterator.hasNext();) { RangeBlocks range = (RangeBlocks) iterator.next(); Integer index = patternRangeIndex.get(range.getPattern()); Color color = range.getColor(); if (color != null) { //Paint colorTransparent=new Color(color.getRed(), color.getGreen(), color.getBlue(), 50); Paint colorTransparent = null; if (addTransparency == true) { colorTransparent = new Color(color.getRed(), color.getGreen(), color.getBlue(), 50); } else { colorTransparent = new Color(color.getRed(), color.getGreen(), color.getBlue()); } paintScale.add(index + 0.5, colorTransparent); } //String insertLabel=" "+range.getLabel(); String insertLabel = range.getLabel(); labels[index + 1] = insertLabel; } renderer.setPaintScale(paintScale); SymbolAxis scaleAxis = new SymbolAxis(null, labels); scaleAxis.setRange(0.5, ranges.size() + 0.5); scaleAxis.setPlot(new PiePlot()); scaleAxis.setGridBandsVisible(false); org.jfree.chart.title.PaintScaleLegend psl = new PaintScaleLegend(paintScale, scaleAxis); psl.setMargin(new RectangleInsets(3, 10, 3, 10)); psl.setPosition(RectangleEdge.BOTTOM); psl.setAxisOffset(5.0); // ******************** END SCALE **************************** logger.debug("Scale Painted"); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.HORIZONTAL); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5)); logger.debug("Plot set"); JFreeChart chart = new JFreeChart(name, plot); if (styleTitle != null) { TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); } chart.removeLegend(); chart.setBackgroundPaint(Color.white); chart.addSubtitle(psl); logger.debug("OUT"); return chart; }
From source file:net.sourceforge.processdash.ui.web.psp.TimeLogPhaseWaterfallChart.java
private JFreeChart createChart(IntervalXYDataset dataset, ProcessUtil process, List<String> phases, GapSkipTracker gaps) {//from w w w . j a va2 s . c o m JFreeChart result = ChartFactory.createXYBarChart(null, null, true, null, dataset, PlotOrientation.VERTICAL, false, true, false); XYPlot xyplot = (XYPlot) result.getPlot(); DateAxis dateAxis = new DateAxis(null); dateAxis.setTickMarksVisible(false); dateAxis.setTickLabelsVisible(false); dateAxis.setLowerMargin(0.01); dateAxis.setUpperMargin(0.01); setupGaps(gaps, dateAxis, xyplot); xyplot.setDomainAxis(dateAxis); String[] phaseNameList = new String[phases.size()]; for (int i = 0; i < phaseNameList.length; i++) phaseNameList[i] = Translator.translate(phases.get(i)); SymbolAxis symbolaxis = new SymbolAxis(null, phaseNameList); symbolaxis.setGridBandsVisible(false); xyplot.setRangeAxis(symbolaxis); final XYBarRenderer renderer = (XYBarRenderer) xyplot.getRenderer(); renderer.setUseYInterval(true); renderer.setDrawBarOutline(true); renderer.setBaseOutlinePaint(Color.black); new PhaseChartColorer(process, phases) { public void setItemColor(Object key, int pos, Color c) { renderer.setSeriesPaint(pos, c); } }.run(); int exceptionSeries = dataset.getSeriesCount() - 1; renderer.setSeriesPaint(exceptionSeries, EXCEPTION_PAINT); renderer.setSeriesFillPaint(exceptionSeries, EXCEPTION_PAINT); renderer.setSeriesOutlinePaint(exceptionSeries, EXCEPTION_PAINT); renderer.setBaseToolTipGenerator(new TooltipGenerator()); xyplot.setBackgroundPaint(Color.white); xyplot.setDomainGridlinesVisible(false); xyplot.setRangeGridlinePaint(Color.lightGray); xyplot.setDrawingSupplier(DRAWING_SUPPLIER_FACTORY.newDrawingSupplier()); result.setAntiAlias(false); result.setTextAntiAlias(true); parameters.put("title", resources.getString("Title")); return result; }
From source file:com.o4s.sarGrapher.graph.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request//from w w w . j av a 2 s . c om * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { TimeSeriesCollection dataset = new TimeSeriesCollection(); String title = ""; String ytitle = ""; int width = 400; int height = 300; String graphType = "LINE"; Boolean useSSH = false; HttpSession session = request.getSession(); if (session != null && session.getAttribute("jsch") != null) { useSSH = true; } for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) { String name = e.nextElement().toString(); String val = request.getParameter(name); if (val == null) continue; // seems unnecessary but for code clarity else if (name.equals("title")) title = val; else if (name.equals("ytitle")) ytitle = val; else if (name.equals("width")) width = Integer.parseInt(val); else if (name.equals("height")) height = Integer.parseInt(val); else if (name.equals("useSSH")) useSSH = true; else if (name.equals("type")) graphType = val; else { String[] fflds = val.split(":"); String fn = fflds[0]; String[] flds = fflds[1].split(","); if (fn == null) { Logger.getLogger(graph.class.getName()).log(Level.SEVERE, "Unable to find filename from: {0}={1}", new Object[] { name, val }); return; } CSV c = null; if (useSSH) { CSVs cs = new CSVs(); c = cs.get(fn); } if (c == null) { Logger.getLogger(graph.class.getName()).log(Level.SEVERE, "Unable to find CSV: {0}", fn); return; } ArrayList ds = new ArrayList(); for (int i = 0; i < flds.length; i++) ds.add(new TimeSeries(name + "." + flds[i])); try { c.open(); do { try { if (!c.next()) break; } catch (Exception ex) { // Missing field if (ex.getMessage().startsWith("Missing fields")) break; Logger.getLogger(graph.class.getName()).log(Level.SEVERE, null, ex); } String heure = (String) c.get("heure"); for (int i = 0; i < flds.length; i++) { Double fv; val = (String) c.get(flds[i]); if (val != null) { fv = Double.parseDouble(val); } else { // try to replace variable String str = flds[i]; for (String s : c.getFields()) { str = str.replaceAll(s, c.get(s).toString()); } Expression exp = new ExpressionBuilder(str).build(); ValidationResult v = exp.validate(); String errorMsg = ""; if (!v.isValid()) { for (String s : v.getErrors()) { errorMsg += (errorMsg.isEmpty() ? "" : ",") + s; } if (!errorMsg.isEmpty()) { Logger.getLogger(graph.class.getName()).log(Level.SEVERE, "Syntax ERROR or missing variables: {0}", errorMsg); } } fv = exp.evaluate(); } //dataset.addValue(fv,flds[i],heure); Date dt = new SimpleDateFormat("HH:mm:ss").parse(heure); ((TimeSeries) ds.get(i)).addOrUpdate(new Minute(dt), fv); } } while (true); } catch (Exception ex) { Logger.getLogger(graph.class.getName()).log(Level.SEVERE, null, ex); } for (int i = 0; i < flds.length; i++) dataset.addSeries((TimeSeries) ds.get(i)); } } //JFreeChart barChart = ChartFactory.createBarChart(title, "", "Unit vendue", dataset, PlotOrientation.VERTICAL, true, true, false); //JFreeChart barChart = ChartFactory.createTimeSeriesChart(title, title, dataDir, dataset);// .createStackedBarChart(title, "", "", dataset); // JFreeChart timechart = ChartFactory.createTimeSeriesChart( // title, // Title // "Heure", // X-axis Label // "", // Y-axis Label // dataset, // Dataset // true, // Show legend // true, // Use tooltips // false // Generate URLs // ); // Plot p=timechart.getPlot(); XYItemRenderer r; if (graphType.equals("AREA")) { r = new XYAreaRenderer(); } else if (graphType.equals("BAR")) { r = new XYBarRenderer(); } else if (graphType.equals("STACK")) { r = new StackedXYAreaRenderer(); } else { r = new StandardXYItemRenderer(); } final DateAxis domainAxis = new DateAxis("Heure"); domainAxis.setVerticalTickLabels(false); domainAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm")); domainAxis.setLowerMargin(0.01); domainAxis.setUpperMargin(0.01); final ValueAxis rangeAxis = new NumberAxis(ytitle); final XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, r); final JFreeChart chart = new JFreeChart(title, plot); // JFreeChart timechart=null; // if( graphType.equals("AREA") ){ // timechart = ChartFactory.createXYAreaChart(title, "Heure", "", dataset, PlotOrientation.VERTICAL, true, true, false); // } else if( graphType.equals("BAR") ){ // timechart = ChartFactory.createXYBarChart(title, "Heure", true, "", dataset, PlotOrientation.VERTICAL, true, true, false); // } else { // timechart = ChartFactory.createXYLineChart(title, "Heure", "", dataset, PlotOrientation.VERTICAL, true, true, false); // } response.setContentType("image/png"); OutputStream out = response.getOutputStream(); ChartUtilities.writeChartAsPNG(out, chart, width, height); }
From source file:org.jivesoftware.openfire.reporting.graph.GraphEngine.java
/** * Generates a simple Time Axis./*from w w w . j a va 2 s .com*/ * * @return the generated Time Axis. */ private DateAxis generateTimeAxis() { DateAxis xAxis = new DateAxis(""); xAxis.setLowerMargin(0.05); xAxis.setUpperMargin(0.02); xAxis.setLabel(null); xAxis.setTickLabelsVisible(true); xAxis.setTickMarksVisible(true); xAxis.setAxisLineVisible(true); xAxis.setNegativeArrowVisible(false); xAxis.setPositiveArrowVisible(false); xAxis.setVisible(true); xAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); Locale locale = JiveGlobals.getLocale(); // If the tick units have not yet been setup or the locale has changed if (tickUnits == null || !locale.equals(oldLocale)) { tickUnits = createTickUnits(locale, JiveGlobals.getTimeZone()); oldLocale = locale; } xAxis.setStandardTickUnits(tickUnits); return xAxis; }
From source file:diet.gridr.g5k.gui.GanttChart.java
/** * Method creating the chart/*ww w . ja v a 2 s. c o m*/ * * @param dataset dataset containing the data for the chart * @return a chart */ private JFreeChart createChart(XYZDataset dataset) { DateAxis xAxis = new DateAxis("Date"); xAxis.setLowerMargin(0.0); xAxis.setUpperMargin(0.0); xAxis.setDateFormatOverride(new SimpleDateFormat(durationsFormatterArray[this.visualizationDuration])); xAxis.setRange(Calendar.getInstance().getTime(), new Date(System.currentTimeMillis() + HistoryUtil.durationsTimesArray[visualizationDuration] - HistoryUtil.blockWidthsArray[visualizationDuration])); NumberAxis yAxis = new NumberAxis("Nodes"); yAxis.setAutoRangeIncludesZero(false); yAxis.setInverted(true); yAxis.setLowerMargin(0.0); yAxis.setUpperMargin(0.0); yAxis.setRange(1, numberOfNodes); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYBlockRenderer renderer = new XYBlockRenderer(); LookupPaintScale paintScale = new LookupPaintScale(); for (int i = 0; i < jobsList.get(visualizationDuration).size(); i++) { // String jobId = jobsList.get(visualizationDuration).get(i).getId().substring(0,jobsList.get(visualizationDuration).get(i).getId().indexOf(".")); String jobId = jobsList.get(visualizationDuration).get(i).getParameterValue(GridJob.KEY_GRID_JOB_ID); int seed = Integer.parseInt(jobId); Random rng = new Random(seed); Color tempColor = Color.red; int red = tempColor.getRed(); int green = tempColor.getGreen(); int blue = tempColor.getBlue(); int redRNG = rng.nextInt(255); int greenRNG = rng.nextInt(255); int blueRNG = rng.nextInt(255); if (red == redRNG && green == greenRNG && blue == blueRNG) { tempColor = new Color(rng.nextInt(255), rng.nextInt(255), rng.nextInt(255)); } else { tempColor = new Color(redRNG, greenRNG, blueRNG); } if (seed == 0) tempColor = Color.red; paintScale.add(new Double(i), tempColor); } renderer.setBlockWidth(HistoryUtil.blockWidthsArray[visualizationDuration]); renderer.setBlockAnchor(RectangleAnchor.TOP_LEFT); renderer.setPaintScale(paintScale); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.black); plot.setRangeGridlinePaint(Color.black); JFreeChart chart = new JFreeChart("Gantt Chart activity for cluster " + siteName, plot); chart.removeLegend(); chart.setBackgroundPaint(Color.white); LoggingManager.log(Level.CONFIG, LoggingManager.RESOURCESTOOL, this.getClass().getName(), "createChart", "Chart created"); return chart; }
From source file:org.jfree.chart.demo.DifferenceChartDemo2.java
/** * Creates a chart.// www.j av a 2 s. c om * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final XYDataset dataset) { final JFreeChart chart = ChartFactory.createTimeSeriesChart("Daylight Hours - London, UK", "Date", "Time", dataset, true, // legend true, // tool tips false // URLs ); chart.setBackgroundPaint(Color.white); final XYDifferenceRenderer renderer = new XYDifferenceRenderer(Color.blue, Color.blue, false); renderer.setStroke(new BasicStroke(2.0f)); renderer.setSeriesPaint(0, Color.yellow); renderer.setSeriesPaint(1, Color.red); final XYPlot plot = chart.getXYPlot(); plot.setRenderer(renderer); 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 DateAxis domainAxis = new DateAxis("Time"); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); plot.setDomainAxis(domainAxis); plot.setForegroundAlpha(0.5f); final Color c = new Color(255, 60, 24, 63); final Marker bst = new IntervalMarker(new Day(28, 3, 2004).getFirstMillisecond(), new Day(30, 10, 2004).getFirstMillisecond(), c, new BasicStroke(2.0f), null, null, 1.0f); bst.setLabel("British Summer Time"); bst.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); bst.setLabelFont(new Font("SansSerif", Font.ITALIC + Font.BOLD, 10)); bst.setLabelTextAnchor(TextAnchor.BASELINE_RIGHT); plot.addDomainMarker(bst, Layer.BACKGROUND); final DateAxis rangeAxis = new DateAxis("Time"); rangeAxis.setLowerMargin(0.15); rangeAxis.setUpperMargin(0.15); plot.setRangeAxis(rangeAxis); return chart; }
From source file:unusedClasses.MemoryUsageDemo.java
public MemoryUsageDemo(int paramInt) { super(new BorderLayout()); this.total.setMaximumItemAge(paramInt); this.free = new TimeSeries("Free Memory"); this.free.setMaximumItemAge(paramInt); TimeSeriesCollection localTimeSeriesCollection = new TimeSeriesCollection(); localTimeSeriesCollection.addSeries(this.total); localTimeSeriesCollection.addSeries(this.free); DateAxis localDateAxis = new DateAxis("Time"); NumberAxis localNumberAxis = new NumberAxis("Memory"); localDateAxis.setTickLabelFont(new Font("SansSerif", 0, 12)); localNumberAxis.setTickLabelFont(new Font("SansSerif", 0, 12)); localDateAxis.setLabelFont(new Font("SansSerif", 0, 14)); localNumberAxis.setLabelFont(new Font("SansSerif", 0, 14)); XYLineAndShapeRenderer localXYLineAndShapeRenderer = new XYLineAndShapeRenderer(true, false); localXYLineAndShapeRenderer.setSeriesPaint(0, Color.red); localXYLineAndShapeRenderer.setSeriesPaint(1, Color.green); localXYLineAndShapeRenderer.setSeriesStroke(0, new BasicStroke(3.0F, 0, 2)); localXYLineAndShapeRenderer.setSeriesStroke(1, new BasicStroke(3.0F, 0, 2)); XYPlot localXYPlot = new XYPlot(localTimeSeriesCollection, localDateAxis, localNumberAxis, localXYLineAndShapeRenderer); localDateAxis.setAutoRange(true);/*from w w w .j a v a2s. c o m*/ localDateAxis.setLowerMargin(0.0D); localDateAxis.setUpperMargin(0.0D); localDateAxis.setTickLabelsVisible(true); localNumberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); JFreeChart localJFreeChart = new JFreeChart("JVM Memory Usage", new Font("SansSerif", 1, 24), localXYPlot, true); ChartUtilities.applyCurrentTheme(localJFreeChart); ChartPanel localChartPanel = new ChartPanel(localJFreeChart, true); localChartPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createLineBorder(Color.black))); add(localChartPanel); }
From source file:org.jfree.chart.demo.MemoryUsageDemo.java
public MemoryUsageDemo(int i) { super(new BorderLayout()); total = new TimeSeries("Total Memory"); total.setMaximumItemAge(i);/*from w w w. j a va 2 s .c o m*/ free = new TimeSeries("Free Memory"); free.setMaximumItemAge(i); TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(); timeseriescollection.addSeries(total); timeseriescollection.addSeries(free); DateAxis dateaxis = new DateAxis("Time"); NumberAxis numberaxis = new NumberAxis("Memory"); dateaxis.setTickLabelFont(new Font("SansSerif", 0, 12)); numberaxis.setTickLabelFont(new Font("SansSerif", 0, 12)); dateaxis.setLabelFont(new Font("SansSerif", 0, 14)); numberaxis.setLabelFont(new Font("SansSerif", 0, 14)); XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(true, false); xylineandshaperenderer.setSeriesPaint(0, Color.red); xylineandshaperenderer.setSeriesPaint(1, Color.green); xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(3F, 0, 2)); xylineandshaperenderer.setSeriesStroke(1, new BasicStroke(3F, 0, 2)); XYPlot xyplot = new XYPlot(timeseriescollection, dateaxis, numberaxis, xylineandshaperenderer); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); dateaxis.setAutoRange(true); dateaxis.setLowerMargin(0.0D); dateaxis.setUpperMargin(0.0D); dateaxis.setTickLabelsVisible(true); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); JFreeChart jfreechart = new JFreeChart("JVM Memory Usage", new Font("SansSerif", 1, 24), xyplot, true); jfreechart.setBackgroundPaint(Color.white); ChartPanel chartpanel = new ChartPanel(jfreechart, true); chartpanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createLineBorder(Color.black))); add(chartpanel); }