List of usage examples for org.jfree.chart JFreeChart getPlot
public Plot getPlot()
From source file:TimeSeriesChartDemo1.java
/** * Creates a chart.//from ww w .j av a 2 s . c o 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 true, // 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); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawSeriesLineAsPath(true); } DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); return chart; }
From source file:com.ace.capitalflows.ui.frame.chart.NianJdChart.java
/** * Creates a chart.// w ww . jav a 2 s .c om * * @param dataset a dataset. * * @return A chart. */ private static JFreeChart createChart(final XYDataset dataset) { final JFreeChart chart = ChartFactory.createTimeSeriesChart("ZhongGuoGuoJiShouZhiPingHeBiao(NianDuCeSuan)", // title "NianJd", // x-axis label "YiMeiYuan", // y-axis label dataset, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(Color.white); final 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); final XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawSeriesLineAsPath(true); } final DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("yyyy-MM")); return chart; }
From source file:org.exist.xquery.modules.jfreechart.JFreeChartFactory.java
private static void setSectionColors(JFreeChart chart, Configuration config) { String sectionColors = config.getSectionColors(); String sectionColorsDelimiter = config.getSectionColorsDelimiter(); if (sectionColors != null) { PiePlot plot = ((PiePlot) chart.getPlot()); StringTokenizer st = new StringTokenizer(sectionColors, sectionColorsDelimiter); while (st.hasMoreTokens()) { String sectionName = st.nextToken().trim(); String colorName = ""; if (st.hasMoreTokens()) { colorName = st.nextToken().trim(); }/* www . j av a 2 s .c om*/ Color color = null; try { color = Colour.getColor(colorName); } catch (XPathException e) { } if (color != null) { plot.setSectionPaint(sectionName, color); } else { logger.warn("Invalid colour name or hex value specified for SectionColors: " + colorName + ", default colour will be used instead. Section Name: " + sectionName); } } } }
From source file:edu.coeia.charts.LineChartPanel.java
/** * Creates a sample chart.//from w w w. j ava2s. c om * * @param dataset a dataset. * * @return The chart. */ private static JFreeChart createChart(final CategoryDataset dataset) { // create the chart... final JFreeChart chart = ChartFactory.createLineChart("Frequency of Messages", // chart title "Time of Messages", // domain axis label "Number of Messages", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); // customise the range axis... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(true); // customise the renderer... final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 10.0f, 6.0f }, 0.0f)); renderer.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 6.0f, 6.0f }, 0.0f)); renderer.setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 2.0f, 6.0f }, 0.0f)); return chart; }
From source file:org.jfree.chart.demo.AnnotationDemo1.java
private static JFreeChart createChart(XYDataset xydataset) { JFreeChart jfreechart = ChartFactory.createXYLineChart(null, "Age in Months", "Weight (kg)", xydataset, PlotOrientation.VERTICAL, true, true, false); TextTitle texttitle = new TextTitle("Growth Charts: United States", new Font("SansSerif", 1, 14)); TextTitle texttitle1 = new TextTitle("Weight-for-age percentiles: boys, birth to 36 months", new Font("SansSerif", 0, 11)); jfreechart.addSubtitle(texttitle);//from w ww . j a v a 2 s . c o m jfreechart.addSubtitle(texttitle1); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis(); numberaxis.setUpperMargin(0.12D); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); NumberAxis numberaxis1 = (NumberAxis) xyplot.getRangeAxis(); numberaxis1.setAutoRangeIncludesZero(false); XYTextAnnotation xytextannotation = null; Font font = new Font("SansSerif", 0, 9); xytextannotation = new XYTextAnnotation("3rd", 36.5D, 11.76D); xytextannotation.setFont(font); xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT); xyplot.addAnnotation(xytextannotation); xytextannotation = new XYTextAnnotation("5th", 36.5D, 12.039999999999999D); xytextannotation.setFont(font); xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT); xyplot.addAnnotation(xytextannotation); xytextannotation = new XYTextAnnotation("10th", 36.5D, 12.493D); xytextannotation.setFont(font); xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT); xyplot.addAnnotation(xytextannotation); xytextannotation = new XYTextAnnotation("25th", 36.5D, 13.313000000000001D); xytextannotation.setFont(font); xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT); xyplot.addAnnotation(xytextannotation); xytextannotation = new XYTextAnnotation("50th", 36.5D, 14.33D); xytextannotation.setFont(font); xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT); xyplot.addAnnotation(xytextannotation); xytextannotation = new XYTextAnnotation("75th", 36.5D, 15.478D); xytextannotation.setFont(font); xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT); xyplot.addAnnotation(xytextannotation); xytextannotation = new XYTextAnnotation("90th", 36.5D, 16.641999999999999D); xytextannotation.setFont(font); xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT); xyplot.addAnnotation(xytextannotation); xytextannotation = new XYTextAnnotation("95th", 36.5D, 17.408000000000001D); xytextannotation.setFont(font); xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT); xyplot.addAnnotation(xytextannotation); xytextannotation = new XYTextAnnotation("97th", 36.5D, 17.936D); xytextannotation.setFont(font); xytextannotation.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT); xyplot.addAnnotation(xytextannotation); return jfreechart; }
From source file:userInterface.cdcRole.DecisionChartJPanel.java
private static JFreeChart createChart2(PieDataset piedataset) { JFreeChart jfreechart = ChartFactory.createPieChart3D("Top 5 Vaccines", piedataset, true, false, false); PiePlot3D pieplot3d = (PiePlot3D) jfreechart.getPlot(); pieplot3d.setStartAngle(270D);//from w w w . java 2 s .c o m pieplot3d.setDirection(Rotation.ANTICLOCKWISE); pieplot3d.setForegroundAlpha(0.6F); return jfreechart; }
From source file:grafici.StatisticheLineChart.java
/** * Creates a sample chart./*www . j av a2 s .c om*/ * * @param dataset * the dataset. * * @return The chart. */ private static JFreeChart createChart(CategoryDataset dataset, Table results, int variabile, int valore) { // create the chart... JFreeChart chart = ChartFactory.createLineChart(titolo, "", // domain axis label results.getColumn(valore).getText().toUpperCase(), // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); // customise the range axis... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(true); // **************************************************************************** // * JFREECHART DEVELOPER GUIDE * // * The JFreeChart Developer Guide, written by David Gilbert, is available * // * to purchase from Object Refinery Limited: * // * * // * http://www.object-refinery.com/jfreechart/guide.html * // * * // * Sales are used to provide funding for the JFreeChart project - please * // * support us so that we can continue developing free software. * // **************************************************************************** // customise the renderer... final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); // renderer.setDrawShapes(true); renderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 10.0f, 6.0f }, 0.0f)); renderer.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 6.0f, 6.0f }, 0.0f)); renderer.setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 2.0f, 6.0f }, 0.0f)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:sas.BarChart.java
public static JFreeChart createChart(CategoryDataset categorydataset, String name, String type, String t) { JFreeChart jfreechart = ChartFactory.createLineChart(name, null, type, categorydataset, PlotOrientation.VERTICAL, false, true, false); jfreechart.addSubtitle(new TextTitle(t)); TextTitle texttitle = new TextTitle(""); texttitle.setFont(new Font("SansSerif", 0, 10)); texttitle.setPosition(RectangleEdge.BOTTOM); texttitle.setHorizontalAlignment(HorizontalAlignment.CENTER); jfreechart.addSubtitle(texttitle);/* w ww.jav a 2s. c o m*/ CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setRangePannable(true); categoryplot.setRangeGridlinesVisible(false); java.net.URL url = (BarChart.class).getClassLoader().getResource("line_Chart_example.png"); if (url != null) { ImageIcon imageicon = new ImageIcon(url); jfreechart.setBackgroundImage(imageicon.getImage()); categoryplot.setBackgroundPaint(null); } NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); ChartUtilities.applyCurrentTheme(jfreechart); LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer(); lineandshaperenderer.setBaseShapesVisible(true); lineandshaperenderer.setDrawOutlines(true); lineandshaperenderer.setUseFillPaint(true); lineandshaperenderer.setBaseFillPaint(Color.white); lineandshaperenderer.setSeriesStroke(0, new BasicStroke(3F)); lineandshaperenderer.setSeriesOutlineStroke(0, new BasicStroke(2.0F)); lineandshaperenderer.setSeriesShape(0, new java.awt.geom.Ellipse2D.Double(-5D, -5D, 10D, 10D)); return jfreechart; }
From source file:canreg.client.analysis.Tools.java
public static void setPiePlotColours(JFreeChart chart, int numberOfSections, Color baseColor) { Color color = baseColor;/*from ww w.java 2 s . co m*/ PiePlot plot = (PiePlot) chart.getPlot(); for (int i = 0; i < numberOfSections; i++) { try { plot.setSectionOutlinePaint(plot.getDataset().getKey(i), baseColor.darker().darker().darker()); color = darken(color); plot.setSectionPaint(plot.getDataset().getKey(i), color); } catch (java.lang.IndexOutOfBoundsException ex) { // not data for all the categories - that is fine Logger.getLogger(TopNChartTableBuilder.class.getName()).log(Level.INFO, null, ex); } } }
From source file:msec.org.Tools.java
public static String generateFullDayChart(String filename, OneDayValue[] data, String title) { if (data[0].getValues().length != 1440) { return "data size invalid"; }// www . j a v a 2s . co m if (data.length > 1) { if (data[1].getValues() == null || data[1].getValues().length != 1440) { return "data 1 invalid"; } } XYDataset xydataset = createDataset(data); 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("HH:mm")); dateaxis.setLabelFont(new Font("", Font.PLAIN, 16)); // dateaxis.setLabelPaint(ChartColor.gray); dateaxis.setTickLabelFont(new Font("", Font.PLAIN, 16)); dateaxis.setTickLabelPaint(ChartColor.GRAY); GregorianCalendar endgc = (GregorianCalendar) gc.clone(); endgc.add(GregorianCalendar.DATE, 1); dateaxis.setMaximumDate(endgc.getTime()); dateaxis.setTickMarksVisible(true); dateaxis.setTickMarkInsideLength(5); dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 2)); 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(); } }