public void drawChart(String filename, int width, int height) throws IOException { // Create plot NumberAxis xAxis = new NumberAxis(xAxisLabel); NumberAxis yAxis = new NumberAxis(yAxisLabel); XYSplineRenderer renderer = new XYSplineRenderer(); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(4, 4, 4, 4)); // Create chart JFreeChart chart = new JFreeChart(chartTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, true); ChartUtilities.applyCurrentTheme(chart); ChartPanel chartPanel = new ChartPanel(chart, false); // Draw png BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR); Graphics graphics = bi.getGraphics(); chartPanel.setBounds(0, 0, width, height); chartPanel.paint(graphics); ImageIO.write(bi, "png", new File(filename)); }
private JFreeChart createLineChart(String title, XYSeriesCollection data) { // plot final NumberAxis xAxis = new NumberAxis("X"); xAxis.setAutoRangeIncludesZero(false); final NumberAxis yAxis = new NumberAxis("Y"); yAxis.setAutoRangeIncludesZero(false); final XYSplineRenderer renderer = new XYSplineRenderer(); final XYPlot plot = new XYPlot(data, xAxis, yAxis, renderer); { plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(4, 4, 4, 4)); } // chart return new JFreeChart(title, plot); }
@Override public void run(final String arg0) { // http://www.math.hu-berlin.de/~ccafm/lehre_BZQ_Numerik/allg/JAVA_Pakete/JFreeChart/JFreeChart-Tutorial.html final String title = "Contrast Transfer Function"; final XYSplineRenderer spline = new XYSplineRenderer(); spline.setSeriesPaint(0, Color.RED); spline.setSeriesPaint(1, Color.BLUE); spline.setSeriesShapesVisible(0, false); spline.setSeriesShapesVisible(1, false); final NumberAxis xax = new NumberAxis("q in 1/nm"); final NumberAxis yax = new NumberAxis("CTF"); final XYPlot plot = new XYPlot(createDataset(), xax, yax, spline); final JFreeChart chart = new JFreeChart(plot); final ChartPanel chartPanel = new ChartPanel(chart); final ApplicationFrame chartFrame = new ApplicationFrame(title); chartFrame.setContentPane(chartPanel); chartFrame.pack(); RefineryUtilities.centerFrameOnScreen(chartFrame); chartFrame.setVisible(true); }
public LineChart(List<Fetch> fetches) { final XYDataset dataset = updateDataset(fetches); final JFreeChart chart = ChartFactory.createXYLineChart( fetches.get(0).getBrand(), // chart title "Time", // domain axis label "Number", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); XYPlot plot = (XYPlot) chart.getPlot(); DateAxis range = new DateAxis("Date"); range.setDateFormatOverride(new SimpleDateFormat("dd/MM/yyyy")); plot.setDomainAxis(range); chart.getXYPlot().setRenderer(new XYSplineRenderer()); chart.setBackgroundPaint(Color.WHITE); lineChartPanel = new ChartPanel(chart); lineChartPanel.setPreferredSize(new Dimension(930, 700)); }
@Override public void customize(JFreeChart jfc, JRChart jrc) { Plot plot = jfc.getPlot(); if (plot instanceof XYPlot) { ((XYPlot)plot).setRenderer( new XYSplineRenderer()); } }
public BufferedImage createChartImage(MediaMatrix mat, Color bgColor, int width, int height) { final XYSplineRenderer renderer = new XYSplineRenderer(); final NumberAxis xAxis = new NumberAxis("Time"); final NumberAxis yAxis = new NumberAxis("Score"); final XYPlot plot = new XYPlot(new MediaMatrixXYDataSetAdapter(mat), xAxis, yAxis, renderer); plot.setBackgroundPaint(bgColor); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(4, 4, 4, 4)); final JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint(Color.white); final LegendTitle legendTitle = chart.getLegend(); legendTitle.setItemFont(new Font("SanSerif", Font.PLAIN, 14)); return chart.createBufferedImage(width, height); }
/** * Test that the equals() method distinguishes all fields. */ public void testEquals() { XYSplineRenderer r1 = new XYSplineRenderer(); XYSplineRenderer r2 = new XYSplineRenderer(); assertEquals(r1, r2); assertEquals(r2, r1); r1.setPrecision(9); assertFalse(r1.equals(r2)); r2.setPrecision(9); assertTrue(r1.equals(r2)); }
/** * Two objects that are equal are required to return the same hashCode. */ public void testHashcode() { XYSplineRenderer r1 = new XYSplineRenderer(); XYSplineRenderer r2 = new XYSplineRenderer(); assertTrue(r1.equals(r2)); int h1 = r1.hashCode(); int h2 = r2.hashCode(); assertEquals(h1, h2); }
/** * Verify that this class implements {@link PublicCloneable}. */ public void testPublicCloneable() { XYSplineRenderer r1 = new XYSplineRenderer(); assertTrue(r1 instanceof PublicCloneable); }
private void createGraghPanel(JPanel dataPanel) { JFreeChart chart = ChartFactory.createScatterPlot(null, null, null, null, PlotOrientation.VERTICAL, false, true, false); chart.setBorderVisible(true); mafChartPanel = new MafChartPanel(chart, this); GridBagConstraints gbl_chartPanel = new GridBagConstraints(); gbl_chartPanel.anchor = GridBagConstraints.PAGE_START; gbl_chartPanel.insets = insets0; gbl_chartPanel.fill = GridBagConstraints.BOTH; gbl_chartPanel.weightx = 1.0; gbl_chartPanel.weighty = 1.0; gbl_chartPanel.gridx = 0; gbl_chartPanel.gridy = 2; dataPanel.add(mafChartPanel.getChartPanel(), gbl_chartPanel); XYSplineRenderer lineRenderer = new XYSplineRenderer(3); lineRenderer.setUseFillPaint(true); lineRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator( StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new DecimalFormat("0.00"), new DecimalFormat("0.00"))); Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f); lineRenderer.setSeriesStroke(0, stroke); lineRenderer.setSeriesStroke(1, stroke); lineRenderer.setSeriesPaint(0, new Color(201, 0, 0)); lineRenderer.setSeriesPaint(1, new Color(0, 0, 255)); lineRenderer.setSeriesShape(0, ShapeUtilities.createDiamond((float) 2.5)); lineRenderer.setSeriesShape(1, ShapeUtilities.createUpTriangle((float) 2.5)); ValueAxis mafvDomain = new NumberAxis(XAxisName); ValueAxis mafgsRange = new NumberAxis(YAxisName); XYSeriesCollection lineDataset = new XYSeriesCollection(); lineDataset.addSeries(currMafData); lineDataset.addSeries(corrMafData); XYPlot plot = chart.getXYPlot(); plot.setRangePannable(true); plot.setDomainPannable(true); plot.setDomainGridlinePaint(Color.DARK_GRAY); plot.setRangeGridlinePaint(Color.DARK_GRAY); plot.setBackgroundPaint(new Color(224, 224, 224)); plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD); plot.setDataset(0, lineDataset); plot.setRenderer(0, lineRenderer); plot.setDomainAxis(0, mafvDomain); plot.setRangeAxis(0, mafgsRange); plot.mapDatasetToDomainAxis(0, 0); plot.mapDatasetToRangeAxis(0, 0); LegendTitle legend = new LegendTitle(plot.getRenderer()); legend.setItemFont(new Font("Arial", 0, 10)); legend.setPosition(RectangleEdge.TOP); chart.addLegend(legend); }