Java Code Examples for org.jfree.chart.JFreeChart#getPlot()
The following examples show how to use
org.jfree.chart.JFreeChart#getPlot() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XYPlotTest.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
/** * A test to reproduce a bug in serialization: the domain and/or range * markers for a plot are not being serialized. */ @Test public void testSerialization4() { XYSeriesCollection dataset = new XYSeriesCollection(); JFreeChart chart = ChartFactory.createXYLineChart("Test Chart", "Domain Axis", "Range Axis", dataset); XYPlot plot = (XYPlot) chart.getPlot(); plot.addDomainMarker(new ValueMarker(1.0), Layer.FOREGROUND); plot.addDomainMarker(new IntervalMarker(2.0, 3.0), Layer.BACKGROUND); plot.addRangeMarker(new ValueMarker(4.0), Layer.FOREGROUND); plot.addRangeMarker(new IntervalMarker(5.0, 6.0), Layer.BACKGROUND); JFreeChart chart2 = (JFreeChart) TestUtilities.serialised(chart); assertEquals(chart, chart2); try { chart2.createBufferedImage(300, 200); } catch (Exception e) { fail("No exception should be thrown."); } }
Example 2
Source File: LogAxisTests.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Checks that the auto-range for the range axis on an XYPlot is * working as expected. */ public void testXYAutoRange2() { XYSeries series = new XYSeries("Series 1"); series.add(1.0, 1.0); series.add(2.0, 2.0); series.add(3.0, 3.0); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); JFreeChart chart = ChartFactory.createScatterPlot("Test", "X", "Y", dataset, false); XYPlot plot = (XYPlot) chart.getPlot(); LogAxis axis = new LogAxis("Log(Y)"); plot.setRangeAxis(axis); assertEquals(0.9465508226401592, axis.getLowerBound(), EPSILON); assertEquals(3.1694019256486126, axis.getUpperBound(), EPSILON); }
Example 3
Source File: StandardXYItemRendererTests.java From astor with GNU General Public License v2.0 | 6 votes |
/** * A check to ensure that an item that falls outside the plot's data area * does NOT generate an item entity. */ public void testNoDisplayedItem() { XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries s1 = new XYSeries("S1"); s1.add(10.0, 10.0); dataset.addSeries(s1); JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y", dataset, PlotOrientation.VERTICAL, false, true, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRenderer(new StandardXYItemRenderer()); NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); xAxis.setRange(0.0, 5.0); NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setRange(0.0, 5.0); BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); ChartRenderingInfo info = new ChartRenderingInfo(); chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, info); g2.dispose(); EntityCollection ec = info.getEntityCollection(); assertFalse(TestUtilities.containsInstanceOf(ec.getEntities(), XYItemEntity.class)); }
Example 4
Source File: XYPlotTest.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
/** * A test for drawing range grid lines when there is no primary renderer. * In 1.0.4, this is throwing a NullPointerException. */ @Test public void testDrawRangeGridlines() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y", dataset, PlotOrientation.VERTICAL, true, false, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRenderer(null); try { BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); } catch (Exception e) { fail("No exception should be thrown."); } }
Example 5
Source File: LogAxisTest.java From openstock with GNU General Public License v3.0 | 6 votes |
/** * Checks that the auto-range for the domain axis on an XYPlot is * working as expected. */ @Test public void testXYAutoRange1() { XYSeries series = new XYSeries("Series 1"); series.add(1.0, 1.0); series.add(2.0, 2.0); series.add(3.0, 3.0); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); JFreeChart chart = ChartFactory.createScatterPlot("Test", "X", "Y", dataset); XYPlot plot = (XYPlot) chart.getPlot(); LogAxis axis = new LogAxis("Log(Y)"); plot.setRangeAxis(axis); assertEquals(0.9465508226401592, axis.getLowerBound(), EPSILON); assertEquals(3.1694019256486126, axis.getUpperBound(), EPSILON); }
Example 6
Source File: CategoryPlotTest.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
/** * This test ensures that a plot with markers is serialized correctly. */ @Test public void testSerialization4() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); JFreeChart chart = ChartFactory.createBarChart( "Test Chart", "Category Axis", "Value Axis", dataset, PlotOrientation.VERTICAL, true, true, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.addRangeMarker(new ValueMarker(1.1), Layer.FOREGROUND); plot.addRangeMarker(new IntervalMarker(2.2, 3.3), Layer.BACKGROUND); JFreeChart chart2 = (JFreeChart) TestUtilities.serialised(chart); assertEquals(chart, chart2); // now check that the chart is usable... try { chart2.createBufferedImage(300, 200); } catch (Exception e) { fail("No exception should be thrown."); } }
Example 7
Source File: NominalAttributeStatisticsModel.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
/** * Creates the histogram chart. * * @return */ private JFreeChart createBarChart() { JFreeChart chart = ChartFactory.createBarChart(null, null, null, createBarDataset(), PlotOrientation.VERTICAL, false, false, false); AbstractAttributeStatisticsModel.setDefaultChartFonts(chart); chart.setBackgroundPaint(null); chart.setBackgroundImageAlpha(0.0f); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setRangeGridlinesVisible(false); plot.setDomainGridlinesVisible(false); plot.setOutlineVisible(false); plot.setRangeZeroBaselineVisible(false); plot.setDomainGridlinesVisible(false); plot.setBackgroundPaint(COLOR_INVISIBLE); plot.setBackgroundImageAlpha(0.0f); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, AttributeGuiTools.getColorForValueType(Ontology.NOMINAL)); renderer.setBarPainter(new StandardBarPainter()); renderer.setDrawBarOutline(true); renderer.setShadowVisible(false); return chart; }
Example 8
Source File: StackedXYBarRendererTest.java From openstock with GNU General Public License v3.0 | 6 votes |
/** * Check that the renderer is calculating the domain bounds correctly. */ @Test public void testFindDomainBounds() { TableXYDataset dataset = RendererXYPackageUtils.createTestTableXYDataset(); JFreeChart chart = ChartFactory.createStackedXYAreaChart( "Test Chart", "X", "Y", dataset, PlotOrientation.VERTICAL, false, false, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRenderer(new StackedXYBarRenderer()); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRangeIncludesZero(false); Range bounds = domainAxis.getRange(); assertFalse(bounds.contains(0.3)); assertTrue(bounds.contains(0.5)); assertTrue(bounds.contains(2.5)); assertFalse(bounds.contains(2.8)); }
Example 9
Source File: Arja_00174_t.java From coming with MIT License | 5 votes |
/** * Sets the chart that is used to draw the individual pie plots. The * chart's plot must be an instance of {@link PiePlot}. * * @param pieChart the pie chart (<code>null</code> not permitted). * * @see #getPieChart() */ public void setPieChart(JFreeChart pieChart) { if (pieChart == null) { throw new IllegalArgumentException("Null 'pieChart' argument."); } if (!(pieChart.getPlot() instanceof PiePlot)) { throw new IllegalArgumentException("The 'pieChart' argument must " + "be a chart based on a PiePlot."); } this.pieChart = pieChart; fireChangeEvent(); }
Example 10
Source File: MemInfo.java From AndroidRobot with Apache License 2.0 | 5 votes |
private JFreeChart createChart(XYDataset xydataset) { JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("", "", "", xydataset, true, true, false); Plot plot = (Plot) jfreechart.getPlot(); xyplot = jfreechart.getXYPlot(); // 纵坐标设定 valueaxis = xyplot.getDomainAxis(); valueaxis.setAutoRange(true); valueaxis.setFixedAutoRange(60000D); valueaxis = xyplot.getRangeAxis(); valueaxis.setRange(0.0D, 1048576D); plot.setBackgroundPaint(Color.black); return jfreechart; }
Example 11
Source File: XYLineAndShapeRendererTests.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Check that the renderer is calculating the range bounds correctly. */ public void testFindRangeBounds() { TableXYDataset dataset = RendererXYPackageTests.createTestTableXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("Test Chart", "X", "Y", dataset, false); XYPlot plot = (XYPlot) chart.getPlot(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRangeIncludesZero(false); Range bounds = rangeAxis.getRange(); assertFalse(bounds.contains(1.0)); assertTrue(bounds.contains(2.0)); assertTrue(bounds.contains(5.0)); assertFalse(bounds.contains(6.0)); }
Example 12
Source File: StackedXYAreaRendererTest.java From SIMVA-SoS with Apache License 2.0 | 5 votes |
/** * Check that the renderer is calculating the range bounds correctly. */ @Test public void testFindRangeBounds() { TableXYDataset dataset = RendererXYPackageUtils.createTestTableXYDataset(); JFreeChart chart = ChartFactory.createStackedXYAreaChart( "Test Chart", "X", "Y", dataset, PlotOrientation.VERTICAL, false, false, false); XYPlot plot = (XYPlot) chart.getPlot(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); Range bounds = rangeAxis.getRange(); assertTrue(bounds.contains(6.0)); assertTrue(bounds.contains(8.0)); }
Example 13
Source File: NumberAxisTests.java From astor with GNU General Public License v2.0 | 5 votes |
/** * A simple test for the auto-range calculation looking at a * NumberAxis used as the range axis for a CategoryPlot. */ public void testAutoRange1() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(100.0, "Row 1", "Column 1"); dataset.setValue(200.0, "Row 1", "Column 2"); JFreeChart chart = ChartFactory.createBarChart("Test", "Categories", "Value", dataset, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); NumberAxis axis = (NumberAxis) plot.getRangeAxis(); assertEquals(axis.getLowerBound(), 0.0, EPSILON); assertEquals(axis.getUpperBound(), 210.0, EPSILON); }
Example 14
Source File: Chart.java From crypto-bot with Apache License 2.0 | 5 votes |
public void showChart() { /** * Building chart datasets */ TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries( buildChartTimeSeries(timeSeries, new ClosePriceIndicator(timeSeries), symbol)); dataset.addSeries( buildChartTimeSeries(timeSeries, new EMAIndicator(new ClosePriceIndicator(timeSeries), 5), "EMA5")); dataset.addSeries( buildChartTimeSeries(timeSeries, new EMAIndicator(new ClosePriceIndicator(timeSeries), 10), "EMA10")); dataset.addSeries( buildChartTimeSeries(timeSeries, new EMAIndicator(new ClosePriceIndicator(timeSeries), 40), "EMA40")); /** * Creating the chart */ JFreeChart chart = ChartFactory.createTimeSeriesChart("BTC", // title "Date", // x-axis label "Price", // y-axis label dataset, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); XYPlot plot = (XYPlot) chart.getPlot(); DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MM-dd-yyyy HH:mm")); addBuySellSignals(timeSeries, strategy, plot); displayChart(chart); }
Example 15
Source File: StackedXYAreaRendererTest.java From ECG-Viewer with GNU General Public License v2.0 | 5 votes |
/** * Check that the renderer is calculating the range bounds correctly. */ @Test public void testFindRangeBounds() { TableXYDataset dataset = RendererXYPackageUtils.createTestTableXYDataset(); JFreeChart chart = ChartFactory.createStackedXYAreaChart( "Test Chart", "X", "Y", dataset, PlotOrientation.VERTICAL, false, false, false); XYPlot plot = (XYPlot) chart.getPlot(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); Range bounds = rangeAxis.getRange(); assertTrue(bounds.contains(6.0)); assertTrue(bounds.contains(8.0)); }
Example 16
Source File: DefaultChartTheme.java From jasperreports with GNU Lesser General Public License v3.0 | 4 votes |
/** * */ protected JFreeChart createPieChart() throws JRException { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createPieChart( evaluateTextExpression(getChart().getTitleExpression()), (PieDataset)getDataset(), isShowLegend(), true, false ); configureChart(jfreeChart); PiePlot piePlot = (PiePlot)jfreeChart.getPlot(); //plot.setStartAngle(290); //plot.setDirection(Rotation.CLOCKWISE); //plot.setNoDataMessage("No data to display"); JRPiePlot jrPiePlot = (JRPiePlot)getPlot(); boolean isCircular = jrPiePlot.getCircular() == null ? true : jrPiePlot.getCircular(); piePlot.setCircular(isCircular); boolean isShowLabels = jrPiePlot.getShowLabels() == null ? true : jrPiePlot.getShowLabels(); if (isShowLabels) { PieSectionLabelGenerator labelGenerator = (PieSectionLabelGenerator)getLabelGenerator(); JRItemLabel itemLabel = jrPiePlot.getItemLabel(); if (labelGenerator != null) { piePlot.setLabelGenerator(labelGenerator); } else if (jrPiePlot.getLabelFormat() != null) { piePlot.setLabelGenerator( new StandardPieSectionLabelGenerator(jrPiePlot.getLabelFormat(), NumberFormat.getNumberInstance(getLocale()), NumberFormat.getPercentInstance(getLocale())) ); }// the default section label is just the key, so there's no need to set localized number formats // else if (itemLabel != null && itemLabel.getMask() != null) // { // piePlot.setLabelGenerator( // new StandardPieSectionLabelGenerator(itemLabel.getMask()) // ); // } piePlot.setLabelFont( fontUtil.getAwtFont( getFont(itemLabel == null ? null : itemLabel.getFont()), getLocale() ) ); if (itemLabel != null && itemLabel.getColor() != null) { piePlot.setLabelPaint(itemLabel.getColor()); } else { piePlot.setLabelPaint(getChart().getForecolor()); } if (itemLabel != null && itemLabel.getBackgroundColor() != null) { piePlot.setLabelBackgroundPaint(itemLabel.getBackgroundColor()); } else { piePlot.setLabelBackgroundPaint(getChart().getBackcolor()); } } else { piePlot.setLabelGenerator(null); } if (jrPiePlot.getLegendLabelFormat() != null) { piePlot.setLegendLabelGenerator( new StandardPieSectionLabelGenerator(jrPiePlot.getLegendLabelFormat(), NumberFormat.getNumberInstance(getLocale()), NumberFormat.getPercentInstance(getLocale())) ); }// the default legend label is just the key, so there's no need to set localized number formats return jfreeChart; }
Example 17
Source File: TimeSeriesChartDemo1.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Creates a chart. * * @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); } DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); return chart; }
Example 18
Source File: CashFlowToChart.java From ta4j-origins with MIT License | 4 votes |
public static void main(String[] args) { // Getting the time series TimeSeries series = CsvTradesLoader.loadBitstampSeries(); // Building the trading strategy Strategy strategy = MovingMomentumStrategy.buildStrategy(series); // Running the strategy TimeSeriesManager seriesManager = new TimeSeriesManager(series); TradingRecord tradingRecord = seriesManager.run(strategy); // Getting the cash flow of the resulting trades CashFlow cashFlow = new CashFlow(series, tradingRecord); /** * Building chart datasets */ TimeSeriesCollection datasetAxis1 = new TimeSeriesCollection(); datasetAxis1.addSeries(buildChartTimeSeries(series, new ClosePriceIndicator(series), "Bitstamp Bitcoin (BTC)")); TimeSeriesCollection datasetAxis2 = new TimeSeriesCollection(); datasetAxis2.addSeries(buildChartTimeSeries(series, cashFlow, "Cash Flow")); /** * Creating the chart */ JFreeChart chart = ChartFactory.createTimeSeriesChart( "Bitstamp BTC", // title "Date", // x-axis label "Price", // y-axis label datasetAxis1, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); XYPlot plot = (XYPlot) chart.getPlot(); DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MM-dd HH:mm")); /** * Adding the cash flow axis (on the right) */ addCashFlowAxis(plot, datasetAxis2); /** * Displaying the chart */ displayChart(chart); }
Example 19
Source File: SWTBarChartDemo1.java From ECG-Viewer with GNU General Public License v2.0 | 4 votes |
/** * Creates a sample chart. * * @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; }
Example 20
Source File: AggregationExecutionChartBuilder.java From livingdoc-confluence with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("deprecation") private void customizeChart(JFreeChart chart) throws IOException { chart.setBackgroundPaint(Color.white); chart.setBorderVisible(settings.isBorder()); TextTitle chartTitle = chart.getTitle(); customizeTitle(chartTitle, DEFAULT_TITLE_FONT); addSubTitle(chart, settings.getSubTitle(), DEFAULT_SUBTITLE_FONT); addSubTitle(chart, settings.getSubTitle2(), DEFAULT_SUBTITLE2_FONT); CategoryPlot plot = ( CategoryPlot ) chart.getPlot(); plot.setNoDataMessage(ldUtil.getText("livingdoc.historic.nodata")); StackedBarRenderer renderer = new StackedBarRenderer(true); plot.setRenderer(renderer); int index = 0; renderer.setSeriesPaint(index ++ , GREEN_COLOR); if (settings.isShowIgnored()) { renderer.setSeriesPaint(index ++ , Color.yellow); } renderer.setSeriesPaint(index, Color.red); renderer.setToolTipGenerator(new DefaultTooltipGenerator()); renderer.setItemURLGenerator(new CategoryURLGenerator() { @Override public String generateURL(CategoryDataset data, int series, int category) { Comparable< ? > valueKey = data.getColumnKey(category); ChartLongValue value = ( ChartLongValue ) valueKey; return "javascript:" + settings.getExecutionUID() + "_showHistoricChart('" + value.getId() + "');"; } }); CategoryAxis domainAxis = plot.getDomainAxis(); customizeAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setCategoryMargin(0.01); ValueAxis rangeAxis = plot.getRangeAxis(); customizeAxis(rangeAxis); rangeAxis.setLowerBound(0); rangeAxis.setUpperBound(1.0); if (rangeAxis instanceof NumberAxis) { NumberAxis numberAxis = ( NumberAxis ) rangeAxis; numberAxis.setTickUnit(new NumberTickUnit(.10)); numberAxis.setNumberFormatOverride(PERCENT_FORMATTER); } plot.setForegroundAlpha(0.8f); }