List of usage examples for org.jfree.chart.plot XYPlot setRangeGridlinePaint
public void setRangeGridlinePaint(Paint paint)
From source file:com.itemanalysis.jmetrik.graph.scatterplot.ScatterplotPanel.java
public void setGraph() { DefaultXYDataset dataset = new DefaultXYDataset(); PlotOrientation orientation = PlotOrientation.VERTICAL; try {/*from w w w . jav a 2s . co m*/ chart = ChartFactory.createScatterPlot(title, // chart title xlabel, // x axis label ylabel, // y axis label dataset, // data orientation, showLegend, // include legend true, // tooltips false // urls ); if (subtitle != null && !"".equals(subtitle)) { TextTitle subtitle1 = new TextTitle(subtitle); chart.addSubtitle(subtitle1); } XYPlot plot = (XYPlot) chart.getPlot(); plot.setNoDataMessage("NO DATA"); plot.setDomainZeroBaselineVisible(false); plot.setRangeZeroBaselineVisible(false); plot.setBackgroundPaint(Color.WHITE); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); ChartPanel panel = new ChartPanel(chart); panel.getPopupMenu().addSeparator(); this.addJpgMenuItem(this, panel.getPopupMenu()); panel.setPreferredSize(new Dimension(width, height)); chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0)); this.setBackground(Color.WHITE); this.add(panel); } catch (IllegalArgumentException ex) { logger.fatal(ex.getMessage(), ex); this.firePropertyChange("error", "", "Error - Check log for details."); } }
From source file:edu.ucsf.valelab.saim.plot.PlotUtils.java
/** * Create a frame with a plot of the data given in XYSeries overwrite any * previously created frame with the same title * // w w w. ja v a 2 s .c o m * @param title shown in the top of the plot * @param data array with data series to be plotted * @param xTitle Title of the X axis * @param yTitle Title of the Y axis * @param showShapes whether or not to draw shapes at the data points * @param annotation to be shown in plot * @return Frame that displays the data */ public Frame plotDataN(String title, XYSeries[] data, String xTitle, String yTitle, boolean[] showShapes, String annotation) { // Close existing frames // Frame[] gfs = ChartFrame.getFrames(); // for (Frame f : gfs) { //if (f.getTitle().equals(title)) { // f.dispose(); //} // } // JFreeChart code XYSeriesCollection dataset = new XYSeriesCollection(); // calculate min and max to scale the graph double minX, minY, maxX, maxY; minX = data[0].getMinX(); minY = data[0].getMinY(); maxX = data[0].getMaxX(); maxY = data[0].getMaxY(); for (XYSeries d : data) { dataset.addSeries(d); if (d.getMinX() < minX) { minX = d.getMinX(); } if (d.getMaxX() > maxX) { maxX = d.getMaxX(); } if (d.getMinY() < minY) { minY = d.getMinY(); } if (d.getMaxY() > maxY) { maxY = d.getMaxY(); } } JFreeChart chart = ChartFactory.createScatterPlot(title, // Title xTitle, // x-axis Label yTitle, // y-axis Label dataset, // Dataset PlotOrientation.VERTICAL, // Plot Orientation true, // Show Legend true, // Use tooltips false // Configure chart to generate URLs? ); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); for (int i = 0; i < data.length; i++) { renderer.setSeriesFillPaint(i, Color.white); renderer.setSeriesLinesVisible(i, true); } renderer.setSeriesPaint(0, Color.blue); Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 4.0f, 4.0f); renderer.setSeriesShape(0, circle, false); if (data.length > 1) { renderer.setSeriesPaint(1, Color.red); Shape square = new Rectangle2D.Float(-2.0f, -2.0f, 4.0f, 4.0f); renderer.setSeriesShape(1, square, false); } if (data.length > 2) { renderer.setSeriesPaint(2, Color.darkGray); Shape rect = new Rectangle2D.Float(-2.0f, -1.0f, 4.0f, 2.0f); renderer.setSeriesShape(2, rect, false); } if (data.length > 3) { renderer.setSeriesPaint(3, Color.magenta); Shape rect = new Rectangle2D.Float(-1.0f, -2.0f, 2.0f, 4.0f); renderer.setSeriesShape(3, rect, false); } for (int i = 0; i < data.length; i++) { if (showShapes.length > i && !showShapes[i]) { renderer.setSeriesShapesVisible(i, false); } } // place annotation at 80 % of max X, maxY XYAnnotation an = new XYTextAnnotation(annotation, maxX - 0.2 * (maxX - minX), maxY); plot.addAnnotation(an); renderer.setUseFillPaint(true); final MyChartFrame graphFrame = new MyChartFrame(title, chart); graphFrame.getChartPanel().setMouseWheelEnabled(true); graphFrame.pack(); graphFrame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent arg0) { graphFrame.dispose(); } }); graphFrame.setVisible(true); return graphFrame; }
From source file:net.pickapack.chart.LinePlotFrame.java
/** * Create a line plot frame.//from w w w . j av a 2s . co m * * @param linePlot the line plot * @param width the width * @param height the height */ public LinePlotFrame(LinePlot linePlot, int width, int height) { super(linePlot.getTitle()); this.linePlot = linePlot; this.numSubPlots = linePlot.getSubLinePlots().size(); CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time")); this.dataSets = new ArrayList<TimeSeriesCollection>(); this.dataSinks = new ArrayList<Map<SubLinePlotLine, Function<Double>>>(); for (SubLinePlot subLinePlot : linePlot.getSubLinePlots()) { TimeSeriesCollection dataSetsPerSubPlot = new TimeSeriesCollection(); this.dataSets.add(dataSetsPerSubPlot); HashMap<SubLinePlotLine, Function<Double>> dataSinksPerSubPlot = new HashMap<SubLinePlotLine, Function<Double>>(); this.dataSinks.add(dataSinksPerSubPlot); for (SubLinePlotLine subLinePlotLine : subLinePlot.getLines()) { TimeSeries timeSeries = new TimeSeries(subLinePlotLine.getTitle()); dataSetsPerSubPlot.addSeries(timeSeries); dataSinksPerSubPlot.put(subLinePlotLine, subLinePlotLine.getGetValueCallback()); } NumberAxis rangeAxis = new NumberAxis(subLinePlot.getTitleY()); rangeAxis.setAutoRangeIncludesZero(false); XYPlot subplot = new XYPlot(dataSetsPerSubPlot, null, rangeAxis, new StandardXYItemRenderer()); subplot.setBackgroundPaint(Color.lightGray); subplot.setDomainGridlinePaint(Color.white); subplot.setRangeGridlinePaint(Color.white); plot.add(subplot); } JFreeChart chart = new JFreeChart(linePlot.getTitle(), plot); chart.setBorderPaint(Color.black); chart.setBorderVisible(true); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis.setFixedAutoRange(3600000.0); JPanel content = new JPanel(new BorderLayout()); ChartPanel chartPanel = new ChartPanel(chart); content.add(chartPanel); chartPanel.setPreferredSize(new java.awt.Dimension(width, height)); chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); setContentPane(content); DataSink dataSink = new DataSink(); new Thread(dataSink).start(); }
From source file:org.micromanager.saim.plot.PlotUtils.java
/** * Create a frame with a plot of the data given in XYSeries overwrite any * previously created frame with the same title * /*from w w w . j av a 2 s. c om*/ * @param title shown in the top of the plot * @param data array with data series to be plotted * @param xTitle Title of the X axis * @param yTitle Title of the Y axis * @param showShapes whether or not to draw shapes at the data points * @param annotation to be shown in plot * @return Frame that displays the data */ public Frame plotDataN(String title, XYSeries[] data, String xTitle, String yTitle, boolean[] showShapes, String annotation) { //Close existing frames Frame[] gfs = ChartFrame.getFrames(); for (Frame f : gfs) { if (f.getTitle().equals(title)) { f.dispose(); } } // JFreeChart code XYSeriesCollection dataset = new XYSeriesCollection(); // calculate min and max to scale the graph double minX, minY, maxX, maxY; minX = data[0].getMinX(); minY = data[0].getMinY(); maxX = data[0].getMaxX(); maxY = data[0].getMaxY(); for (XYSeries d : data) { dataset.addSeries(d); if (d.getMinX() < minX) { minX = d.getMinX(); } if (d.getMaxX() > maxX) { maxX = d.getMaxX(); } if (d.getMinY() < minY) { minY = d.getMinY(); } if (d.getMaxY() > maxY) { maxY = d.getMaxY(); } } JFreeChart chart = ChartFactory.createScatterPlot(title, // Title xTitle, // x-axis Label yTitle, // y-axis Label dataset, // Dataset PlotOrientation.VERTICAL, // Plot Orientation true, // Show Legend true, // Use tooltips false // Configure chart to generate URLs? ); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); for (int i = 0; i < data.length; i++) { renderer.setSeriesFillPaint(i, Color.white); renderer.setSeriesLinesVisible(i, true); } renderer.setSeriesPaint(0, Color.blue); Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 4.0f, 4.0f); renderer.setSeriesShape(0, circle, false); if (data.length > 1) { renderer.setSeriesPaint(1, Color.red); Shape square = new Rectangle2D.Float(-2.0f, -2.0f, 4.0f, 4.0f); renderer.setSeriesShape(1, square, false); } if (data.length > 2) { renderer.setSeriesPaint(2, Color.darkGray); Shape rect = new Rectangle2D.Float(-2.0f, -1.0f, 4.0f, 2.0f); renderer.setSeriesShape(2, rect, false); } if (data.length > 3) { renderer.setSeriesPaint(3, Color.magenta); Shape rect = new Rectangle2D.Float(-1.0f, -2.0f, 2.0f, 4.0f); renderer.setSeriesShape(3, rect, false); } for (int i = 0; i < data.length; i++) { if (showShapes.length > i && !showShapes[i]) { renderer.setSeriesShapesVisible(i, false); } } // place annotation at 80 % of max X, maxY XYAnnotation an = new XYTextAnnotation(annotation, maxX - 0.2 * (maxX - minX), maxY); plot.addAnnotation(an); renderer.setUseFillPaint(true); final MyChartFrame graphFrame = new MyChartFrame(title, chart); graphFrame.getChartPanel().setMouseWheelEnabled(true); graphFrame.pack(); graphFrame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent arg0) { graphFrame.dispose(); } }); graphFrame.setVisible(true); return graphFrame; }
From source file:de.suse.swamp.modules.scheduledjobs.Statistics.java
/** * Generating the graphs that show the amount of running finished wfs over the time. *//*w w w . j ava 2 s .c o m*/ 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:opendial.gui.stateviewer.DistributionViewer.java
/** * Constructs a chart panel for the continuous distribution. * // w w w . jav a 2 s . co m * @param distrib the continuous distribution * @return the generated chart panel * @throws DialException if the distribution could not be displayed */ private ChartPanel generatePanel(ContinuousDistribution distrib) throws DialException { final String variableName = distrib.getVariable(); List<XYSeries> series = extractSeries(distrib.getFunction()); CombinedDomainXYPlot combined = new CombinedDomainXYPlot(new NumberAxis("Value")); for (XYSeries serie : series) { JFreeChart chart = ChartFactory.createXYLineChart("", // chart title "Value", // domain axis label "Density", // range axis label new XYSeriesCollection(serie), // data PlotOrientation.VERTICAL, // orientation (distrib.getFunction().getDimensionality() > 1), // include legend true, // tooltips? false); // URLs? XYPlot plot = (XYPlot) chart.getPlot(); combined.add(plot); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.white); } return new ChartPanel(new JFreeChart("Probability distribution P(" + variableName + ")", JFreeChart.DEFAULT_TITLE_FONT, combined, true), false); }
From source file:subterranean.crimson.server.graphics.graphs.LineChart.java
private JFreeChart createChart(final XYDataset dataset) { final JFreeChart result = ChartFactory.createTimeSeriesChart("", "", "", dataset, false, false, false); XYPlot plot = result.getXYPlot(); plot.setDataset(1, new TimeSeriesCollection(s2)); plot.setBackgroundPaint(new Color(0x000000)); plot.setDomainGridlinesVisible(false); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinesVisible(false); plot.setRangeGridlinePaint(Color.lightGray); ValueAxis xaxis = plot.getDomainAxis(); xaxis.setAutoRange(true);/*from w ww . j a va 2s .c om*/ xaxis.setFixedAutoRange(160000.0); // 160 seconds xaxis.setVerticalTickLabels(false); ValueAxis yaxis = plot.getRangeAxis(); yaxis.setAutoRange(true); yaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return result; }
From source file:com.naval.gui.Gui.java
private void update() { Coordonnees coords = partie.coords;//w w w . j av a 2 s. co m XYSeriesCollection dataset = new XYSeriesCollection(); for (Navire n : partie.navires) { XYSeries series = new XYSeries(n.nom); for (int m = 0; m < partie.minute; m++) { Donnees d = coords.donneesPour(m); series.add(d.xs[n.id], d.ys[n.id]); } if (series.isEmpty() && partie.minute == 0) { series.add(n.x, n.y); } dataset.addSeries(series); } JFreeChart chart = ChartFactory.createXYLineChart( "Map turn " + partie.getHeureMinute() + " visibilite:" + partie.visibilite + "%", // Title "x-axis", // x-axis Label "y-axis", // y-axis Label dataset, // Dataset PlotOrientation.VERTICAL, // Plot Orientation true, // Show Legend true, // Use tooltips false // Configure chart to generate URLs? ); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.black); plot.setDomainGridlinePaint(Color.black); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, true); renderer.setSeriesLinesVisible(1, true); renderer.setSeriesShapesVisible(1, true); plot.setRenderer(renderer); if (cPanel != null) { remove(cPanel); cPanel = new ChartPanel(chart); add(cPanel, BorderLayout.CENTER); } else { cPanel = new ChartPanel(chart); add(cPanel, BorderLayout.CENTER); } frame.validate(); }
From source file:opendial.gui.utils.DistributionViewer.java
/** * Constructs a chart panel for the continuous distribution. * // ww w . ja v a 2 s. co m * @param distrib the continuous distribution * @return the generated chart panel */ private ChartPanel generatePanel(ContinuousDistribution distrib) { final String variableName = distrib.getVariable(); List<XYSeries> series = extractSeries(distrib.getFunction()); CombinedDomainXYPlot combined = new CombinedDomainXYPlot(new NumberAxis("Value")); for (XYSeries serie : series) { JFreeChart chart = ChartFactory.createXYLineChart("", // chart title "Value", // domain axis label "Density", // range axis label new XYSeriesCollection(serie), // data PlotOrientation.VERTICAL, // orientation (distrib.getFunction().getDimensions() > 1), // include // legend true, // tooltips? false); // URLs? XYPlot plot = (XYPlot) chart.getPlot(); combined.add(plot); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.white); } return new ChartPanel(new JFreeChart("Probability distribution P(" + variableName + ")", JFreeChart.DEFAULT_TITLE_FONT, combined, true), false); }
From source file:com.bitplan.vzjava.Plot.java
/** * Creates a chart.//www . j a v a2 s .co m * * @param dataset * a dataset. * * @return A chart. */ private JFreeChart createChart(final ColoredDataSet cdataset) { final JFreeChart chart = ChartFactory.createTimeSeriesChart(title, "Time", "Power", cdataset.dataSet, true, true, false); chart.setBackgroundPaint(Color.white); // final StandardLegend sl = (StandardLegend) chart.getLegend(); // sl.setDisplaySeriesShapes(true); final XYPlot plot = chart.getXYPlot(); // plot.setOutlinePaint(null); 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)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(false); final XYItemRenderer renderer = plot.getRenderer(); if (renderer instanceof StandardXYItemRenderer) { renderer.setSeriesStroke(0, new BasicStroke(3.0f)); renderer.setSeriesStroke(1, new BasicStroke(3.0f)); } final DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("HH:mm")); // http://www.jfree.org/jfreechart/api/gjdoc/org/jfree/chart/plot/DefaultDrawingSupplier-source.html DrawingSupplier supplier = new DefaultDrawingSupplier(cdataset.paintSequence, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE); chart.getPlot().setDrawingSupplier(supplier); return chart; }