List of usage examples for org.jfree.chart JFreeChart getPlot
public Plot getPlot()
From source file:org.encog.workbench.dialogs.activation.EquationPanel.java
/** * Creates a line chart using the data from the supplied dataset. * * @param dataset the dataset./*w w w . j av a2 s.c o m*/ * * @return The chart. */ public static JFreeChart createChart(XYDataset dataset, ActivationFunction activation, boolean normal) { String title; if (normal) { title = activation.getClass().getSimpleName(); } else { if (activation.hasDerivative()) { title = "Derv of " + activation.getClass().getSimpleName(); } else { title = "NO Derv of " + activation.getClass().getSimpleName(); } } JFreeChart chart = ChartFactory.createXYLineChart(title, "input (x)", "output (y)", dataset, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); if (normal) { plot.setDomainZeroBaselineVisible(true); plot.setRangeZeroBaselineVisible(true); plot.setDomainPannable(true); plot.setRangePannable(true); ValueAxis xAxis = plot.getDomainAxis(); xAxis.setLowerMargin(0.0); xAxis.setUpperMargin(0.0); XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer(); r.setDrawSeriesLineAsPath(true); r.setSeriesStroke(0, new BasicStroke(1.5f)); r.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 6.0f, 4.0f }, 0.0f)); r.setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 6.0f, 4.0f, 3.0f, 3.0f }, 0.0f)); r.setSeriesStroke(3, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 4.0f, 4.0f }, 0.0f)); } return chart; }
From source file:org.jfree.chart.demo.ItemLabelDemo5.java
private static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createStackedBarChart("Item Label Demo 5", null, null, categorydataset, PlotOrientation.VERTICAL, false, true, false); jfreechart.setBackgroundPaint(new Color(255, 255, 255)); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); MyStackedBarRenderer mystackedbarrenderer = new MyStackedBarRenderer(); categoryplot.setRenderer(mystackedbarrenderer); ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 0.0D);//from w w w . ja va 2 s . c o m mystackedbarrenderer.setPositiveItemLabelPositionFallback(itemlabelposition); mystackedbarrenderer.setNegativeItemLabelPositionFallback(itemlabelposition); StandardCategoryItemLabelGenerator standardcategoryitemlabelgenerator = new StandardCategoryItemLabelGenerator( "{0}", NumberFormat.getInstance()); mystackedbarrenderer.setBaseItemLabelGenerator(standardcategoryitemlabelgenerator); mystackedbarrenderer.setBaseItemLabelsVisible(true); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setUpperBound(100D); return jfreechart; }
From source file:org.jfree.expdemo.SelectionDemo4.java
/** * Creates a chart.//w ww. j a va2 s . c o m * * @param dataset * a dataset. * * @return The chart. */ private static JFreeChart createChart(IntervalXYDataset dataset, DatasetSelectionExtension ext) { JFreeChart chart = ChartFactory.createHistogram("SelectionDemo4", null, null, dataset, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainPannable(true); plot.setRangePannable(true); plot.setForegroundAlpha(0.85f); NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(true); renderer.setBaseOutlinePaint(Color.red); renderer.setBarPainter(new StandardXYBarPainter()); renderer.setShadowVisible(false); //add selection specific rendering IRSUtilities.setSelectedItemPaint(renderer, ext, Color.white); //register plot as selection change listener ext.addSelectionChangeListener(plot); return chart; }
From source file:org.pau.assetmanager.viewmodel.chart.PrepareChart.java
public static void prepareJFreeBarChartForStocks(JFreeChart jfchart, CategoryDataset categoryModel) { CategoryPlot categoryPlot = ((CategoryPlot) jfchart.getPlot()); categoryPlot.getRangeAxis().resizeRange(1.2); categoryPlot.setBackgroundPaint(Color.WHITE); categoryPlot.setDomainGridlinePaint(Color.WHITE); categoryPlot.setRangeMinorGridlinePaint(Color.WHITE); categoryPlot.setRangeGridlinePaint(Color.BLACK); BarRenderer renderer = (BarRenderer) categoryPlot.getRenderer(); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2} {1} ", NumberFomatter.PERCENTAGE_FORMATTER, NumberFormat.getPercentInstance())); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelFont(new Font("Serif", Font.PLAIN, 12)); renderer.setItemLabelAnchorOffset(15); renderer.setDrawBarOutline(false);//w w w . j a v a 2 s . c o m renderer.setShadowVisible(false); renderer.setItemMargin(.1); renderer.setBarPainter(new StandardBarPainter()); }
From source file:jprobix.ui.SPlotFinal.java
public static JPanel creteDemoPanel() { JFreeChart jfreechart = ChartFactory.createScatterPlot("Scatter plot demo", "X", "Y", samplexydataset2(), PlotOrientation.VERTICAL, true, true, false); Shape cross = ShapeUtilities.createDiagonalCross(3, 2); XYPlot xyPlot = (XYPlot) jfreechart.getPlot(); xyPlot.setDomainCrosshairVisible(true); xyPlot.setRangeCrosshairVisible(true); XYItemRenderer renderer = xyPlot.getRenderer(); renderer.setSeriesShape(5, cross);// w w w . j a v a 2 s . c om renderer.setSeriesPaint(0, Color.YELLOW); XYDotRenderer xydotrenderer = new XYDotRenderer(); xyPlot.setRenderer(xydotrenderer); xydotrenderer.setSeriesShape(0, cross); xyPlot.setDomainCrosshairVisible(true); xyPlot.setRangeCrosshairVisible(true); return new ChartPanel(jfreechart); }
From source file:org.jfree.chart.demo.WaterfallChartDemo1.java
private static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createWaterfallChart("Product Cost Breakdown", "Expense Category", "Cost Per Unit", categorydataset, PlotOrientation.VERTICAL, false, true, false); jfreechart.setBackgroundPaint(Color.white); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.lightGray); categoryplot.setRangeGridlinePaint(Color.white); categoryplot.setRangeGridlinesVisible(true); categoryplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); ValueAxis valueaxis = categoryplot.getRangeAxis(); DecimalFormat decimalformat = new DecimalFormat("##,###"); decimalformat.setNegativePrefix("("); decimalformat.setNegativeSuffix(")"); TickUnits tickunits = new TickUnits(); tickunits.add(new NumberTickUnit(5D, decimalformat)); tickunits.add(new NumberTickUnit(10D, decimalformat)); tickunits.add(new NumberTickUnit(20D, decimalformat)); tickunits.add(new NumberTickUnit(50D, decimalformat)); tickunits.add(new NumberTickUnit(100D, decimalformat)); tickunits.add(new NumberTickUnit(200D, decimalformat)); tickunits.add(new NumberTickUnit(500D, decimalformat)); tickunits.add(new NumberTickUnit(1000D, decimalformat)); tickunits.add(new NumberTickUnit(2000D, decimalformat)); tickunits.add(new NumberTickUnit(5000D, decimalformat)); valueaxis.setStandardTickUnits(tickunits); BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setDrawBarOutline(false); barrenderer.setBase(5D);/* w w w.ja va 2s . co m*/ DecimalFormat decimalformat1 = new DecimalFormat("$##,###.00"); decimalformat1.setNegativePrefix("("); decimalformat1.setNegativeSuffix(")"); barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", decimalformat1)); barrenderer.setBaseItemLabelsVisible(true); return jfreechart; }
From source file:org.radargun.reporting.BarPlotGenerator.java
/** * @param operation Name of the plotted operation * @param ranges ranges[0] = min, ranges[ranges.length - 1] = max * @param counts counts[i] is number of entries with value >= ranges[i - 1] and < ranges[i] * @param reportDir//ww w . j a v a 2 s . co m * @param filename * @throws IOException */ public static void generate(String operation, long[] ranges, long[] counts, String reportDir, String filename) throws IOException { XYSeries series = new XYSeries(operation + " response times"); long totalCount = 0; for (long count : counts) { totalCount += count; } double left = Math.log10(ranges[0]); double right = Math.log10(ranges[ranges.length - 1]); for (int i = 0; i < counts.length; i++) { series.add(Math.log10(ranges[i]), (double) counts[i] / totalCount); } series.add(right, 0d); XYDataset dataset = new XYSeriesCollection(series); JFreeChart chart = ChartFactory.createXYStepAreaChart(operation + " response time histogram", "Response time", "Percentage", dataset, PlotOrientation.VERTICAL, false, false, false); XYPlot plot = (XYPlot) chart.getPlot(); NumberAxis d = (NumberAxis) plot.getDomainAxis(); d.setRange(left, right); d.setStandardTickUnits(new HistoTickUnitSource()); plot.setDomainAxis(d); FileOutputStream output = new FileOutputStream(new File(reportDir + File.separator + filename)); ChartUtilities.writeChartAsPNG(output, chart, 1024, 768); output.close(); }
From source file:org.jfree.chart.demo.PriceVolumeDemo2.java
private static JFreeChart createChart() { OHLCDataset ohlcdataset = createPriceDataset(); String s = "Sun Microsystems (SUNW)"; JFreeChart jfreechart = ChartFactory.createHighLowChart(s, "Date", "Price", ohlcdataset, true); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setLowerMargin(0.01D);/*from w ww . j a v a 2s . c o m*/ dateaxis.setUpperMargin(0.01D); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setLowerMargin(0.59999999999999998D); numberaxis.setAutoRangeIncludesZero(false); XYItemRenderer xyitemrenderer = xyplot.getRenderer(); xyitemrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})", new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); NumberAxis numberaxis1 = new NumberAxis("Volume"); numberaxis1.setUpperMargin(1.0D); xyplot.setRangeAxis(1, numberaxis1); xyplot.setDataset(1, createVolumeDataset()); xyplot.setRangeAxis(1, numberaxis1); xyplot.mapDatasetToRangeAxis(1, 1); XYBarRenderer xybarrenderer = new XYBarRenderer(); xybarrenderer.setDrawBarOutline(false); xybarrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})", new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0,000.00"))); xyplot.setRenderer(1, xybarrenderer); ChartUtilities.applyCurrentTheme(jfreechart); xybarrenderer.setShadowVisible(false); xybarrenderer.setBarPainter(new StandardXYBarPainter()); return jfreechart; }
From source file:org.jfree.graphics2d.demo.CanvasBarChartDemo1.java
/** * Creates a sample chart./*from w w w . j a v a 2 s . com*/ * * @param dataset a dataset. * * @return The chart. */ private static JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createLineChart("Statistical Bar Chart Demo 1", // chart title "Type", // domain axis label "Value", // range axis label dataset); CategoryPlot plot = (CategoryPlot) chart.getPlot(); // customise the range axis... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(false); // customise the renderer... StatisticalBarRenderer renderer = new StatisticalBarRenderer(); renderer.setDrawBarOutline(false); renderer.setErrorIndicatorPaint(Color.black); renderer.setIncludeBaseInRange(false); plot.setRenderer(renderer); // ensure the current theme is applied to the renderer just added ChartUtilities.applyCurrentTheme(chart); renderer.setDefaultItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setDefaultItemLabelsVisible(true); renderer.setDefaultItemLabelPaint(Color.yellow); renderer.setDefaultPositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.INSIDE6, TextAnchor.BOTTOM_CENTER)); // set up gradient paints for series... GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); return chart; }
From source file:org.matsim.contrib.dvrp.util.chart.RouteChartUtils.java
public static JFreeChart chartRoutes(List<? extends Vehicle> vehicles) { CoordDataset lData = new CoordDataset(); for (int i = 0; i < vehicles.size(); i++) { Schedule<?> schedule = vehicles.get(i).getSchedule(); lData.addSeries(Integer.toString(i), LinkSources.createLinkSource(schedule)); }//from w w w .j a v a 2 s . c o m JFreeChart chart = ChartFactory.createXYLineChart("Routes", "X", "Y", lData, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRangeGridlinesVisible(false); plot.setDomainGridlinesVisible(false); plot.setBackgroundPaint(Color.white); NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setAutoRangeIncludesZero(false); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesShapesVisible(0, true); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesItemLabelsVisible(0, true); renderer.setBaseItemLabelGenerator(new XYItemLabelGenerator() { public String generateLabel(XYDataset dataset, int series, int item) { return ((CoordDataset) dataset).getText(series, item); } }); for (int i = 1; i <= vehicles.size(); i++) { renderer.setSeriesShapesVisible(i, true); renderer.setSeriesLinesVisible(i, true); renderer.setSeriesItemLabelsVisible(i, true); } return chart; }