List of usage examples for org.jfree.chart.plot XYPlot getRenderer
public XYItemRenderer getRenderer()
From source file:org.jfree.experimental.chart.demo.XYTitleAnnotationDemo1.java
/** * Creates a chart.//w w w . j ava2 s. co m * * @param dataset a dataset. * * @return A chart. */ private static JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", // title "Date", // x-axis label "Price Per Unit", // y-axis label dataset, // data false, // create legend? true, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); 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); LegendTitle lt = new LegendTitle(plot); lt.setItemFont(new Font("Dialog", Font.PLAIN, 9)); lt.setBackgroundPaint(new Color(200, 200, 255, 100)); lt.setFrame(new BlockBorder(Color.white)); lt.setPosition(RectangleEdge.BOTTOM); XYTitleAnnotation ta = new XYTitleAnnotation(0.98, 0.02, lt, RectangleAnchor.BOTTOM_RIGHT); ta.setMaxWidth(0.48); plot.addAnnotation(ta); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); } DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); ValueAxis yAxis = plot.getRangeAxis(); yAxis.setLowerMargin(0.35); return chart; }
From source file:org.mwc.debrief.sensorfusion.views.DataSupport.java
/** * Creates a chart./* w w w.ja v a2 s .co m*/ * * @param dataset * a dataset. * * @return A chart. */ public static JFreeChart createChart(final XYDataset dataset) { final JFreeChart chart = ChartFactory.createTimeSeriesChart("Bearing Management", // title "Time", // x-axis label "Bearing", // y-axis label dataset, // data false, // create legend? true, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(Color.white); final XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); plot.setOrientation(PlotOrientation.HORIZONTAL); final XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); } final DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("HH:mm.ss")); return chart; }
From source file:org.jfree.chart.demo.QuarterDateFormatDemo.java
private static JFreeChart createChart(XYDataset xydataset) { JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", "Date", "Price Per Unit", xydataset, true, true, false); jfreechart.setBackgroundPaint(Color.white); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); PeriodAxis periodaxis = new PeriodAxis("Quarter", new Quarter(), new Quarter()); periodaxis.setAutoRangeTimePeriodClass(org.jfree.data.time.Quarter.class); PeriodAxisLabelInfo aperiodaxislabelinfo[] = new PeriodAxisLabelInfo[1]; aperiodaxislabelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Quarter.class, new QuarterDateFormat(TimeZone.getDefault(), QuarterDateFormat.ROMAN_QUARTERS)); periodaxis.setLabelInfo(aperiodaxislabelinfo); xyplot.setDomainAxis(periodaxis);//from w ww.j a v a 2 s . c o m xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); xyplot.setDomainCrosshairVisible(true); xyplot.setRangeCrosshairVisible(true); org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer(); if (xyitemrenderer instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer; xylineandshaperenderer.setBaseShapesVisible(true); xylineandshaperenderer.setBaseShapesFilled(true); } return jfreechart; }
From source file:net.sf.mzmine.chartbasics.HistogramChartFactory.java
public static JFreeChart createHistogramOld(double[] data, int bin, String yAxisLabel, double min, double max) { if (data != null && data.length > 0) { HistogramDataset dataset = new HistogramDataset(); dataset.addSeries("histo", data, bin, min, max); JFreeChart chart = ChartFactory.createHistogram("", yAxisLabel, "n", dataset, PlotOrientation.VERTICAL, true, false, false);// www .ja v a2 s. c o m chart.setBackgroundPaint(new Color(230, 230, 230)); chart.getLegend().setVisible(false); XYPlot xyplot = chart.getXYPlot(); xyplot.setForegroundAlpha(0.7F); xyplot.setBackgroundPaint(Color.WHITE); xyplot.setDomainGridlinePaint(new Color(150, 150, 150)); xyplot.setRangeGridlinePaint(new Color(150, 150, 150)); xyplot.getDomainAxis().setVisible(true); xyplot.getRangeAxis().setVisible(yAxisLabel != null); XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer(); xybarrenderer.setShadowVisible(false); xybarrenderer.setBarPainter(new StandardXYBarPainter()); // xybarrenderer.setDrawBarOutline(false); return chart; } else return null; }
From source file:org.jfree.chart.demo.XYTitleAnnotationDemo1.java
private static JFreeChart createChart(XYDataset xydataset) { JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", "Date", "Price Per Unit", xydataset, false, true, false); jfreechart.setBackgroundPaint(Color.white); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); xyplot.setDomainCrosshairVisible(true); xyplot.setRangeCrosshairVisible(true); LegendTitle legendtitle = new LegendTitle(xyplot); legendtitle.setItemFont(new Font("Dialog", 0, 9)); legendtitle.setBackgroundPaint(new Color(200, 200, 255, 100)); legendtitle.setFrame(new BlockBorder(Color.white)); legendtitle.setPosition(RectangleEdge.BOTTOM); XYTitleAnnotation xytitleannotation = new XYTitleAnnotation(0.97999999999999998D, 0.02D, legendtitle, RectangleAnchor.BOTTOM_RIGHT); xytitleannotation.setMaxWidth(0.47999999999999998D); xyplot.addAnnotation(xytitleannotation); org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer(); if (xyitemrenderer instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer; xylineandshaperenderer.setBaseShapesVisible(true); xylineandshaperenderer.setBaseShapesFilled(true); }//from www. ja va 2s . c o m DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); ValueAxis valueaxis = xyplot.getRangeAxis(); valueaxis.setLowerMargin(0.34999999999999998D); return jfreechart; }
From source file:org.nbrcp.demo.core.views.Barchart.java
private void setUpView() { final JFreeChart chart = ChartFactory.createXYBarChart("", "X", false, "Y", Data.getDataset(), PlotOrientation.HORIZONTAL, true, true, false); XYPlot plot = chart.getXYPlot(); XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setShadowVisible(false);/*from w ww . java2 s.c o m*/ renderer.setMargin(0.96); final ChartPanel panel = new ChartPanel(chart); panel.setMinimumDrawHeight(10); panel.setMaximumDrawHeight(2000); panel.setMinimumDrawWidth(10); panel.setMaximumDrawWidth(2000); panel.setSize(this.getSize()); this.add(panel); }
From source file:tarea1.histogram.java
private ChartPanel createChartPanel() { // dataset/*www.java 2 s .c o m*/ HistogramDataset dataset = new HistogramDataset(); Raster raster = image.getRaster(); final int w = image.getWidth(); final int h = image.getHeight(); double[] r = new double[w * h]; r = raster.getSamples(0, 0, w, h, 0, r); dataset.addSeries("Red", r, BINS); r = raster.getSamples(0, 0, w, h, 1, r); dataset.addSeries("Green", r, BINS); r = raster.getSamples(0, 0, w, h, 2, r); dataset.addSeries("Blue", r, BINS); // chart JFreeChart chart = ChartFactory.createHistogram("Histogram", "Value", "Count", dataset, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setBarPainter(new StandardXYBarPainter()); // translucent red, green & blue Paint[] paintArray = { new Color(0x80ff0000, true), new Color(0x8000ff00, true), new Color(0x800000ff, true) }; plot.setDrawingSupplier( new DefaultDrawingSupplier(paintArray, DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE)); ChartPanel panel = new ChartPanel(chart); panel.setMouseWheelEnabled(true); return panel; }
From source file:scrum.server.common.BurndownChart.java
private static JFreeChart createSprintBurndownChart(List<BurndownSnapshot> snapshots, Date firstDay, Date lastDay, Date originallyLastDay, WeekdaySelector freeDays, int dateMarkTickUnit, float widthPerDay) { DefaultXYDataset data = createSprintBurndownChartDataset(snapshots, firstDay, lastDay, originallyLastDay, freeDays);/*from w ww .j a va 2s . co m*/ double tick = 1.0; double max = BurndownChart.getMaximum(data); while (max / tick > 25) { tick *= 2; if (max / tick <= 25) break; tick *= 2.5; if (max / tick <= 25) break; tick *= 2; } double valueLabelTickUnit = tick; double upperBoundary = Math.min(max * 1.1f, max + 3); if (!Sys.isHeadless()) LOG.warn("GraphicsEnvironment is not headless"); JFreeChart chart = ChartFactory.createXYLineChart("", "", "", data, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.WHITE); XYPlot plot = chart.getXYPlot(); // plot.setInsets(new RectangleInsets(0, 0, 0, 0)); plot.setAxisOffset(RectangleInsets.ZERO_INSETS); // plot.setOutlineVisible(false); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); plot.setDomainGridlinePaint(Color.lightGray); // plot.setRangeCrosshairPaint(Color.lightGray); // plot.setRangeMinorGridlinePaint(Color.lightGray); // plot.setDomainCrosshairPaint(Color.blue); // plot.setDomainMinorGridlinePaint(Color.green); // plot.setDomainTickBandPaint(Color.green); XYItemRenderer renderer = plot.getRenderer(); renderer.setBaseStroke(new BasicStroke(2f)); renderer.setSeriesPaint(0, COLOR_PAST_LINE); renderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer.setSeriesPaint(1, COLOR_PROJECTION_LINE); renderer.setSeriesStroke(1, new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL, 1.0f, new float[] { 3f }, 0)); renderer.setSeriesPaint(2, COLOR_OPTIMUM_LINE); renderer.setSeriesStroke(2, new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); DateAxis domainAxis1 = new DateAxis(); String dateFormat = "d."; widthPerDay -= 5; if (widthPerDay > 40) { dateFormat = "EE " + dateFormat; } if (widthPerDay > 10) { float spaces = widthPerDay / 2.7f; dateFormat = Str.multiply(" ", (int) spaces) + dateFormat; } domainAxis1.setDateFormatOverride(new SimpleDateFormat(dateFormat, Locale.US)); domainAxis1.setTickUnit(new DateTickUnit(DateTickUnit.DAY, dateMarkTickUnit)); domainAxis1.setAxisLineVisible(false); Range range = new Range(firstDay.toMillis(), lastDay.nextDay().toMillis()); domainAxis1.setRange(range); DateAxis domainAxis2 = new DateAxis(); domainAxis2.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 1)); domainAxis2.setTickMarksVisible(false); domainAxis2.setTickLabelsVisible(false); domainAxis2.setRange(range); plot.setDomainAxis(0, domainAxis2); plot.setDomainAxis(1, domainAxis1); plot.setDomainAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setNumberFormatOverride(NumberFormat.getIntegerInstance()); rangeAxis.setTickUnit(new NumberTickUnit(valueLabelTickUnit)); rangeAxis.setLowerBound(0); rangeAxis.setUpperBound(upperBoundary); plot.setRangeAxis(rangeAxis); return chart; }
From source file:org.operamasks.faces.render.graph.BarChartRenderer.java
private void setBarStyles(XYPlot plot, UIChart comp) { XYItemRenderer r = plot.getRenderer(); if (r instanceof XYBarRenderer) { XYBarRenderer renderer = (XYBarRenderer) r; Boolean drawOutline = comp.getDrawOutline(); if (drawOutline != null) { renderer.setDrawBarOutline(drawOutline); }/*from www . j av a 2 s .c o m*/ } }
From source file:org.jfree.chart.demo.MarkerDemo2.java
private static JFreeChart createChart(XYDataset xydataset) { JFreeChart jfreechart = ChartFactory.createXYLineChart("Marker Demo 2", "X", "Temperature", xydataset, PlotOrientation.VERTICAL, false, true, false); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setDomainGridlinePaint(Color.lightGray); xyplot.setDomainGridlineStroke(new BasicStroke(1.0F)); xyplot.setRangeGridlinePaint(Color.lightGray); xyplot.setRangeGridlineStroke(new BasicStroke(1.0F)); xyplot.setRangeTickBandPaint(new Color(240, 240, 240)); PeriodAxis periodaxis = new PeriodAxis(null, new Hour(0, 30, 6, 2005), new Hour(23, 30, 6, 2005)); PeriodAxisLabelInfo aperiodaxislabelinfo[] = new PeriodAxisLabelInfo[2]; aperiodaxislabelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Hour.class, new SimpleDateFormat("HH")); aperiodaxislabelinfo[1] = new PeriodAxisLabelInfo(org.jfree.data.time.Day.class, new SimpleDateFormat("dd-MMM")); periodaxis.setLabelInfo(aperiodaxislabelinfo); xyplot.setDomainAxis(periodaxis);//w ww . j a v a 2 s . c o m ValueAxis valueaxis = xyplot.getRangeAxis(); valueaxis.setRange(0.0D, 100D); XYItemRenderer xyitemrenderer = xyplot.getRenderer(); xyitemrenderer.setSeriesPaint(0, Color.green); xyitemrenderer.setSeriesStroke(0, new BasicStroke(2.0F)); ValueMarker valuemarker = new ValueMarker(80D); valuemarker.setLabelOffsetType(LengthAdjustmentType.EXPAND); valuemarker.setPaint(Color.red); valuemarker.setStroke(new BasicStroke(2.0F)); valuemarker.setLabel("Temperature Threshold"); valuemarker.setLabelFont(new Font("SansSerif", 0, 11)); valuemarker.setLabelPaint(Color.red); valuemarker.setLabelAnchor(RectangleAnchor.TOP_LEFT); valuemarker.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT); xyplot.addRangeMarker(valuemarker); Hour hour = new Hour(18, 30, 6, 2005); Hour hour1 = new Hour(20, 30, 6, 2005); double d = hour.getFirstMillisecond(); double d1 = hour1.getFirstMillisecond(); IntervalMarker intervalmarker = new IntervalMarker(d, d1); intervalmarker.setLabelOffsetType(LengthAdjustmentType.EXPAND); intervalmarker.setPaint(new Color(150, 150, 255)); intervalmarker.setLabel("Automatic Cooling"); intervalmarker.setLabelFont(new Font("SansSerif", 0, 11)); intervalmarker.setLabelPaint(Color.blue); intervalmarker.setLabelAnchor(RectangleAnchor.TOP_LEFT); intervalmarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); xyplot.addDomainMarker(intervalmarker, Layer.BACKGROUND); ValueMarker valuemarker1 = new ValueMarker(d, Color.blue, new BasicStroke(2.0F)); ValueMarker valuemarker2 = new ValueMarker(d1, Color.blue, new BasicStroke(2.0F)); xyplot.addDomainMarker(valuemarker1, Layer.BACKGROUND); xyplot.addDomainMarker(valuemarker2, Layer.BACKGROUND); return jfreechart; }