org.jfree.chart.JFreeChart Java Examples
The following examples show how to use
org.jfree.chart.JFreeChart.
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: ChartUtils.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static byte[] getChartAsPngByteArray( JFreeChart jFreeChart, int width, int height ) { ByteArrayOutputStream out = new ByteArrayOutputStream(); try { org.jfree.chart.ChartUtils.writeChartAsPNG( out, jFreeChart, width, height ); out.flush(); return out.toByteArray(); } catch ( IOException ex ) { throw new UncheckedIOException( ex ); } }
Example #2
Source File: AgentsPanel.java From computational-economy with GNU General Public License v3.0 | 6 votes |
protected ChartPanel createAgentNumberPanel(final Currency currency, final Class<? extends Agent> agentType) { final TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection(); timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry() .getNationalEconomyModel(currency).numberOfAgentsModels.get(agentType).getTimeSeries()); // in case of households if (Household.class.isAssignableFrom(agentType)) { // show retired households timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry() .getNationalEconomyModel(currency).householdsModel.retiredModel.getTimeSeries()); } final JFreeChart chart = ChartFactory.createTimeSeriesChart("# " + agentType.getSimpleName() + " Agents", "Date", "# Agents", timeSeriesCollection, true, true, false); configureChart(chart); return new ChartPanel(chart); }
Example #3
Source File: CrosshairOverlayFXDemo1.java From jfree-fxdemos with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void chartMouseMoved(ChartMouseEventFX event) { Rectangle2D dataArea = this.chartViewer.getCanvas().getRenderingInfo().getPlotInfo().getDataArea(); JFreeChart chart = event.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis xAxis = plot.getDomainAxis(); double x = xAxis.java2DToValue(event.getTrigger().getX(), dataArea, RectangleEdge.BOTTOM); // make the crosshairs disappear if the mouse is out of range if (!xAxis.getRange().contains(x)) { x = Double.NaN; } double y = DatasetUtils.findYValue(plot.getDataset(), 0, x); this.xCrosshair.setValue(x); this.yCrosshair.setValue(y); }
Example #4
Source File: LogAxisTest.java From ECG-Viewer 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. */ @Test 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); 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 #5
Source File: LineChartBuilder.java From nmonvisualizer with Apache License 2.0 | 6 votes |
/** * Sets the X axis to display time relative to the given start time. */ // for relative time, format the x axis differently // the data _does not_ change public static void setRelativeAxis(JFreeChart chart, long startTime) { if (chart != null) { RelativeDateFormat format = new RelativeDateFormat(startTime); // : separators format.setHourSuffix(":"); format.setMinuteSuffix(":"); format.setSecondSuffix(""); // zero pad minutes and seconds DecimalFormat padded = new DecimalFormat("00"); format.setMinuteFormatter(padded); format.setSecondFormatter(padded); XYPlot plot = chart.getXYPlot(); ((DateAxis) plot.getDomainAxis()).setDateFormatOverride(format); } }
Example #6
Source File: BoxAndWhiskerRendererTest.java From ECG-Viewer with GNU General Public License v2.0 | 6 votes |
/** * Draws a chart where the dataset contains a null median value. */ @Test public void testDrawWithNullMedian() { boolean success; try { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); dataset.add(new BoxAndWhiskerItem(new Double(1.0), null, new Double(0.0), new Double(4.0), new Double(0.5), new Double(4.5), new Double(-0.5), new Double(5.5), null), "S1", "C1"); CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), new BoxAndWhiskerRenderer()); ChartRenderingInfo info = new ChartRenderingInfo(); JFreeChart chart = new JFreeChart(plot); /* BufferedImage image = */ chart.createBufferedImage(300, 200, info); success = true; } catch (Exception e) { success = false; } assertTrue(success); }
Example #7
Source File: AreaRendererTests.java From astor with GNU General Public License v2.0 | 6 votes |
/** * A check for the datasetIndex and seriesIndex fields in the LegendItem * returned by the getLegendItem() method. */ public void testGetLegendItemSeriesIndex() { DefaultCategoryDataset dataset0 = new DefaultCategoryDataset(); dataset0.addValue(21.0, "R1", "C1"); dataset0.addValue(22.0, "R2", "C1"); DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); dataset1.addValue(23.0, "R3", "C1"); dataset1.addValue(24.0, "R4", "C1"); dataset1.addValue(25.0, "R5", "C1"); AreaRenderer r = new AreaRenderer(); CategoryPlot plot = new CategoryPlot(dataset0, new CategoryAxis("x"), new NumberAxis("y"), r); plot.setDataset(1, dataset1); /*JFreeChart chart =*/ new JFreeChart(plot); LegendItem li = r.getLegendItem(1, 2); assertEquals("R5", li.getLabel()); assertEquals(1, li.getDatasetIndex()); assertEquals(2, li.getSeriesIndex()); }
Example #8
Source File: DefaultChartService.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override @Transactional( readOnly = true ) public JFreeChart getJFreeOrganisationUnitChart( Indicator indicator, OrganisationUnit parent, boolean title, I18nFormat format ) { List<Period> periods = periodService.reloadPeriods( new RelativePeriods().setThisYear( true ).getRelativePeriods( format, true ) ); Chart chart = new Chart(); if ( title ) { chart.setName( indicator.getName() ); } chart.setType( ChartType.COLUMN ); chart.setDimensions( DimensionalObject.DATA_X_DIM_ID, DimensionalObject.ORGUNIT_DIM_ID, DimensionalObject.PERIOD_DIM_ID ); chart.setHideLegend( true ); chart.addDataDimensionItem( indicator ); chart.setPeriods( periods ); chart.setOrganisationUnits( parent.getSortedChildren() ); chart.setHideSubtitle( title ); chart.setFormat( format ); return getJFreeChart( chart ); }
Example #9
Source File: SimpleChartTheme.java From jasperreports with GNU Lesser General Public License v3.0 | 6 votes |
/** * */ protected JFreeChart createAreaChart() throws JRException { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createAreaChart( evaluateTextExpression(getChart().getTitleExpression()), evaluateTextExpression(((JRAreaPlot)getPlot()).getCategoryAxisLabelExpression()), evaluateTextExpression(((JRAreaPlot)getPlot()).getValueAxisLabelExpression()), (CategoryDataset)getDataset(), getPlot().getOrientationValue().getOrientation(), isShowLegend(), true, false); configureChart(jfreeChart, getPlot()); JRAreaPlot areaPlot = (JRAreaPlot)getPlot(); // Handle the axis formating for the category axis configureAxis(((CategoryPlot)jfreeChart.getPlot()).getDomainAxis(), areaPlot.getCategoryAxisLabelFont(), areaPlot.getCategoryAxisLabelColor(), areaPlot.getCategoryAxisTickLabelFont(), areaPlot.getCategoryAxisTickLabelColor(), areaPlot.getCategoryAxisTickLabelMask(), areaPlot.getCategoryAxisVerticalTickLabels(), areaPlot.getOwnCategoryAxisLineColor(), getDomainAxisSettings(), (Comparable<?>)evaluateExpression(areaPlot.getDomainAxisMinValueExpression()), (Comparable<?>)evaluateExpression(areaPlot.getDomainAxisMaxValueExpression()) ); // Handle the axis formating for the value axis configureAxis(((CategoryPlot)jfreeChart.getPlot()).getRangeAxis(), areaPlot.getValueAxisLabelFont(), areaPlot.getValueAxisLabelColor(), areaPlot.getValueAxisTickLabelFont(), areaPlot.getValueAxisTickLabelColor(), areaPlot.getValueAxisTickLabelMask(), areaPlot.getValueAxisVerticalTickLabels(), areaPlot.getOwnValueAxisLineColor(), getRangeAxisSettings(), (Comparable<?>)evaluateExpression(areaPlot.getRangeAxisMinValueExpression()), (Comparable<?>)evaluateExpression(areaPlot.getRangeAxisMaxValueExpression()) ); return jfreeChart; }
Example #10
Source File: GraphFrame.java From SPIM_Registration with GNU General Public License v2.0 | 6 votes |
public GraphFrame( final JFreeChart chart, final int referenceTimePoint, final boolean enableReferenceTimePoint, final List<FileOpenMenuEntry> extraMenuItems, final ArrayList< RegistrationStatistics > data ) { super(); this.referenceTimePoint = referenceTimePoint; this.enableReferenceTimePoint = enableReferenceTimePoint; mainPanel = new JPanel(); mainPanel.setLayout( new BorderLayout() ); updateWithNewChart( chart, true, extraMenuItems, data ); JPanel buttonsPanel = new JPanel(); mainPanel.add( buttonsPanel, BorderLayout.SOUTH ); setContentPane( mainPanel ); validate(); GUI.center( this ); }
Example #11
Source File: IntervalBarRendererTest.java From ECG-Viewer with GNU General Public License v2.0 | 6 votes |
/** * Draws the chart with a <code>null</code> info object to make sure that * no exceptions are thrown (particularly by code in the renderer). */ @Test public void testDrawWithNullInfo() { try { double[][] starts = new double[][] {{0.1, 0.2, 0.3}, {0.3, 0.4, 0.5}}; double[][] ends = new double[][] {{0.5, 0.6, 0.7}, {0.7, 0.8, 0.9}}; DefaultIntervalCategoryDataset dataset = new DefaultIntervalCategoryDataset(starts, ends); IntervalBarRenderer renderer = new IntervalBarRenderer(); CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), renderer); JFreeChart chart = new JFreeChart(plot); /* BufferedImage image = */ chart.createBufferedImage(300, 200, null); } catch (NullPointerException e) { fail("No exception should be thrown."); } }
Example #12
Source File: StandardXYItemRendererTest.java From SIMVA-SoS with Apache License 2.0 | 6 votes |
/** * A check to ensure that an item that falls outside the plot's data area * does NOT generate an item entity. */ @Test 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 #13
Source File: AreaRendererTest.java From ECG-Viewer with GNU General Public License v2.0 | 6 votes |
/** * A check for the datasetIndex and seriesIndex fields in the LegendItem * returned by the getLegendItem() method. */ @Test public void testGetLegendItemSeriesIndex() { DefaultCategoryDataset dataset0 = new DefaultCategoryDataset(); dataset0.addValue(21.0, "R1", "C1"); dataset0.addValue(22.0, "R2", "C1"); DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); dataset1.addValue(23.0, "R3", "C1"); dataset1.addValue(24.0, "R4", "C1"); dataset1.addValue(25.0, "R5", "C1"); AreaRenderer r = new AreaRenderer(); CategoryPlot plot = new CategoryPlot(dataset0, new CategoryAxis("x"), new NumberAxis("y"), r); plot.setDataset(1, dataset1); /*JFreeChart chart =*/ new JFreeChart(plot); LegendItem li = r.getLegendItem(1, 2); assertEquals("R5", li.getLabel()); assertEquals(1, li.getDatasetIndex()); assertEquals(2, li.getSeriesIndex()); }
Example #14
Source File: MultiplePiePlot.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
/** * Creates a new plot. * * @param dataset the dataset (<code>null</code> permitted). */ public MultiplePiePlot(CategoryDataset dataset) { super(); setDataset(dataset); PiePlot piePlot = new PiePlot(null); piePlot.setIgnoreNullValues(true); this.pieChart = new JFreeChart(piePlot); this.pieChart.removeLegend(); this.dataExtractOrder = TableOrder.BY_COLUMN; this.pieChart.setBackgroundPaint(null); TextTitle seriesTitle = new TextTitle("Series Title", new Font("SansSerif", Font.BOLD, 12)); seriesTitle.setPosition(RectangleEdge.BOTTOM); this.pieChart.setTitle(seriesTitle); this.aggregatedItemsKey = "Other"; this.aggregatedItemsPaint = Color.lightGray; this.sectionPaints = new HashMap(); this.legendItemShape = new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0); }
Example #15
Source File: NumericalAttributeStatisticsModel.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
/** * Creates the histogram chart. * * @param exampleSet * @return */ private JFreeChart createHistogramChart(ExampleSet exampleSet) { JFreeChart chart = ChartFactory.createHistogram(null, null, null, createHistogramDataset(exampleSet), PlotOrientation.VERTICAL, false, false, false); AbstractAttributeStatisticsModel.setDefaultChartFonts(chart); chart.setBackgroundPaint(null); chart.setBackgroundImageAlpha(0.0f); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRangeGridlinesVisible(false); plot.setDomainGridlinesVisible(false); plot.setOutlineVisible(false); plot.setRangeZeroBaselineVisible(false); plot.setDomainZeroBaselineVisible(false); plot.setBackgroundPaint(COLOR_INVISIBLE); plot.setBackgroundImageAlpha(0.0f); XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, AttributeGuiTools.getColorForValueType(Ontology.NUMERICAL)); renderer.setBarPainter(new StandardXYBarPainter()); renderer.setDrawBarOutline(true); renderer.setShadowVisible(false); return chart; }
Example #16
Source File: TimeSeriesLineChartBuilder.java From qpid-broker-j with Apache License 2.0 | 6 votes |
@Override public JFreeChart createChartImpl(String title, String xAxisTitle, String yAxisTitle, final Dataset dataset, PlotOrientation plotOrientation, boolean showLegend, boolean showToolTips, boolean showUrls) { JFreeChart chart = ChartFactory.createTimeSeriesChart( title, xAxisTitle, yAxisTitle, (XYDataset)dataset, showLegend, showToolTips, showUrls); return chart; }
Example #17
Source File: CategoryPlotTest.java From openstock with GNU General Public License v3.0 | 6 votes |
/** * A test for bug 1654215 (where a renderer is added to the plot without * a corresponding dataset and it throws an exception at drawing time). */ @Test public void test1654215() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); JFreeChart chart = ChartFactory.createLineChart("Title", "X", "Y", dataset, PlotOrientation.VERTICAL, true, false, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setRenderer(1, new LineAndShapeRenderer()); 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 #18
Source File: XYPlotTest.java From SIMVA-SoS with Apache License 2.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 #19
Source File: CombinedDomainXYPlotTest.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
/** * Check that only one chart change event is generated by a change to a * subplot. */ @Test public void testNotification() { CombinedDomainXYPlot plot = createPlot(); JFreeChart chart = new JFreeChart(plot); chart.addChangeListener(this); XYPlot subplot1 = (XYPlot) plot.getSubplots().get(0); NumberAxis yAxis = (NumberAxis) subplot1.getRangeAxis(); yAxis.setAutoRangeIncludesZero(!yAxis.getAutoRangeIncludesZero()); assertEquals(1, this.events.size()); // a redraw should NOT trigger another change event BufferedImage image = new BufferedImage(200, 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); this.events.clear(); chart.draw(g2, new Rectangle2D.Double(0.0, 0.0, 200.0, 100.0)); assertTrue(this.events.isEmpty()); }
Example #20
Source File: TICPanel.java From PDV with GNU General Public License v3.0 | 5 votes |
/** * Update panel * @param nameToKeyToRtAndInt File name to spectrum key to RT and intensity * @param mode Mode */ public void updatePanel(HashMap<String, HashMap<String, ArrayList<float[]>>> nameToKeyToRtAndInt, Integer mode, Integer topNum){ XYDataset xyDataset = creatMultiXYDataset(nameToKeyToRtAndInt, mode, topNum); JFreeChart chart = ChartFactory.createXYLineChart("TIC","Elution Time","Intensity (10^" + (topNum.toString().length() - 1) +")", xyDataset, PlotOrientation.VERTICAL,true,false,false); ChartUtils.setAntiAlias(chart); ChartUtils.setLineRender(chart.getXYPlot()); chart.getLegend().setFrame(new BlockBorder(Color.WHITE)); viewJPanel.removeAll(); chartPanel = new LineChart(msDataDisplay, chart); GroupLayout viewJPanelLayout = new GroupLayout(viewJPanel); viewJPanel.setLayout(viewJPanelLayout); viewJPanelLayout.setHorizontalGroup( viewJPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(viewJPanelLayout.createSequentialGroup() .addComponent(chartPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) ) ); viewJPanelLayout.setVerticalGroup( viewJPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(viewJPanelLayout.createSequentialGroup() .addComponent(chartPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) ) ); viewJPanel.revalidate(); viewJPanel.repaint(); }
Example #21
Source File: PannableTimeChartPanel.java From jsonde with BSD 3-Clause "New" or "Revised" License | 5 votes |
public PannableTimeChartPanel(long startTime, long endTime, TimeSeriesCollection dataset) { double interval = ((endTime - startTime) / (30000.)); JFreeChart chart = ChartFactory.createXYLineChart( "Memory Telemtry View", "Time", "Memory (Mb)", dataset, PlotOrientation.VERTICAL, true, true, false ); plot = (XYPlot) chart.getPlot(); DateAxis domainAxis = new DateAxis(); plot.setDomainAxis(domainAxis); domainAxis.setLabelAngle(Math.PI / 2); domainAxis.setAutoRange(true); domainAxis.setMinimumDate(new Date(startTime)); domainAxis.setMaximumDate(new Date(startTime + 30L * 1000L)); plot.setDomainPannable(true); setLayout(new BorderLayout()); add(new ChartPanel(chart), BorderLayout.CENTER); JScrollBar panScrollBar = new JScrollBar(JScrollBar.HORIZONTAL); rangeModel = new DefaultBoundedRangeModel(); rangeModel.setMinimum(0); rangeModel.setMaximum((int)((interval - 1) * 100)); rangeModel.addChangeListener(this); panScrollBar.setModel(rangeModel); add(panScrollBar, BorderLayout.SOUTH); }
Example #22
Source File: UserChartController.java From airsonic with GNU General Public License v3.0 | 5 votes |
@GetMapping public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { String type = request.getParameter("type"); CategoryDataset dataset = createDataset(type); JFreeChart chart = createChart(dataset, request); int imageHeight = Math.max(IMAGE_MIN_HEIGHT, 15 * dataset.getColumnCount()); ChartUtils.writeChartAsPNG(response.getOutputStream(), chart, IMAGE_WIDTH, imageHeight); return null; }
Example #23
Source File: MoneyPanel.java From computational-economy with GNU General Public License v3.0 | 5 votes |
protected ChartPanel createKeyInterestRatesPanel() { final TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection(); for (final Currency currency : Currency.values()) { timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry() .getNationalEconomyModel(currency).keyInterestRateModel.getTimeSeries()); } final JFreeChart chart = ChartFactory.createTimeSeriesChart("Key Interest Rate", "Date", "Key Interest Rate", timeSeriesCollection, true, true, false); configureChart(chart); return new ChartPanel(chart); }
Example #24
Source File: ChartExportUtil.java From mzmine3 with GNU General Public License v2.0 | 5 votes |
public static void writeChartToJPEG(JFreeChart chart, ChartRenderingInfo info, int width, int height, File fileName, int resolution) throws IOException { // Background color Paint saved = chart.getBackgroundPaint(); if (((Color) saved).getAlpha() == 0) { chart.setBackgroundPaint(Color.WHITE); chart.setBackgroundImageAlpha(255); if (chart.getLegend() != null) chart.getLegend().setBackgroundPaint(Color.WHITE); // legends and stuff for (int i = 0; i < chart.getSubtitleCount(); i++) if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass())) ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(Color.WHITE); // apply bg chart.getPlot().setBackgroundPaint(Color.WHITE); } // if (resolution == 72) writeChartToJPEG(chart, width, height, fileName); else { OutputStream out = new BufferedOutputStream(new FileOutputStream(fileName)); try { BufferedImage image = paintScaledChartToBufferedImage(chart, info, out, width, height, resolution, BufferedImage.TYPE_INT_RGB); EncoderUtil.writeBufferedImage(image, ImageFormat.JPEG, out, 1.f); } finally { out.close(); } } }
Example #25
Source File: TimeSeries.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public JFreeChart getChart() { if (chart == null) { createDataset(); chart = ChartFactory.createTimeSeriesChart(title, // chart title xLabel, // domain axis label yLabel, // range axis label dataset, // data true, // include legend true, // tooltips? false // URLs? ); } XYPlot plot = (XYPlot) chart.getPlot(); if (colors == null) { colors = ColorBrewer.getPairedColors(seriesNames.size()); } for( int i = 0; i < colors.length; i++ ) { plot.getRenderer().setSeriesPaint(i, colors[i]); } setShapeLinesVisibility(plot); return chart; }
Example #26
Source File: BarChartDemo1.java From SIMVA-SoS with Apache License 2.0 | 5 votes |
/** * Creates a new demo instance. * * @param title the frame title. */ public BarChartDemo1(String title) { super(title); CategoryDataset dataset = createDataset(); JFreeChart chart = createChart(dataset); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setFillZoomRectangle(true); chartPanel.setMouseWheelEnabled(true); chartPanel.setPreferredSize(new Dimension(500, 270)); setContentPane(chartPanel); }
Example #27
Source File: RenderUtils.java From heroic with Apache License 2.0 | 5 votes |
private static JFreeChart buildChart( final String title, final XYDataset lineAndShape, final XYDataset interval, final XYItemRenderer lineAndShapeRenderer, final XYItemRenderer intervalRenderer ) { final ValueAxis timeAxis = new DateAxis(); timeAxis.setLowerMargin(0.02); timeAxis.setUpperMargin(0.02); final NumberAxis valueAxis = new NumberAxis(); valueAxis.setAutoRangeIncludesZero(false); final XYPlot plot = new XYPlot(); plot.setDomainAxis(0, timeAxis); plot.setRangeAxis(0, valueAxis); plot.setDataset(0, lineAndShape); plot.setRenderer(0, lineAndShapeRenderer); plot.setDomainAxis(1, timeAxis); plot.setRangeAxis(1, valueAxis); plot.setDataset(1, interval); plot.setRenderer(1, intervalRenderer); return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false); }
Example #28
Source File: BarChartDemo1.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Creates a new demo instance. * * @param title the frame title. */ public BarChartDemo1(String title) { super(title); CategoryDataset dataset = createDataset(); JFreeChart chart = createChart(dataset); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setFillZoomRectangle(true); chartPanel.setMouseWheelEnabled(true); chartPanel.setPreferredSize(new Dimension(500, 270)); setContentPane(chartPanel); }
Example #29
Source File: LinkAndBrushChartPanel.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
public LinkAndBrushChartPanel(JFreeChart chart, int defaultWidth, int defaultHeigth, int minDrawWidth, int minDrawHeigth, boolean zoomOnLinkAndBrush) { super(chart, defaultWidth, defaultHeigth, minDrawWidth, minDrawHeigth, DEFAULT_MAXIMUM_DRAW_WIDTH, DEFAULT_MAXIMUM_DRAW_HEIGHT, DEFAULT_BUFFER_USED, false, // copy false, // properties false, // save false, // print false, // zoom true); // tooltips this.zoomOnLinkAndBrushSelection = zoomOnLinkAndBrush; setInitialDelay(200); setMouseWheelEnabled(false); }
Example #30
Source File: DefaultChartService.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
private JFreeChart getMultiplePieChart( BaseChart chart, CategoryDataset[] dataSets ) { JFreeChart multiplePieChart = ChartFactory.createMultiplePieChart( chart.getName(), dataSets[0], TableOrder.BY_ROW, !chart.isHideLegend(), false, false ); setBasicConfig( multiplePieChart, chart ); if ( multiplePieChart.getLegend() != null ) { multiplePieChart.getLegend().setItemFont( SUB_TITLE_FONT ); } MultiplePiePlot multiplePiePlot = (MultiplePiePlot) multiplePieChart.getPlot(); JFreeChart pieChart = multiplePiePlot.getPieChart(); pieChart.setBackgroundPaint( DEFAULT_BACKGROUND_COLOR ); pieChart.getTitle().setFont( SUB_TITLE_FONT ); PiePlot piePlot = (PiePlot) pieChart.getPlot(); piePlot.setBackgroundPaint( DEFAULT_BACKGROUND_COLOR ); piePlot.setOutlinePaint( DEFAULT_BACKGROUND_COLOR ); piePlot.setLabelFont( LABEL_FONT ); piePlot.setLabelGenerator( new StandardPieSectionLabelGenerator( "{2}" ) ); piePlot.setSimpleLabels( true ); piePlot.setIgnoreZeroValues( true ); piePlot.setIgnoreNullValues( true ); piePlot.setShadowXOffset( 0d ); piePlot.setShadowYOffset( 0d ); for ( int i = 0; i < dataSets[0].getColumnCount(); i++ ) { piePlot.setSectionPaint( dataSets[0].getColumnKey( i ), COLORS[(i % COLORS.length)] ); } return multiplePieChart; }