List of usage examples for org.jfree.chart.plot XYPlot getRenderer
public XYItemRenderer getRenderer()
From source file:de.mpg.mpi_inf.bioinf.netanalyzer.ui.charts.JFreeChartConn.java
/** * Updates the bar properties of a plot. * /*ww w. java2 s.co m*/ * @param aPlot * Plot to be updated. * @param aBars * Bar visual settings to be applied. */ private static void updateBars(XYPlot aPlot, BarsSettings aBars) { XYBarRenderer renderer = (XYBarRenderer) aPlot.getRenderer(); renderer.setSeriesPaint(0, aBars.getBarColor()); }
From source file:org.jfree.expdemo.SelectionDemo2.java
private static JFreeChart createChart(XYDataset dataset, DatasetSelectionExtension ext) { JFreeChart chart = ChartFactory.createScatterPlot("SelectionDemo2", "X", "Y", dataset, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setNoDataMessage("NO DATA"); plot.setDomainPannable(true);/*w w w . j ava 2s . c o m*/ plot.setRangePannable(true); plot.setDomainZeroBaselineVisible(true); plot.setRangeZeroBaselineVisible(true); plot.setDomainGridlineStroke(new BasicStroke(0.0f)); plot.setRangeGridlineStroke(new BasicStroke(0.0f)); plot.setDomainMinorGridlinesVisible(true); plot.setRangeMinorGridlinesVisible(true); XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer(); r.setSeriesFillPaint(0, r.lookupSeriesPaint(0)); r.setSeriesFillPaint(1, r.lookupSeriesPaint(1)); r.setSeriesFillPaint(2, r.lookupSeriesPaint(2)); r.setUseFillPaint(true); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRangeIncludesZero(false); domainAxis.setTickMarkInsideLength(2.0f); domainAxis.setTickMarkOutsideLength(2.0f); domainAxis.setMinorTickCount(2); domainAxis.setMinorTickMarksVisible(true); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setTickMarkInsideLength(2.0f); rangeAxis.setTickMarkOutsideLength(2.0f); rangeAxis.setMinorTickCount(2); rangeAxis.setMinorTickMarksVisible(true); //add selection specific rendering IRSUtilities.setSelectedItemFillPaint(r, ext, Color.white); //register plot as selection change listener ext.addSelectionChangeListener(plot); return chart; }
From source file:org.matsim.contrib.drt.analysis.DynModeTripsAnalyser.java
private static JFreeChart chartProfile(int length, TimeSeriesCollection dataset, String descriptor, String yax) {//from ww w. j av a2 s.co m JFreeChart chart = ChartFactory.createTimeSeriesChart(descriptor, "Time", yax, dataset); // ChartFactory.createXYLineChart("TimeProfile", "Time", "Wait Time // [s]", dataset, // PlotOrientation.VERTICAL, true, false, false); XYPlot plot = chart.getXYPlot(); plot.setRangeGridlinesVisible(false); plot.setDomainGridlinesVisible(false); plot.setBackgroundPaint(Color.white); NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setAutoRange(true); XYItemRenderer renderer = plot.getRenderer(); for (int s = 0; s < length; s++) { renderer.setSeriesStroke(s, new BasicStroke(2)); } return chart; }
From source file:org.talend.dataprofiler.chart.ChartDecorator.java
/** * DOC bZhou Comment method "decorateXYPlot". * /* ww w . ja va2 s.co m*/ * @param chart */ private static void decorateXYPlot(JFreeChart chart) { Font font = null; XYPlot plot = chart.getXYPlot(); XYItemRenderer render = plot.getRenderer(); ValueAxis domainAxis = plot.getDomainAxis(); ValueAxis valueAxis = plot.getRangeAxis(); font = new Font("Tahoma", Font.BOLD, BASE_ITEM_LABEL_SIZE);//$NON-NLS-1$ render.setBaseItemLabelFont(font); font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE);//$NON-NLS-1$ domainAxis.setLabelFont(font); font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE);//$NON-NLS-1$ valueAxis.setLabelFont(font); font = new Font("sans-serif", Font.PLAIN, BASE_TICK_LABEL_SIZE);//$NON-NLS-1$ domainAxis.setTickLabelFont(font); valueAxis.setTickLabelFont(font); setLegendFont(chart); font = new Font("sans-serif", Font.BOLD, BASE_TITLE_LABEL_SIZE);//$NON-NLS-1$ TextTitle title = chart.getTitle(); if (title != null) { title.setFont(font); } font = null; }
From source file:com.griddynamics.jagger.reporting.chart.ChartHelper.java
public static JFreeChart createXYChart(String title, XYDataset data, String xLabel, String yLabel, int pointRadius, int lineThickness, ColorTheme theme) { JFreeChart chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, data, PlotOrientation.VERTICAL, true, false, false);//from w w w. j a v a2s.c o m formatColorTheme(chart, theme); XYPlot plot = (XYPlot) chart.getPlot(); Shape icon = new Ellipse2D.Double(-pointRadius, -pointRadius, pointRadius * 2, pointRadius * 2); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); plot.setRenderer(renderer); Color[] colors = generateJetSpectrum(data.getSeriesCount()); for (int i = 0; i < data.getSeriesCount(); i++) { plot.getRenderer().setSeriesStroke(i, new BasicStroke(lineThickness)); plot.getRenderer().setSeriesShape(i, icon); ((XYLineAndShapeRenderer) plot.getRenderer()).setSeriesShapesVisible(i, true); ((XYLineAndShapeRenderer) plot.getRenderer()).setSeriesShapesFilled(i, true); plot.getRenderer().setSeriesPaint(i, colors[i]); } LegendTitle legend = chart.getLegend(); Font legendFont = legend.getItemFont(); float legendFontSize = legendFont.getSize(); Font newLegendFont = legendFont.deriveFont(legendFontSize * 0.6f); legend.setItemFont(newLegendFont); ValueAxis domainAxis = ((XYPlot) chart.getPlot()).getDomainAxis(); Font domainAxisLabelFont = domainAxis.getLabelFont(); float domainAxisLabelFontSize = domainAxisLabelFont.getSize(); domainAxis.setLabelFont(domainAxisLabelFont.deriveFont(domainAxisLabelFontSize * 0.6f)); Font domainAxisTickLabelFont = domainAxis.getTickLabelFont(); float domainAxisTickLabelFontSize = domainAxisTickLabelFont.getSize(); domainAxis.setTickLabelFont(domainAxisTickLabelFont.deriveFont(domainAxisTickLabelFontSize * 0.6f)); ValueAxis rangeAxis = ((XYPlot) chart.getPlot()).getRangeAxis(); Font rangeAxisLabelFont = rangeAxis.getLabelFont(); float rangeAxisLabelFontSize = rangeAxisLabelFont.getSize(); rangeAxis.setLabelFont(rangeAxisLabelFont.deriveFont(rangeAxisLabelFontSize * 0.6f)); Font rangeAxisTickLabelFont = rangeAxis.getTickLabelFont(); float rangeAxisTickLabelFontSize = rangeAxisTickLabelFont.getSize(); rangeAxis.setTickLabelFont(rangeAxisTickLabelFont.deriveFont(rangeAxisTickLabelFontSize * 0.6f)); return chart; }
From source file:PerformanceGraph.java
/** * Plots the performance graph of the best fitness value so far versus the * number of function calls (NFC)./*from w w w. j a va2 s . c o m*/ * * @param bestFitness A linked hashmap mapping the NFC to the best fitness value * found so far. * @param fitnessFunction The name of the fitness function, used for the title and the * name of the file that is saved, e.g. "De Jong". */ public static void plot(LinkedHashMap<Integer, Double> bestFitness, String fitnessFunction) { /* Create an XYSeries plot */ XYSeries series = new XYSeries("Best Fitness Value Vs. Number of Function Calls"); /* Add the NFC and best fitness value data to the series */ for (Integer NFC : bestFitness.keySet()) { /* Jfreechart crashes if double values are too large! */ if (bestFitness.get(NFC) <= 10E12) { series.add(NFC.doubleValue(), bestFitness.get(NFC).doubleValue()); } } /* Add the x,y series data to the dataset */ XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); /* Plot the data as an X,Y line chart */ JFreeChart chart = ChartFactory.createXYLineChart("Best Fitness Value Vs. Number of Function Calls", "Number of Function Calls (NFC)", "Best Fitness Value", dataset, PlotOrientation.VERTICAL, false, true, false); /* Configure the chart settings such as anti-aliasing, background colour */ chart.setAntiAlias(true); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); plot.setDomainGridlinePaint(Color.black); /* Set the domain range from 0 to NFC */ NumberAxis domain = (NumberAxis) plot.getDomainAxis(); domain.setRange(0.0, ControlVariables.MAX_FUNCTION_CALLS.doubleValue()); /* Logarithmic range axis */ plot.setRangeAxis(new LogAxis()); /* Set the thickness and colour of the lines */ XYItemRenderer renderer = plot.getRenderer(); BasicStroke thickLine = new BasicStroke(3.0f); renderer.setSeriesStroke(0, thickLine); renderer.setPaint(Color.BLACK); /* Display the plot in a JFrame */ ChartFrame frame = new ChartFrame(fitnessFunction + " Best Fitness Value", chart); frame.setVisible(true); frame.setSize(1000, 600); /* Save the plot as an image named after fitness function try { ChartUtilities.saveChartAsJPEG(new File("plots/" + fitnessFunction + ".jpg"), chart, 1600, 900); } catch (IOException e) { e.printStackTrace(); }*/ }
From source file:de.mpg.mpi_inf.bioinf.netanalyzer.ui.charts.JFreeChartConn.java
/** * Updates the point-related properties of a plot. * /* w w w. j ava 2 s .com*/ * @param aPlot * Plot to be updated. * @param aScatter * Visual settings to be applied. */ private static void updateScatter(XYPlot aPlot, ScatterSettings aScatter) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) aPlot.getRenderer(); renderer.setSeriesPaint(0, aScatter.getPointColor()); final Rectangle2D ds = AbstractRenderer.DEFAULT_SHAPE.getBounds2D(); final double x = ds.getX(); final double y = ds.getY(); final double w = ds.getWidth(); final double h = ds.getHeight(); Shape shape = null; switch (aScatter.getPointShape()) { case POINT: shape = new Rectangle2D.Double(x + w / 2, y + h / 2, 1, 1); renderer.setBaseShapesFilled(true); break; case CIRCLE: shape = new Ellipse2D.Double(x, y, w, h); renderer.setBaseShapesFilled(false); break; case FILLED_CIRCLE: shape = new Ellipse2D.Double(x, y, w, h); renderer.setBaseShapesFilled(true); break; case SQUARE: shape = new Rectangle2D.Double(x, y, w, h); renderer.setBaseShapesFilled(false); break; case FILLED_SQUARE: shape = new Rectangle2D.Double(x, y, w, h); renderer.setBaseShapesFilled(true); break; case CROSS: shape = new Cross(x, y, w, h); renderer.setBaseShapesFilled(false); } renderer.setSeriesShape(0, shape); }
From source file:org.jfree.chart.demo.PriceVolumeDemo1.java
private static JFreeChart createChart() { XYDataset xydataset = createPriceDataset(); String s = "Eurodollar Futures Contract (MAR03)"; JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(s, "Date", "Price", xydataset, true, true, false);//w w w . j a v a 2s . c o m XYPlot xyplot = (XYPlot) jfreechart.getPlot(); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setLowerMargin(0.40000000000000002D); DecimalFormat decimalformat = new DecimalFormat("00.00"); numberaxis.setNumberFormatOverride(decimalformat); XYItemRenderer xyitemrenderer = xyplot.getRenderer(); xyitemrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})", new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); NumberAxis numberaxis1 = new NumberAxis("Volume"); numberaxis1.setUpperMargin(1.0D); xyplot.setRangeAxis(1, numberaxis1); xyplot.setDataset(1, createVolumeDataset()); xyplot.setRangeAxis(1, numberaxis1); xyplot.mapDatasetToRangeAxis(1, 1); XYBarRenderer xybarrenderer = new XYBarRenderer(0.20000000000000001D); xybarrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})", new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0,000.00"))); xyplot.setRenderer(1, xybarrenderer); return jfreechart; }
From source file:org.gumtree.vis.awt.PlotFactory.java
public static JFreeChart createTimeChart(ITimeSeriesSet timeSeriesSet) { // TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(); JFreeChart chart = ChartFactory.createTimeSeriesChart(timeSeriesSet.getTitle(), null, timeSeriesSet.getYTitle()/*from w ww .j a v a 2 s. co m*/ + (timeSeriesSet.getYUnits() != null ? " (" + timeSeriesSet.getYUnits() + ")" : ""), timeSeriesSet, true, true, false); XYPlot xyplot = chart.getXYPlot(); ValueAxis valueaxis = xyplot.getDomainAxis(); valueaxis.setAutoRange(true); // valueaxis.setFixedAutoRange(60000D); valueaxis = xyplot.getRangeAxis(); valueaxis.setRange(0.0D, 200D); valueaxis.setAutoRange(true); XYItemRenderer renderer = xyplot.getRenderer(); if (renderer instanceof XYLineAndShapeRenderer) { ((XYLineAndShapeRenderer) renderer).setBaseShapesVisible(false); } chartTheme.apply(chart); Font font = valueaxis.getLabelFont(); valueaxis.setLabelFont(font.deriveFont(Font.PLAIN)); return chart; }
From source file:DataCharts.LineGraph.java
public static JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart("Customers by Month", "Months", "Customers", dataset); String fontName = "SansSerif"; chart.getTitle().setFont(new Font(fontName, Font.BOLD, 18)); chart.addSubtitle(new TextTitle(" ", new Font(fontName, Font.PLAIN, 14))); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainPannable(false);//from w w w . j a v a2 s. c om plot.setRangePannable(false); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); plot.getDomainAxis().setLowerMargin(0.0); plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14)); plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12)); plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14)); plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12)); chart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14)); chart.getLegend().setFrame(BlockBorder.NONE); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setDrawSeriesLineAsPath(false); // set the default stroke for all series renderer.setAutoPopulateSeriesStroke(false); } return chart; }