List of usage examples for org.jfree.chart JFreeChart getPlot
public Plot getPlot()
From source file:be.vds.jtbdive.client.view.core.stats.StatChartGenerator.java
private static JFreeChart buildChartForDive(StatQueryObject sqo) { Collection<StatSerie> s = sqo.getValues(); String legend = I18nResourceManager.sharedInstance().getString("dive.times"); TimeSeriesCollection collection = new TimeSeriesCollection(); for (StatSerie statSerie : s) { TimeSeries ts = new TimeSeries(legend); for (StatPoint point : statSerie.getPoints()) { Date dd = (Date) point.getX(); FixedMillisecond day = new FixedMillisecond(dd); Object index = ts.getDataItem(day); if (null != index) { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(dd);//from w w w . j ava2s . c o m gc.add(Calendar.MILLISECOND, 1); day = new FixedMillisecond(gc.getTime()); } if (sqo.getStatYAxisParams().getStatYAxis().equals(StatYAxis.DEPTHS)) { ts.add(day, UnitsAgent.getInstance().convertLengthFromModel((Double) point.getY())); } else if (sqo.getStatYAxisParams().getStatYAxis().equals(StatYAxis.TEMPERATURES)) { ts.add(day, UnitsAgent.getInstance().convertTemperatureFromModel((Double) point.getY())); } else { ts.add(day, point.getY()); } } collection.addSeries(ts); } JFreeChart chart = createLineChart(collection, getXLabel(sqo), getYLabel(sqo)); if (sqo.getStatYAxisParams().getStatYAxis().equals(StatYAxis.DIVE_TIME)) { XYPlot xyp = (XYPlot) chart.getPlot(); ((NumberAxis) xyp.getRangeAxis()).setNumberFormatOverride(new HoursMinutesNumberFormat()); } return chart; }
From source file:org.jfree.chart.demo.ParetoChartDemo1.java
public static JFreeChart createChart(CategoryDataset acategorydataset[]) { JFreeChart jfreechart = ChartFactory.createBarChart("Freshmeat Software Projects", "Language", "Projects", acategorydataset[0], PlotOrientation.VERTICAL, true, true, false); jfreechart.addSubtitle(new TextTitle("By Programming Language")); jfreechart.addSubtitle(new TextTitle("As at 5 March 2003")); jfreechart.setBackgroundPaint(Color.white); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setRangeGridlinePaint(Color.white); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setLowerMargin(0.02D);/*from www . j ava 2 s . c o m*/ categoryaxis.setUpperMargin(0.02D); categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); LineAndShapeRenderer lineandshaperenderer = new LineAndShapeRenderer(); NumberAxis numberaxis1 = new NumberAxis("Percent"); numberaxis1.setNumberFormatOverride(NumberFormat.getPercentInstance()); categoryplot.setRangeAxis(1, numberaxis1); categoryplot.setDataset(1, acategorydataset[1]); categoryplot.setRenderer(1, lineandshaperenderer); categoryplot.mapDatasetToRangeAxis(1, 1); categoryplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); return jfreechart; }
From source file:org.jfree.chart.demo.XYBarChartDemo1.java
private static JFreeChart createChart(IntervalXYDataset intervalxydataset) { JFreeChart jfreechart = ChartFactory.createXYBarChart("State Executions - USA", "Year", true, "Number of People", intervalxydataset, PlotOrientation.VERTICAL, true, false, false); jfreechart.addSubtitle(new TextTitle("Source: http://www.amnestyusa.org/abolish/listbyyear.do", new Font("Dialog", 2, 10))); jfreechart.setBackgroundPaint(Color.white); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); XYItemRenderer xyitemrenderer = xyplot.getRenderer(); StandardXYToolTipGenerator standardxytooltipgenerator = new StandardXYToolTipGenerator("{1} = {2}", new SimpleDateFormat("yyyy"), new DecimalFormat("0")); xyitemrenderer.setBaseToolTipGenerator(standardxytooltipgenerator); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setRangeGridlinePaint(Color.white); DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); dateaxis.setLowerMargin(0.01D);//from www . ja va 2 s .co m dateaxis.setUpperMargin(0.01D); return jfreechart; }
From source file:org.jrecruiter.web.actions.admin.ShowStatisticsAction.java
private static JFreeChart createChart(final CategoryDataset categorydataset, final String chartTitle) { final JFreeChart chart = ChartFactory.createBarChart(chartTitle, "Jobs", "Number of Hits", categorydataset, PlotOrientation.VERTICAL, true, true, false); final CategoryPlot categoryplot = (CategoryPlot) chart.getPlot(); categoryplot.setNoDataMessage("NO DATA!"); chart.setBackgroundPaint(new Color(245, 245, 255)); chart.setBorderPaint(new Color(204, 204, 204)); chart.setBorderStroke(new BasicStroke(1f)); final LegendTitle legend = chart.getLegend(); legend.setWidth(1000);/* w ww . j a va 2 s. c o m*/ legend.setPosition(RectangleEdge.BOTTOM); final BlockBorder border = new BlockBorder(new Color(204, 204, 204)); legend.setBorder(border); final CategoryPlot categoryPlot = (CategoryPlot) chart.getPlot(); categoryPlot.setBackgroundPaint(Color.WHITE); categoryPlot.setRangeGridlinePaint(new Color(204, 204, 204)); categoryPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); final NumberAxis numberaxis = (NumberAxis) categoryPlot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); final BarRenderer renderer = (BarRenderer) categoryPlot.getRenderer(); renderer.setDrawBarOutline(true); final ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER); renderer.setPositiveItemLabelPosition(itemlabelposition); renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setItemLabelsVisible(true); return chart; }
From source file:gui.statistic.JChartPanel.java
protected static JFreeChart createChart() { categoryDataset = new DefaultCategoryDataset(); //categoryDataset.addValue(20, "", "A"); //categoryDataset.addValue(35, "", "A"); //categoryDataset.addValue(40, "", "B"); //categoryDataset.addValue(60, "", "B"); JFreeChart chart = ChartFactory.createBarChart("", // Title "Belegungen", // X-Axis label "Werte", // Y-Axis label categoryDataset, // Dataset PlotOrientation.VERTICAL, false, true, false // Show legend );//from www .ja va 2s . com chart.setBackgroundPaint(Color.WHITE); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.LIGHT_GRAY); 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:org.physionet.graphics.Plot.java
private static JFreeChart createChart(XYDataset dataset, String title, String timeLabel, String amplitudeLabel) {//from ww w . j av a2 s. c o m // create the chart... JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title timeLabel, // x axis label amplitudeLabel, // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); XYPlot plot = (XYPlot) chart.getPlot(); plot.getDomainAxis().setLowerMargin(0.0); plot.getDomainAxis().setUpperMargin(0.0); return chart; }
From source file:gui.MainForm.java
private static JFreeChart create_AMS_DATA_Chart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createBarChart("AMS??", "", "??", categorydataset, PlotOrientation.VERTICAL, true, true, false); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setDomainGridlinesVisible(true); categoryplot.setRangeCrosshairVisible(true); categoryplot.setRangeCrosshairPaint(Color.blue); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setDrawBarOutline(false); GradientPaint gradientpaint = new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, new Color(0, 0, 64)); GradientPaint gradientpaint1 = new GradientPaint(0.0F, 0.0F, Color.green, 0.0F, 0.0F, new Color(0, 64, 0)); GradientPaint gradientpaint2 = new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, new Color(64, 0, 0)); barrenderer.setSeriesPaint(0, gradientpaint); barrenderer.setSeriesPaint(1, gradientpaint1); barrenderer.setSeriesPaint(2, gradientpaint2); barrenderer.setLegendItemToolTipGenerator(new StandardCategorySeriesLabelGenerator("Tooltip: {0}")); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(0.52359877559829882D)); return jfreechart; }
From source file:org.jfree.chart.demo.BarChartDemo1.java
/** * Creates a sample chart.//from w w w .j a va 2s .co m * * @param dataset the dataset. * * @return The chart. */ private static JFreeChart createChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createBarChart("Performance: JFreeSVG vs Batik", null /* x-axis label*/, "Milliseconds" /* y-axis label */, dataset); chart.addSubtitle( new TextTitle("Time to generate 1000 charts in SVG " + "format (lower bars = better performance)")); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); // ****************************************************************** // More than 150 demo applications are included with the JFreeChart // Developer Guide...for more information, see: // // > http://www.object-refinery.com/jfreechart/guide.html // // ****************************************************************** NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); chart.getLegend().setFrame(BlockBorder.NONE); return chart; }
From source file:com.ouc.cpss.view.ProfitChartBuilder.java
public static JFreeChart createJFreeChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createLineChart("?", "", "?", dataset, PlotOrientation.VERTICAL, true, true, false); // ?/*from w ww.j a v a2 s . c om*/ LegendTitle legendTitle = chart.getLegend(0); // legendTitle.setItemFont(new Font("", Font.BOLD, 18)); CategoryPlot plot = (CategoryPlot) chart.getPlot(); // ? org.jfree.chart.axis.CategoryAxis categoryAxis = plot.getDomainAxis(); // categoryAxis.setLabelFont(new Font("", Font.BOLD, 18)); // categoryAxis.setTickLabelFont(new Font("", Font.BOLD, 12)); // ? NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis(); // numberAxis.setLabelFont(new Font("", Font.BOLD, 14)); numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());// CategoryItemRenderer xylineandshaperenderer = plot.getRenderer(); xylineandshaperenderer.setBaseItemLabelsVisible(true); xylineandshaperenderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE2, TextAnchor.BASELINE_RIGHT)); xylineandshaperenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); return chart; }
From source file:org.jfree.chart.swt.demo.SWTBarChartDemo1.java
/** * Creates a sample chart.// w w w .ja va2 s .c o m * * @param dataset the dataset. * * @return The chart. */ private static JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart("SWTBarChartDemo1", // chart title "Category", // domain axis label "Value", // range axis label dataset); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // get a reference to the plot for further customisation... CategoryPlot plot = (CategoryPlot) chart.getPlot(); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // the SWTGraphics2D class doesn't handle GradientPaint well, so // replace the gradient painter from the default theme with a // standard painter... renderer.setBarPainter(new StandardBarPainter()); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }