List of usage examples for org.jfree.chart JFreeChart getPlot
public Plot getPlot()
From source file:msec.org.Tools.java
public static String generateDaysChart(String filename, ArrayList<OneDayValue> data, OneAttrDaysChart chart, String title, int duration) { if (data.size() == 0) { return "data size invalid"; }/*from www. j av a 2 s. c o m*/ int date = Integer.parseInt(data.get(0).getDate()); GregorianCalendar startgc = new GregorianCalendar(date / 10000, date % 10000 / 100 - 1, date % 100); XYDataset xydataset = createDaysDataset(data, startgc, chart); JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(title, "time", "", xydataset, true, true, true); try { XYPlot xyplot = (XYPlot) jfreechart.getPlot(); // DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setDateFormatOverride(new SimpleDateFormat("MM/dd")); dateaxis.setLabelFont(new Font("", Font.PLAIN, 16)); // dateaxis.setLabelPaint(ChartColor.gray); dateaxis.setTickLabelFont(new Font("", Font.PLAIN, 16)); dateaxis.setTickLabelPaint(ChartColor.GRAY); dateaxis.setMinimumDate(startgc.getTime()); GregorianCalendar endgc = (GregorianCalendar) startgc.clone(); endgc.add(GregorianCalendar.DATE, duration); dateaxis.setMaximumDate(endgc.getTime()); dateaxis.setTickMarksVisible(true); dateaxis.setTickMarkInsideLength(5); dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.DAY, 1)); dateaxis.setVerticalTickLabels(true); dateaxis.setLabel(""); // ValueAxis rangeAxis = xyplot.getRangeAxis();//? rangeAxis.setLabelFont(new Font("", Font.PLAIN, 16)); rangeAxis.setLabelPaint(ChartColor.gray); rangeAxis.setTickLabelFont(new Font("", Font.PLAIN, 16)); rangeAxis.setTickLabelPaint(ChartColor.gray); rangeAxis.setLowerBound(0); // jfreechart.getLegend().setItemFont(new Font("", Font.PLAIN, 12)); jfreechart.getLegend().setItemPaint(ChartColor.gray); jfreechart.getLegend().setBorder(0, 0, 0, 0);// // jfreechart.getTitle().setFont(new Font("", Font.PLAIN, 18));// jfreechart.getTitle().setPaint(ChartColor.gray); //? xyplot.setRangeGridlinePaint(ChartColor.GRAY); xyplot.setBackgroundPaint(ChartColor.WHITE); xyplot.setOutlinePaint(null);// int w = 500; int h = 300; // ChartUtilities.saveChartAsPNG(new File(filename), jfreechart, w, h); ChartUtilities.saveChartAsJPEG(new File(filename), 0.8f, jfreechart, w, h); return "success"; } catch (Exception e) { e.printStackTrace(); return e.getMessage(); } }
From source file:eu.cassandra.training.utils.ChartUtils.java
/** * This function is used for parsing and presenting the basic and the new * pricing schema.//from w w w .j a v a 2s .c o m * * @param basic * The basic pricing schema * @param after * The new pricing schema * * @return a chart panel with the * graphical representation. */ public static ChartPanel parsePricingScheme(String basic, String after) { double[] data = Utils.parseScheme(basic); double[] data2 = Utils.parseScheme(after); XYSeries series1 = new XYSeries("Basic Pricing Scheme"); for (int i = 0; i < data.length; i++) { series1.add(i, data[i]); } XYSeries series2 = new XYSeries("New Pricing Scheme"); for (int i = 0; i < data2.length; i++) { series2.add(i, data2[i]); } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series1); dataset.addSeries(series2); PlotOrientation orientation = PlotOrientation.VERTICAL; boolean show = true; boolean toolTips = false; boolean urls = false; JFreeChart chart = ChartFactory.createXYLineChart("Pricing Schemes", "Minute of Day", "Euros/kWh", dataset, orientation, show, toolTips, urls); XYPlot xyplot = (XYPlot) chart.getPlot(); xyplot.setDomainPannable(true); xyplot.setRangePannable(true); xyplot.setForegroundAlpha(0.85F); NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis(); domainAxis.setTickUnit(new NumberTickUnit(100)); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return new ChartPanel(chart); }
From source file:org.jfree.experimental.chart.swt.demo.SWTBarChartDemo1.java
/** * Creates a sample chart.//from ww w . j a v a 2s . com * * @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, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); // 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; }
From source file:com.orsonpdf.demo.PDFPieChartDemo1.java
/** * Creates a chart./*from w ww .j a v a2 s . c om*/ * * @param dataset the dataset. * * @return A chart. */ private static JFreeChart createChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart("Smart Phones Manufactured / Q3 2011", dataset, false, false, false); chart.setBackgroundPaint( new GradientPaint(new Point(0, 0), new Color(20, 20, 20), new Point(400, 200), Color.DARK_GRAY)); // customise the title position and font TextTitle t = chart.getTitle(); t.setHorizontalAlignment(HorizontalAlignment.LEFT); t.setPaint(new Color(240, 240, 240)); t.setFont(new Font("Arial", Font.BOLD, 26)); PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(null); plot.setInteriorGap(0.04); plot.setOutlineVisible(false); plot.setShadowPaint(null); plot.setLabelShadowPaint(null); // use gradients and white borders for the section colours plot.setSectionPaint("Others", createGradientPaint(new Color(200, 200, 255), Color.BLUE)); plot.setSectionPaint("Samsung", createGradientPaint(new Color(255, 200, 200), Color.RED)); plot.setSectionPaint("Apple", createGradientPaint(new Color(200, 255, 200), Color.GREEN)); plot.setSectionPaint("Nokia", createGradientPaint(new Color(200, 255, 200), Color.YELLOW)); plot.setBaseSectionOutlinePaint(Color.WHITE); plot.setSectionOutlinesVisible(true); BasicStroke bs = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 1.0f); plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f)); // customise the section label appearance plot.setLabelFont(new Font("Courier New", Font.BOLD, 20)); plot.setLabelLinkPaint(Color.WHITE); plot.setLabelLinkStroke(new BasicStroke(2.0f)); plot.setLabelOutlineStroke(null); plot.setLabelPaint(Color.WHITE); plot.setLabelBackgroundPaint(null); // add a subtitle giving the data source TextTitle source = new TextTitle("Source: http://www.bbc.co.uk/news/business-15489523", new Font("Courier New", Font.PLAIN, 12)); source.setPaint(Color.WHITE); source.setPosition(RectangleEdge.BOTTOM); source.setHorizontalAlignment(HorizontalAlignment.RIGHT); chart.addSubtitle(source); return chart; }
From source file:eu.choreos.vv.chart.XYChart.java
private static JFreeChart createChart(XYDataset dataset, String chartTitle, String xLabel, String yLabel) { // create the chart... JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title xLabel, // domain axis label yLabel, // range axis label dataset, // initial series PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? );//from w ww. ja va2s. c o m // set chart background chart.setBackgroundPaint(Color.white); // set a few custom plot features XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(new Color(0xffffe0)); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); // set the plot's axes to display integers TickUnitSource ticks = NumberAxis.createIntegerTickUnits(); NumberAxis domain = (NumberAxis) plot.getDomainAxis(); domain.setStandardTickUnits(ticks); domain.resizeRange(1.1); domain.setLowerBound(0.5); NumberAxis range = (NumberAxis) plot.getRangeAxis(); range.setStandardTickUnits(ticks); range.setUpperBound(range.getUpperBound() * 1.1); // render shapes and lines XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, true); plot.setRenderer(renderer); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); // set the renderer's stroke Stroke stroke = new BasicStroke(3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL); renderer.setBaseOutlineStroke(stroke); // label the points NumberFormat format = NumberFormat.getNumberInstance(); format.setMaximumFractionDigits(2); XYItemLabelGenerator generator = new StandardXYItemLabelGenerator( StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, format, format); renderer.setBaseItemLabelGenerator(generator); renderer.setBaseItemLabelsVisible(true); return chart; }
From source file:canreg.client.analysis.Tools.java
public static void setBarPlotColours(JFreeChart chart, int numberOfSections, Color baseColor) { Color color = baseColor;//from ww w.j a v a2 s. com BarRenderer renderer = (BarRenderer) ((CategoryPlot) chart.getPlot()).getRenderer(); renderer.setBarPainter(new StandardBarPainter()); for (int i = 0; i < numberOfSections; i++) { renderer.setSeriesPaint(i, color); color = darken(color); } }
From source file:userInterface.cdcRole.DecisionChartJPanel.java
private static JFreeChart createChart(PieDataset piedataset) { // System.out.println("1"); JFreeChart jfreechart = ChartFactory.createPieChart3D("Top 5 States (For Vaccinations)", piedataset, true, false, false);/*from w w w . jav a 2s. c o m*/ PiePlot3D pieplot3d = (PiePlot3D) jfreechart.getPlot(); pieplot3d.setDrawingSupplier(new ChartDrawingSupplier()); pieplot3d.setStartAngle(270D); pieplot3d.setDirection(Rotation.ANTICLOCKWISE); pieplot3d.setForegroundAlpha(0.6F); return jfreechart; }
From source file:userInterface.cdcRole.DecisionChartJPanel.java
private static JFreeChart createChart1(PieDataset piedataset) { JFreeChart jfreechart = ChartFactory.createPieChart3D("Top 5 Hospitals (For Orders Placed)", piedataset, true, false, false);/* w w w .jav a 2s .co m*/ PiePlot3D pieplot3d = (PiePlot3D) jfreechart.getPlot(); pieplot3d.setStartAngle(270D); pieplot3d.setDirection(Rotation.ANTICLOCKWISE); pieplot3d.setForegroundAlpha(0.6F); return jfreechart; }
From source file:org.exist.xquery.modules.jfreechart.JFreeChartFactory.java
private static void setPieSectionLabel(JFreeChart chart, Configuration config) { String pieSectionLabel = config.getPieSectionLabel(); String pieSectionNumberFormat = config.getPieSectionNumberFormat(); String pieSectionPercentFormat = config.getPieSectionPercentFormat(); if (pieSectionLabel != null) { ((PiePlot) chart.getPlot()).setLabelGenerator(new StandardPieSectionLabelGenerator(pieSectionLabel, new DecimalFormat(pieSectionNumberFormat), new DecimalFormat(pieSectionPercentFormat))); }/*from w ww.j a va 2 s.c o m*/ }
From source file:org.opennms.netmgt.charts.ChartUtils.java
private static void setPlotBackgroundColor(BarChart chartConfig, JFreeChart chart) { Red red = chartConfig.getPlotBackgroundColor().getRgb().getRed(); Blue blue = chartConfig.getPlotBackgroundColor().getRgb().getBlue(); Green green = chartConfig.getPlotBackgroundColor().getRgb().getGreen(); chart.getPlot().setBackgroundPaint(new Color(red.getRgbColor(), green.getRgbColor(), blue.getRgbColor())); }