List of usage examples for org.jfree.chart JFreeChart getPlot
public Plot getPlot()
From source file:org.physionet.wfdb.examples.PlotECGQRSDemo2.java
private static JFreeChart createChart(XYDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createXYLineChart("Plot ECG Demo1 ", // chart title "Time (seconds)", // x axis label "mV", // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls );/*from ww w. j a v a 2 s . c o m*/ XYPlot plot = (XYPlot) chart.getPlot(); plot.getDomainAxis().setLowerMargin(0.0); plot.getDomainAxis().setUpperMargin(0.0); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesShapesFilled(1, true); } return chart; }
From source file:org.jfree.chart.demo.ThumbnailDemo1.java
private static JFreeChart createChart2(PieDataset piedataset) { JFreeChart jfreechart = ChartFactory.createPieChart3D("Pie Chart 3D Demo 1", piedataset, true, true, false); jfreechart.setBackgroundPaint(Color.white); PiePlot3D pieplot3d = (PiePlot3D) jfreechart.getPlot(); pieplot3d.setDarkerSides(true);// ww w . j ava 2s. co m pieplot3d.setStartAngle(290D); pieplot3d.setDirection(Rotation.CLOCKWISE); pieplot3d.setForegroundAlpha(0.5F); pieplot3d.setOutlinePaint(null); pieplot3d.setNoDataMessage("No data to display"); return jfreechart; }
From source file:org.exist.xquery.modules.jfreechart.JFreeChartFactory.java
private static void setSeriesColors(JFreeChart chart, Configuration config) { String seriesColors = config.getSeriesColors(); if (chart.getPlot() instanceof SpiderWebPlot) { setSeriesColors((SpiderWebPlot) chart.getPlot(), seriesColors); } else {//from ww w . ja v a 2 s.c o m CategoryItemRenderer renderer = ((CategoryPlot) chart.getPlot()).getRenderer(); setSeriesColors(renderer, seriesColors); } }
From source file:userInterface.cdcRole.OverviewJPanel.java
private static JFreeChart createChart1(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createBarChart("Distribution of Vaccines", "Vaccine", "Quantity", categorydataset, PlotOrientation.VERTICAL, true, true, false); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setDomainGridlinesVisible(true); categoryplot.setRangeCrosshairVisible(true); categoryplot.setRangeCrosshairPaint(Color.green); 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.green, 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:utils.Graphs.java
public static File generate(File baseFolder, String titles[], int[] values, Color backgroundColor) { DefaultPieDataset dataset = new DefaultPieDataset(); // add our data values int i = -1;/*from www .jav a 2s . c om*/ for (String title : titles) { i++; dataset.setValue(title, values[i]); } final JFreeChart chart = // ChartFactory.createPieChart("", dataset, true, true, false); ChartFactory.createPieChart("", // chart title dataset, // data true, // include legend true, false); PiePlot plot = (PiePlot) chart.getPlot(); //PiePlot3D plot = (PiePlot3D) chart.getPlot(); //plot.setStartAngle(290); plot.setStartAngle(45); plot.setDirection(Rotation.CLOCKWISE); plot.setForegroundAlpha(0.5f); // final PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(backgroundColor); // plot.setLegendLabelGenerator( // new StandardPieSectionLabelGenerator("{0} {2}")); chart.setBorderVisible(false); chart.getPlot().setOutlineVisible(false); chart.getLegend().setFrame(BlockBorder.NONE); // get the same background chart.setBackgroundPaint(backgroundColor); chart.getLegend().setBackgroundPaint(backgroundColor); // hide the shadow effects plot.setShadowXOffset(0); plot.setShadowYOffset(0); //chart.getLegend().setVisible(false); plot.setCircular(true); //plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {2}", NumberFormat.getNumberInstance(), NumberFormat plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{2}", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance())); plot.setNoDataMessage("No data found."); Color greenColor = new Color(0x8FBC0C); Color redColor = new Color(0xFF0000); //Color redColor = new Color(0xDA6022); plot.setSectionPaint(0, greenColor); plot.setSectionPaint(1, redColor); plot.setSectionOutlinesVisible(true); final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file = new File(baseFolder, "chart.png"); try { ChartUtilities.saveChartAsPNG(file, chart, 200, 160, info); } catch (IOException ex) { Logger.getLogger(Graphs.class.getName()).log(Level.SEVERE, null, ex); } // //// final ChartPanel chartPanel = new ChartPanel(chart, true); // final ChartPanel chartPanel = new ChartPanel(chart, true); // chartPanel.setMinimumDrawWidth(0); // chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE); // chartPanel.setMinimumDrawHeight(0); // chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE); // JDialog dialog = new JDialog(); // dialog.add(chartPanel); // dialog.setLayout(new GridLayout(1, 1)); // dialog.setSize(400, 200); // dialog.setVisible(true); return file; }
From source file:net.sf.jsfcomp.chartcreator.utils.ChartUtils.java
public static void setGeneralChartProperties(JFreeChart chart, ChartData chartData) { chart.setBackgroundPaint(ChartUtils.getColor(chartData.getBackground())); chart.getPlot().setBackgroundPaint(ChartUtils.getColor(chartData.getForeground())); chart.setTitle(chartData.getTitle()); chart.setAntiAlias(chartData.isAntialias()); // Alpha transparency (100% means opaque) if (chartData.getAlpha() < 100) { chart.getPlot().setForegroundAlpha((float) chartData.getAlpha() / 100); }/*from w w w .j ava 2 s. co m*/ }
From source file:org.fhaes.fhsamplesize.view.SSIZCurveChart.java
/** * Create the chart./* ww w . j a v a 2 s . c om*/ * * @param eventsPerCenturyDataset * @return */ private static JFreeChart createChart(final XYDataset eventsPerCenturyDataset, Integer xcross, Integer ycross) { // JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(null, "Number of series resampled", "Number of events", // eventsPerCenturyDataset, true, true, false); JFreeChart jfreechart = ChartFactory.createScatterPlot(null, "Number of series resampled", "Number of events per century", eventsPerCenturyDataset); jfreechart.setBackgroundPaint(Color.WHITE); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setInsets(new RectangleInsets(5D, 5D, 5D, 20D)); xyplot.setBackgroundPaint(Color.WHITE); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); // xyplot.setDomainGridlinePaint(Color.white); // xyplot.setRangeGridlinePaint(Color.white); DeviationRenderer deviationrenderer = new DeviationRenderer(true, false); deviationrenderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1)); deviationrenderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1)); deviationrenderer.setSeriesStroke(1, new BasicStroke(3F, 1, 1)); deviationrenderer.setSeriesFillPaint(0, new Color(255, 200, 200)); deviationrenderer.setSeriesFillPaint(1, new Color(200, 200, 255)); xyplot.setRenderer(deviationrenderer); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); jfreechart.removeLegend(); if (xcross != null && ycross != null) { XYPlot xyp = jfreechart.getXYPlot(); xyp.setRangeCrosshairVisible(true); xyp.setRangeCrosshairValue(ycross, true); xyp.setRangeCrosshairLockedOnData(true); xyp.setDomainCrosshairVisible(true); xyp.setDomainCrosshairValue(xcross, true); xyp.setDomainCrosshairLockedOnData(true); } // Initialize the chart variable for later use chart = jfreechart; return jfreechart; }
From source file:unalcol.termites.boxplots.HybridGlobalInfoReport.java
private static void createChart(Hashtable<String, XYSeriesCollection> dataCollected) { System.out.println("dc" + dataCollected); for (String key : dataCollected.keySet()) { JFreeChart chart = ChartFactory.createXYLineChart(key, "Round number", "GlobalInfo", dataCollected.get(key), PlotOrientation.VERTICAL, true, true, false); XYPlot xyPlot = (XYPlot) chart.getPlot(); NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis(); domain.setRange(0.0, 10000.0);/*from w ww .j a v a 2 s . c o m*/ FileOutputStream output; try { System.out.println("Key: " + key); output = new FileOutputStream(key + mazeMode + ".jpg"); ChartUtilities.writeChartAsJPEG(output, 1.0f, chart, 400, 400, null); } catch (FileNotFoundException ex) { Logger.getLogger(ECALAgentsRight.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ECALAgentsRight.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.che.software.testato.util.jfreechart.LineChartGraphistUtil.java
/** * Colorized and transforms a given JFreeChart. * /*from w ww . j a v a 2s . co m*/ * @author Clement HELIOU (clement.heliou@che-software.com). * @param lineChart the given chart. * @param maxAbscissaValue the max abscissa value of the chart. * @param xValues the x axis values list. * @param yValues the y axis values list. * @param xExcludedValues the x axis excluded values. * @param yExcludedValues the y axis excluded values. * @return the transformed chart. * @since August, 2011. */ public static JFreeChart getColorizedChartFromChart(JFreeChart lineChart, double maxAbscissaValue, List<MatrixResult> xValues, List<MatrixResult> yValues, List<MatrixResult> xExcludedValues, List<MatrixResult> yExcludedValues) { LOGGER.debug("getColorizedChartFromChart()."); lineChart.setBackgroundPaint(Color.WHITE); XYPlot plot = (XYPlot) lineChart.getPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesStroke(2, new BasicStroke(2)); renderer.setSeriesStroke(3, new BasicStroke(2)); renderer.setSeriesShapesVisible(2, false); renderer.setSeriesShapesVisible(3, false); renderer.setSeriesPaint(0, ColorUtil.getHSBColor(ColorUtil.BLUE_COLOR[0], ColorUtil.BLUE_COLOR[1], ColorUtil.BLUE_COLOR[2])); renderer.setSeriesPaint(1, ColorUtil.getHSBColor(ColorUtil.ORANGE_COLOR[0], ColorUtil.ORANGE_COLOR[1], ColorUtil.ORANGE_COLOR[2])); renderer.setSeriesPaint(2, ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1], ColorUtil.DARK_BLUE_COLOR[2])); renderer.setSeriesPaint(3, ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1], ColorUtil.DARK_BLUE_COLOR[2])); plot.setRenderer(renderer); XYTextAnnotation low = new XYTextAnnotation( LocaleUtil.getResourceBundleStringByName(LocaleUtil.AREA_LOW_NAME), (0.5 * maxAbscissaValue) - 1, maxAbscissaValue + 1), medium = new XYTextAnnotation(LocaleUtil.getResourceBundleStringByName(LocaleUtil.AREA_MEDIUM_NAME), (1.5 * maxAbscissaValue) - 2, maxAbscissaValue + 1), high = new XYTextAnnotation(LocaleUtil.getResourceBundleStringByName(LocaleUtil.AREA_HIGH_NAME), 1.5 * maxAbscissaValue, maxAbscissaValue - 2); low.setFont(ColorUtil.TITLE_FONT); medium.setFont(ColorUtil.TITLE_FONT); high.setFont(ColorUtil.TITLE_FONT); low.setPaint(ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1], ColorUtil.DARK_BLUE_COLOR[2])); medium.setPaint(ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1], ColorUtil.DARK_BLUE_COLOR[2])); high.setPaint(ColorUtil.getHSBColor(ColorUtil.DARK_BLUE_COLOR[0], ColorUtil.DARK_BLUE_COLOR[1], ColorUtil.DARK_BLUE_COLOR[2])); plot.addAnnotation(low); plot.addAnnotation(medium); plot.addAnnotation(high); for (int i = 0; i < xValues.size(); i++) { XYTextAnnotation itemLabel = new XYTextAnnotation(xValues.get(i).getScriptLabel(), (yValues.get(i).getPercentage() * 100), (xValues.get(i).getPercentage() * 100) + 0.5); itemLabel.setFont(ColorUtil.DEFAULT_FONT); itemLabel.setPaint(ColorUtil.getHSBColor(ColorUtil.BLUE_COLOR[0], ColorUtil.BLUE_COLOR[1], ColorUtil.BLUE_COLOR[2])); plot.addAnnotation(itemLabel); } if (null != xExcludedValues) { for (int j = 0; j < xExcludedValues.size(); j++) { XYTextAnnotation itemLabel = new XYTextAnnotation(xExcludedValues.get(j).getScriptLabel(), (yExcludedValues.get(j).getPercentage() * 100), (xExcludedValues.get(j).getPercentage() * 100) + 0.5); itemLabel.setFont(ColorUtil.DEFAULT_FONT); itemLabel.setPaint(ColorUtil.getHSBColor(ColorUtil.ORANGE_COLOR[0], ColorUtil.ORANGE_COLOR[1], ColorUtil.ORANGE_COLOR[2])); plot.addAnnotation(itemLabel); } } return lineChart; }
From source file:com.imaging100x.tracker.TrackerUtils.java
/** * Create a frame with a plot of the data given in XYSeries */// ww w. j a v a 2s. c o m public static void plotData(String title, final XYSeries data, String xTitle, String yTitle, int xLocation, int yLocation) { // JFreeChart code XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(data); JFreeChart chart = ChartFactory.createScatterPlot(title, // Title xTitle, // x-axis Label yTitle, // y-axis Label dataset, // Dataset PlotOrientation.VERTICAL, // Plot Orientation false, // Show Legend true, // Use tooltips false // Configure chart to generate URLs? ); final XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setSeriesPaint(0, Color.black); renderer.setSeriesFillPaint(0, Color.white); renderer.setSeriesLinesVisible(0, true); Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 4.0f, 4.0f); renderer.setSeriesShape(0, circle, false); renderer.setUseFillPaint(true); ChartFrame graphFrame = new ChartFrame(title, chart); graphFrame.getChartPanel().setMouseWheelEnabled(true); graphFrame.setPreferredSize(new Dimension(SIZE, SIZE)); graphFrame.setResizable(true); graphFrame.pack(); graphFrame.setLocation(xLocation, yLocation); graphFrame.setVisible(true); dataset.addChangeListener(new DatasetChangeListener() { public void datasetChanged(DatasetChangeEvent dce) { double xRange = data.getMaxX() - data.getMinX(); double yRange = data.getMaxY() - data.getMinY(); double xAvg = (data.getMaxX() + data.getMinX()) / 2; double yAvg = (data.getMaxY() + data.getMinY()) / 2; double range = xRange; if (yRange > range) { range = yRange; } double offset = 0.55 * range; plot.getDomainAxis().setRange(xAvg - offset, xAvg + offset); plot.getRangeAxis().setRange(yAvg - offset, yAvg + offset); } }); }