List of usage examples for org.jfree.chart.plot XYPlot XYPlot
public XYPlot(XYDataset dataset, ValueAxis domainAxis, ValueAxis rangeAxis, XYItemRenderer renderer)
From source file:tools.descartes.bungee.chart.ChartGenerator.java
public static XYPlot createIntensityPlot(final List<ArrivalRateTuple> intensities) { final TimeSeriesCollection dataset = new TimeSeriesCollection(); final TimeSeries series = new TimeSeries("load intensity"); for (ArrivalRateTuple intensity : intensities) { long milliseconds = (referenceDate.getTime() / 1000 + (long) Math.floor(intensity.getTimeStamp())) * 1000;/* w w w . j ava2s . c o m*/ series.add(new FixedMillisecond(milliseconds), intensity.getArrivalRate()); } dataset.addSeries(series); XYStepRenderer renderer = new XYStepRenderer(); //renderer.setSeriesStroke(0, (new BasicStroke(2.0F))); renderer.setSeriesPaint(0, Color.GRAY); final NumberAxis rangeAxis = new NumberAxis("Arrival Rate [1/s]"); //rangeAxis.setRange(0, 220); final XYPlot intensityPlot = new XYPlot(dataset, null, rangeAxis, renderer); return intensityPlot; }
From source file:charts.Chart.java
public static void ScatterPlot(XYSeriesCollection dataset, String title, String xAxisLabel, String yAxisLabel) { NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setAutoRangeIncludesZero(false); XYToolTipGenerator toolTipGenerator = new StandardXYToolTipGenerator(); XYURLGenerator urlGenerator = new StandardXYURLGenerator(); XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true);//(boolean lines, boolean shapes) renderer.setBaseToolTipGenerator(toolTipGenerator); renderer.setURLGenerator(urlGenerator); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); //plot.setDataset(dataset); //plot.setDomainAxis(xAxis); //plot.setRangeAxis(yAxis); //plot.setRenderer(renderer); plot.setOrientation(PlotOrientation.VERTICAL); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);//true==legend //INVERTER AS CORES DOS PONTOS E LEGENDA. if (dataset.getSeriesCount() > 1) { Shape s0 = plot.getLegendItems().get(0).getShape(); Shape s1 = plot.getLegendItems().get(1).getShape(); renderer.setSeriesShape(0, s1);/*from w w w . ja v a 2s . c o m*/ renderer.setSeriesShape(1, s0); Paint p0 = plot.getLegendItems().get(0).getLinePaint(); Paint p1 = plot.getLegendItems().get(1).getLinePaint(); renderer.setSeriesPaint(0, p1); renderer.setSeriesPaint(1, p0); } //FIM DA INVERSAO. JFrame chartwindow = new JFrame(title); JPanel jpanel = new ChartPanel(chart); jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight)); chartwindow.setContentPane(jpanel); chartwindow.pack(); RefineryUtilities.centerFrameOnScreen(chartwindow); chartwindow.setVisible(true); }
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);/*from w w w . j a v a2s. c om*/ xAxis.setUpperMargin(0.0); 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:asl.util.PlotMaker.java
public void plotCoherence(double per[], double[] gamma, String plotString) { final String plotTitle = String.format("%04d%03d.%s.%s-%s", date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR), station, channelX, channelY); final String pngName = String.format("%s/%04d%03d.%s.%s-%s.%s.png", outputDir, date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR), station, channelX, channelY, plotString); File outputFile = new File(pngName); // Check that we will be able to output the file without problems and if not --> return if (!checkFileOut(outputFile)) { System.out.format("== plotCoherence: request to output plot=[%s] but we are unable to create it " + " --> skip plot\n", pngName); return;//www . ja v a 2s . co m } final String legend = String.format("%s--%s", channelX, channelY); final XYSeries series1 = new XYSeries(legend); for (int k = 0; k < gamma.length; k++) { series1.add(per[k], gamma[k]); } //final XYItemRenderer renderer1 = new StandardXYItemRenderer(); final XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer(); Rectangle rectangle = new Rectangle(3, 3); renderer1.setSeriesShape(0, rectangle); renderer1.setSeriesShapesVisible(0, true); renderer1.setSeriesLinesVisible(0, false); Paint[] paints = new Paint[] { Color.red, Color.black }; renderer1.setSeriesPaint(0, paints[0]); final NumberAxis rangeAxis1 = new NumberAxis("Coherence, Gamma"); rangeAxis1.setRange(new Range(0, 1.2)); rangeAxis1.setTickUnit(new NumberTickUnit(0.1)); final LogarithmicAxis horizontalAxis = new LogarithmicAxis("Period (sec)"); horizontalAxis.setRange(new Range(0.05, 10000)); final XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(series1); final XYPlot xyplot = new XYPlot((XYDataset) seriesCollection, horizontalAxis, rangeAxis1, renderer1); xyplot.setDomainGridlinesVisible(true); xyplot.setRangeGridlinesVisible(true); xyplot.setRangeGridlinePaint(Color.black); xyplot.setDomainGridlinePaint(Color.black); final JFreeChart chart = new JFreeChart(xyplot); chart.setTitle(new TextTitle(plotTitle)); try { ChartUtilities.saveChartAsPNG(outputFile, chart, 500, 300); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } }
From source file:org.hxzon.demo.jfreechart.XYDatasetDemo2.java
private static JFreeChart createXYStepAreaChart(XYDataset dataset) { NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); XYToolTipGenerator toolTipGenerator = null; if (tooltips) { toolTipGenerator = new StandardXYToolTipGenerator(); }//from w w w . j a v a 2 s .co m XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } XYItemRenderer renderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA_AND_SHAPES, toolTipGenerator, urlGenerator); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); plot.setRenderer(renderer); plot.setOrientation(orientation); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); JFreeChart chart = new JFreeChart("XYStepArea Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); yAxis.setNumberFormatOverride(MyNumberFormat.getMyNumberFormat()); return chart; }
From source file:loci.slim.ui.DecayGraph.java
/** * Creates the chart//from www . j av a 2 s . co m * * @param bins number of bins * @param timeInc time increment per bin * @return the chart */ JFreeChart createCombinedChart(final int bins, final double timeInc) { // create empty chart data sets _decayDataset = new XYSeriesCollection(); _residualDataset = new XYSeriesCollection(); // make a common horizontal axis for both sub-plots final NumberAxis timeAxis = new NumberAxis(TIME_AXIS_LABEL); timeAxis.setLabel(UNITS_LABEL); timeAxis.setRange(0.0, (bins - 1) * timeInc); // make a vertically combined plot final CombinedDomainXYPlot parent = new CombinedDomainXYPlot(timeAxis); // create decay sub-plot NumberAxis photonAxis; if (_logarithmic) { photonAxis = new LogarithmicAxis(PHOTON_AXIS_LABEL); } else { photonAxis = new NumberAxis(PHOTON_AXIS_LABEL); } final XYSplineRenderer decayRenderer = new XYSplineRenderer(); decayRenderer.setSeriesShapesVisible(0, false); decayRenderer.setSeriesShapesVisible(1, false); decayRenderer.setSeriesLinesVisible(2, false); decayRenderer.setSeriesShape(2, new Ellipse2D.Float(-1.0f, -1.0f, 2.0f, 2.0f)); decayRenderer.setSeriesPaint(0, PROMPT_COLOR); decayRenderer.setSeriesPaint(1, FITTED_COLOR); decayRenderer.setSeriesPaint(2, DECAY_COLOR); _decaySubPlot = new XYPlot(_decayDataset, null, photonAxis, decayRenderer); _decaySubPlot.setDomainCrosshairVisible(true); _decaySubPlot.setRangeCrosshairVisible(true); // add decay sub-plot to parent parent.add(_decaySubPlot, DECAY_WEIGHT); // create residual sub-plot final NumberAxis residualAxis = new NumberAxis(RESIDUAL_AXIS_LABEL); final XYSplineRenderer residualRenderer = new XYSplineRenderer(); residualRenderer.setSeriesPaint(0, RESIDUAL_COLOR); residualRenderer.setSeriesLinesVisible(0, false); residualRenderer.setSeriesShape(0, new Ellipse2D.Float(-1.0f, -1.0f, 2.0f, 2.0f)); final XYPlot residualSubPlot = new XYPlot(_residualDataset, null, residualAxis, residualRenderer); residualSubPlot.setDomainCrosshairVisible(true); residualSubPlot.setRangeCrosshairVisible(true); residualSubPlot.setFixedLegendItems(null); // add residual sub-plot to parent parent.add(residualSubPlot, RESIDUAL_WEIGHT); // now make the top level JFreeChart final JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, parent, true); chart.removeLegend(); return chart; }
From source file:org.jfree.chart.demo.SymbolicYPlotDemo.java
/** * Creates a XY graph with symbolic value on Y axis. * /*from w ww. j a v a 2 s . c o m*/ * @param title * the chart title. * @param xAxisLabel * the x-axis label. * @param yAxisLabel * the y-axis label. * @param data * the data. * @param legend * a flag controlling whether or not the legend is created for the chart. * @return the chart. */ public static JFreeChart createYSymbolicPlot(final String title, final String xAxisLabel, final String yAxisLabel, final XYDataset data, final boolean legend) { final ValueAxis valueAxis = new NumberAxis(xAxisLabel); final SymbolicAxis symbolicAxis = new SymbolicAxis(yAxisLabel, ((YisSymbolic) data).getYSymbolicValues()); final XYPlot plot = new XYPlot(data, valueAxis, symbolicAxis, null); final XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, new SymbolicXYItemLabelGenerator()); plot.setRenderer(renderer); final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:org.hxzon.demo.jfreechart.OtherDatasetDemo.java
private static JFreeChart createBubbleChart(XYZDataset dataset) { NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); // A renderer that draws a circle at each data point with a diameter that is // determined by the z-value in the dataset (the renderer requires the dataset // to be an instance of {@link XYZDataset}. XYItemRenderer renderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator()); }//from w w w . ja v a2s . com if (urls) { renderer.setURLGenerator(new StandardXYZURLGenerator()); } plot.setRenderer(renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart("Bubble Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); return chart; }
From source file:de.codesourcery.eve.skills.ui.components.impl.PriceHistoryComponent.java
private JPanel createFreeChartPanel2() { /*// w w w. j a v a2s.c o m * Price plot. */ final StandardXYItemRenderer renderer1 = new StandardXYItemRenderer(); renderer1.setDrawSeriesLineAsPath(false); final ValueAxis priceAxis = new NumberAxis("ISK"); currentDataSets.pricePlot = new XYPlot(currentDataSets.prices, null, priceAxis, renderer1); currentDataSets.pricePlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); /* * Buy/sell volume plot. */ final StandardXYItemRenderer renderer2 = // XYBarRenderer new StandardXYItemRenderer(); final ValueAxis volumeAxis = new NumberAxis("Units"); TimeSeriesCollection volumes = new TimeSeriesCollection(); volumes.addSeries(currentDataSets.buyVolume); volumes.addSeries(currentDataSets.sellVolume); currentDataSets.volumePlot = new XYPlot(volumes, null, volumeAxis, renderer2); currentDataSets.volumePlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); /* * Combined plot. */ final ValueAxis dateAxis = new DateAxis("Date"); final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(dateAxis); plot.setGap(10.0); plot.add(currentDataSets.pricePlot, 2); plot.add(currentDataSets.volumePlot, 1); plot.setOrientation(PlotOrientation.VERTICAL); /* * Create chart. */ chart = new JFreeChart(item.getName(), JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); final XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); } final DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("yyyy-MM-dd")); changeDateRange((DisplayRange) this.dateRangeChooser.getSelectedItem()); // display chart ChartPanel chartPanel = new ChartPanel(chart); // chartPanel.setMouseZoomable(true, false); return chartPanel; }
From source file:com.ewcms.plugin.report.generate.service.chart.ChartGenerationService.java
/** * ?//ww w . jav a2 s. c o m * <P> * ?XYPlot? ??? * <P> * ?:???TimeSeriesCollection?XYDataset? * * @param title * @param titleFont * @param timeAxisLabel * @param valueAxisLabel * @param data ?? * @param legend * @param tooltips ???? * @param urls ??URL * * @return ? */ public static JFreeChart createTimeSeriesChart(String title, java.awt.Font titleFont, String timeAxisLabel, String valueAxisLabel, XYDataset data, boolean legend, boolean tooltips, boolean urls) { ValueAxis timeAxis = new DateAxis(timeAxisLabel); timeAxis.setLowerMargin(0.02); timeAxis.setUpperMargin(0.02); NumberAxis valueAxis = new NumberAxis(valueAxisLabel); valueAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(data, timeAxis, valueAxis, null); XYToolTipGenerator tooltipGenerator = null; if (tooltips) { tooltipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance(); // new StandardXYToolTipGenerator(DateFormat.getDateInstance()); } XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } plot.setRenderer(new StandardXYItemRenderer(StandardXYItemRenderer.LINES, tooltipGenerator, urlGenerator)); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }