@Override public void start(Stage stage) throws Exception { PieDataset dataset = createDataset(); JFreeChart chart = createChart(dataset); ChartViewer viewer = new ChartViewer(chart); stage.setScene(new Scene(viewer)); stage.setTitle("JFreeChart: PieChartFXDemo1.java"); stage.setWidth(700); stage.setHeight(390); stage.show(); }
@Override public void start(Stage stage) throws Exception { XYDataset dataset = createDataset(); JFreeChart chart = createChart(dataset); ChartViewer viewer = new ChartViewer(chart); stage.setScene(new Scene(viewer)); stage.setTitle("JFreeChart: TimeSeriesFXDemo1.java"); stage.setWidth(700); stage.setHeight(390); stage.show(); }
/** * Adds a chart viewer to the stage and displays it. * * @param stage the stage. * @throws Exception if something goes wrong. */ @Override public void start(Stage stage) throws Exception { CategoryDataset dataset = createDataset(); JFreeChart chart = createChart(dataset); ChartViewer viewer = new ChartViewer(chart); viewer.addChartMouseListener(this); stage.setScene(new Scene(viewer)); stage.setTitle("JFreeChart: BarChartFXDemo1.java"); stage.setWidth(700); stage.setHeight(390); stage.show(); }
public static void printChart(ChartViewer chartNode) { // As of java 1.8.0_74, the JavaFX printing support seems to do poor // job. It creates pixelated, low-resolution print outs. For that // reason, we use the AWT PrinterJob class, until the JavaFX printing // support is improved. SwingUtilities.invokeLater(() -> { PrinterJob job = PrinterJob.getPrinterJob(); PageFormat pf = job.defaultPage(); PageFormat pf2 = job.pageDialog(pf); if (pf2 == pf) return; ChartPanel p = new ChartPanel(chartNode.getChart()); job.setPrintable(p, pf2); if (!job.printDialog()) return; try { job.print(); } catch (PrinterException e) { e.printStackTrace(); MZmineGUI.displayMessage("Error printing: " + e.getMessage()); } }); }
public MyDemoPane() { XYDataset dataset = createDataset(); JFreeChart chart = createChart(dataset); this.chartViewer = new ChartViewer(chart); this.chartViewer.addChartMouseListener(this); getChildren().add(this.chartViewer); CrosshairOverlayFX crosshairOverlay = new CrosshairOverlayFX(); this.xCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f)); this.xCrosshair.setStroke(new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1, new float[]{2.0f, 2.0f}, 0)); this.xCrosshair.setLabelVisible(true); this.yCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f)); this.yCrosshair.setStroke(new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1, new float[] {2.0f, 2.0f}, 0)); this.yCrosshair.setLabelVisible(true); crosshairOverlay.addDomainCrosshair(xCrosshair); crosshairOverlay.addRangeCrosshair(yCrosshair); Platform.runLater(() -> { this.chartViewer.getCanvas().addOverlay(crosshairOverlay); }); }
public static void exportToClipboard(ChartViewer chartNode) { final Clipboard clipboard = Clipboard.getSystemClipboard(); final ClipboardContent content = new ClipboardContent(); final int width = (int) chartNode.getWidth(); final int height = (int) chartNode.getHeight(); WritableImage img = new WritableImage(width, height); SnapshotParameters params = new SnapshotParameters(); chartNode.snapshot(params, img); content.putImage(img); clipboard.setContent(content); }
public static void showSaveDialog(ChartViewer chartNode, ImgFileType fileType) { FileChooser fileChooser = new FileChooser(); switch (fileType) { case JPG: fileChooser.setTitle("Export to JPG"); fileChooser.getExtensionFilters().add(new ExtensionFilter("JPEG", "*.jpg")); break; case PNG: fileChooser.setTitle("Export to PNG"); fileChooser.getExtensionFilters() .add(new ExtensionFilter("Portable Network Graphics (PNG)", "*.png")); break; case SVG: fileChooser.setTitle("Export to SVG"); fileChooser.getExtensionFilters() .add(new ExtensionFilter("Scalable Vector Graphics (SVG)", "*.svg")); break; case PDF: fileChooser.setTitle("Export to PDF"); fileChooser.getExtensionFilters() .add(new ExtensionFilter("Portable Document Format (PDF)", "*.pdf")); break; case EMF: fileChooser.setTitle("Export to EMF"); fileChooser.getExtensionFilters().add(new ExtensionFilter("EMF image", "*.emf")); break; case EPS: fileChooser.setTitle("Export to EPS"); fileChooser.getExtensionFilters().add(new ExtensionFilter("EPS Image", "*.eps")); break; } // Remember last directory if (lastSaveDirectory != null && lastSaveDirectory.isDirectory()) fileChooser.setInitialDirectory(lastSaveDirectory); // Show the file chooser File file = fileChooser.showSaveDialog(chartNode.getScene().getWindow()); // If nothing was chosen, quit if (file == null) return; // Save the last open directory lastSaveDirectory = file.getParentFile(); // Do the export in a new thread final File finalFile = file; new Thread(() -> { exportToImageFile(chartNode, finalFile, fileType); }).start(); }
public static void exportToImageFile(ChartViewer chartNode, File file, ImgFileType fileType) { final JFreeChart chart = chartNode.getChart(); final int width = (int) chartNode.getWidth(); final int height = (int) chartNode.getHeight(); try { switch (fileType) { case JPG: ExportUtils.writeAsJPEG(chart, width, height, file); break; case PNG: ExportUtils.writeAsPNG(chart, width, height, file); break; case SVG: setDrawSeriesLineAsPath(chart, true); ExportUtils.writeAsSVG(chart, width, height, file); setDrawSeriesLineAsPath(chart, false); break; case PDF: setDrawSeriesLineAsPath(chart, true); ExportUtils.writeAsPDF(chart, width, height, file); setDrawSeriesLineAsPath(chart, false); break; case EMF: FileOutputStream out2 = new FileOutputStream(file); setDrawSeriesLineAsPath(chart, true); EMFGraphics2D g2d2 = new EMFGraphics2D(out2, new Dimension(width, height)); g2d2.startExport(); chart.draw(g2d2, new Rectangle(width, height)); g2d2.endExport(); setDrawSeriesLineAsPath(chart, false); break; case EPS: FileOutputStream out = new FileOutputStream(file); setDrawSeriesLineAsPath(chart, true); EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false); g2d.setGraphicContext(new GraphicContext()); g2d.setupDocument(out, width, height); chart.draw(g2d, new Rectangle(width, height)); g2d.finish(); setDrawSeriesLineAsPath(chart, false); out.close(); break; } } catch (IOException e) { MZmineGUI.displayMessage("Unable to save image: " + e.getMessage()); e.printStackTrace(); } }
/** * * @param chartNode * @param plot * @param reservedPoints Number of screen pixels to reserve for each label, so that the labels do * not overlap * @param underlyingGenerator */ public IntelligentItemLabelGenerator(ChartViewer chartNode, int reservedPixels, XYItemLabelGenerator underlyingGenerator) { this.chartNode = chartNode; this.reservedPixels = reservedPixels; this.underlyingGenerator = underlyingGenerator; }
/** * Creates a new instance with no modifier keys required. * * @param id the handler ID ({@code null} not permitted). * @param parent the chart viewer. */ public ZoomHandlerFX(String id, ChartViewer parent) { this(id, parent, false, false, false, false); }
/** * Creates a new instance that will be activated using the specified * combination of modifier keys. * * @param id the handler ID ({@code null} not permitted). * @param parent the chart viewer. * @param altKey require ALT key? * @param ctrlKey require CTRL key? * @param metaKey require META key? * @param shiftKey require SHIFT key? */ public ZoomHandlerFX(String id, ChartViewer parent, boolean altKey, boolean ctrlKey, boolean metaKey, boolean shiftKey) { super(id, altKey, ctrlKey, metaKey, shiftKey); this.viewer = parent; }
/** * Creates a new instance with no modifier keys required. * * @param id the handler ID (<code>null</code> not permitted). * @param parent the chart viewer. */ public ZoomHandlerFX(String id, ChartViewer parent) { this(id, parent, false, false, false, false); }
/** * Creates a new instance that will be activated using the specified * combination of modifier keys. * * @param id the handler ID (<code>null</code> not permitted). * @param parent the chart viewer. * @param altKey require ALT key? * @param ctrlKey require CTRL key? * @param metaKey require META key? * @param shiftKey require SHIFT key? */ public ZoomHandlerFX(String id, ChartViewer parent, boolean altKey, boolean ctrlKey, boolean metaKey, boolean shiftKey) { super(id, altKey, ctrlKey, metaKey, shiftKey); this.viewer = parent; }