List of usage examples for org.jfree.chart.annotations XYPointerAnnotation setFont
public void setFont(Font font)
From source file:org.jfree.chart.demo.XYAreaChartDemo1.java
private static JFreeChart createChart(XYDataset xydataset) { JFreeChart jfreechart = ChartFactory.createXYAreaChart("XY Area Chart Demo", "Domain (X)", "Range (Y)", xydataset, PlotOrientation.VERTICAL, true, true, false); jfreechart.setBackgroundPaint(Color.white); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setForegroundAlpha(0.65F);// w w w . ja va 2s .c o m xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); ValueAxis valueaxis = xyplot.getDomainAxis(); valueaxis.setTickMarkPaint(Color.black); valueaxis.setLowerMargin(0.0D); valueaxis.setUpperMargin(0.0D); ValueAxis valueaxis1 = xyplot.getRangeAxis(); valueaxis1.setTickMarkPaint(Color.black); XYPointerAnnotation xypointerannotation = new XYPointerAnnotation("Test", 5D, -500D, 2.3561944901923448D); xypointerannotation.setTipRadius(0.0D); xypointerannotation.setBaseRadius(35D); xypointerannotation.setFont(new Font("SansSerif", 0, 9)); xypointerannotation.setPaint(Color.blue); xypointerannotation.setTextAnchor(TextAnchor.HALF_ASCENT_RIGHT); xyplot.addAnnotation(xypointerannotation); return jfreechart; }
From source file:com.bwc.ora.views.LabelPopupMenu.java
private void initMenu() { //determine if the point clicked already has an annotation boolean hasAnnotationAlready = hasAnnoationAlready(); if (hasAnnotationAlready) { //add label to allow users to deselect the label for a given peak JMenuItem nonItem = new JMenuItem("Remove Label"); nonItem.addActionListener(e -> { removeAnnotation();//from www .j a v a2 s. co m lrp.setAnnotations(LrpDisplayFrame.getInstance().getAnnotations()); }); add(nonItem); } //add list of possible labels for a point to the popup menu Arrays.stream(RetinalBand.values()).map(RetinalBand::toString).map(label -> { XYPointerAnnotation pointer = new XYPointerAnnotation(label, item.getDataset().getXValue(item.getSeriesIndex(), item.getItem()), item.getDataset().getYValue(item.getSeriesIndex(), item.getItem()), 0); pointer.setBaseRadius(35.0); pointer.setTipRadius(10.0); pointer.setFont(new Font("SansSerif", Font.PLAIN, 9)); pointer.setPaint(Color.blue); pointer.setTextAnchor(TextAnchor.CENTER_LEFT); JMenuItem l = new JMenuItem(label); l.addActionListener(e -> { if (hasAnnotationAlready) { removeAnnotation(); } chartPanel.getChart().getXYPlot().addAnnotation(pointer); lrp.setAnnotations(LrpDisplayFrame.getInstance().getAnnotations()); }); return l; }).forEach(this::add); }
From source file:org.jfree.chart.demo.MarkerDemo1.java
/** * Creates a sample chart.//from w w w.ja va 2 s . c om * * @param data the sample data. * * @return A configured chart. */ private JFreeChart createChart(final XYDataset data) { final JFreeChart chart = ChartFactory.createScatterPlot("Marker Demo 1", "X", "Y", data, PlotOrientation.VERTICAL, true, true, false); // chart.getLegend().setAnchor(Legend.EAST); // customise... final XYPlot plot = chart.getXYPlot(); plot.getRenderer().setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); // set axis margins to allow space for marker labels... final DateAxis domainAxis = new DateAxis("Time"); domainAxis.setUpperMargin(0.50); plot.setDomainAxis(domainAxis); final ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setUpperMargin(0.30); rangeAxis.setLowerMargin(0.50); // add a labelled marker for the bid start price... final Marker start = new ValueMarker(200.0); start.setPaint(Color.green); start.setLabel("Bid Start Price"); start.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); start.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addRangeMarker(start); // add a labelled marker for the target price... final Marker target = new ValueMarker(175.0); target.setPaint(Color.red); target.setLabel("Target Price"); target.setLabelAnchor(RectangleAnchor.TOP_RIGHT); target.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); plot.addRangeMarker(target); // add a labelled marker for the original closing time... final Hour hour = new Hour(2, new Day(22, 5, 2003)); double millis = hour.getFirstMillisecond(); final Marker originalEnd = new ValueMarker(millis); originalEnd.setPaint(Color.orange); originalEnd.setLabel("Original Close (02:00)"); originalEnd.setLabelAnchor(RectangleAnchor.TOP_LEFT); originalEnd.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addDomainMarker(originalEnd); // add a labelled marker for the current closing time... final Minute min = new Minute(15, hour); millis = min.getFirstMillisecond(); final Marker currentEnd = new ValueMarker(millis); currentEnd.setPaint(Color.red); currentEnd.setLabel("Close Date (02:15)"); currentEnd.setLabelAnchor(RectangleAnchor.TOP_RIGHT); currentEnd.setLabelTextAnchor(TextAnchor.TOP_LEFT); plot.addDomainMarker(currentEnd); // **************************************************************************** // * JFREECHART DEVELOPER GUIDE * // * The JFreeChart Developer Guide, written by David Gilbert, is available * // * to purchase from Object Refinery Limited: * // * * // * http://www.object-refinery.com/jfreechart/guide.html * // * * // * Sales are used to provide funding for the JFreeChart project - please * // * support us so that we can continue developing free software. * // **************************************************************************** // label the best bid with an arrow and label... final Hour h = new Hour(2, new Day(22, 5, 2003)); final Minute m = new Minute(10, h); millis = m.getFirstMillisecond(); final CircleDrawer cd = new CircleDrawer(Color.red, new BasicStroke(1.0f), null); final XYAnnotation bestBid = new XYDrawableAnnotation(millis, 163.0, 11, 11, cd); plot.addAnnotation(bestBid); final XYPointerAnnotation pointer = new XYPointerAnnotation("Best Bid", millis, 163.0, 3.0 * Math.PI / 4.0); pointer.setBaseRadius(35.0); pointer.setTipRadius(10.0); pointer.setFont(new Font("SansSerif", Font.PLAIN, 9)); pointer.setPaint(Color.blue); pointer.setTextAnchor(TextAnchor.HALF_ASCENT_RIGHT); plot.addAnnotation(pointer); return chart; }
From source file:com.sdk.connector.chart.TimeDomainRenderer.java
public void createAnnotation(String lap, double x, double y) { final CircleDrawer cd = new CircleDrawer(Color.GREEN, new BasicStroke(1.0f), null); final XYAnnotation lapLabel = new XYDrawableAnnotation(x, y, 15, 15, cd); lapAnnotations.add(lapLabel);//from w ww.j a va2s .co m plot.addAnnotation(lapAnnotations.lastElement(), false); final XYPointerAnnotation pointer = new XYPointerAnnotation( java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("label.lap") + lap, x, y, 345); pointer.setBaseRadius(35.0); pointer.setTipRadius(10.0); pointer.setFont(new Font("DejaVu Sans", Font.BOLD, 11)); pointer.setPaint(Color.black); pointer.setTextAnchor(TextAnchor.HALF_ASCENT_RIGHT); lapAnnotations.add(pointer); plot.addAnnotation(lapAnnotations.lastElement(), false); }
From source file:org.owasp.benchmark.score.report.Scatter.java
private XYPointerAnnotation makePointer(int x, int y, String msg, TextAnchor anchor, int angle) { XYPointerAnnotation pointer = new XYPointerAnnotation(msg, x, y, Math.toRadians(angle)); pointer.setBackgroundPaint(Color.white); pointer.setTextAnchor(anchor);/*from w w w .j a v a 2 s. c om*/ pointer.setArrowWidth(4); pointer.setArrowLength(8); pointer.setArrowPaint(Color.red); pointer.setLabelOffset(2); pointer.setPaint(Color.red); pointer.setFont(theme.getRegularFont()); return pointer; }
From source file:com.sdk.connector.chart.FrequencyDomainRenderer.java
public void createAnnotation(Color color, double lap, double x, double y) { final XYPointerAnnotation pointer = new XYPointerAnnotation("", x, y, 345); pointer.setBaseRadius(35.0);//from w ww. j a v a 2s .co m pointer.setTipRadius(5.0); pointer.setFont(new Font("DejaVu Sans", Font.PLAIN, 9)); pointer.setPaint(Color.blue); pointer.setTextAnchor(TextAnchor.HALF_ASCENT_RIGHT); lapAnnotations.add(pointer); renderer.addAnnotation(lapAnnotations.lastElement()); chartPanel.repaint(); chartPanel.revalidate(); }
From source file:ch.algotrader.client.chart.ChartTab.java
@SuppressWarnings("unchecked") public void updateData(ChartDataVO chartData) { resetAxis();// w ww. java2 s. c o m // add/update indicators for (IndicatorVO indicator : chartData.getIndicators()) { RegularTimePeriod timePeriod = getRegularTimePeriod(indicator.getDateTime()); TimeSeries series = this.indicators.get(indicator.getName()); if (series != null) { series.addOrUpdate(timePeriod, indicator.getValue()); } } // add/update bars for (BarVO bar : chartData.getBars()) { OHLCSeries series = this.bars.get(bar.getSecurityId()); if (series != null) { // remove a value if it already exists RegularTimePeriod timePeriod = getRegularTimePeriod(bar.getDateTime()); if (series.indexOf(timePeriod) >= 0) { series.remove(timePeriod); } series.add(timePeriod, bar.getOpen().doubleValue(), bar.getHigh().doubleValue(), bar.getLow().doubleValue(), bar.getClose().doubleValue()); } } // make all invisible since they might not currently have a value for (Marker marker : this.markers.values()) { marker.setAlpha(0); } // update markers for (MarkerVO markerVO : chartData.getMarkers()) { Marker marker = this.markers.get(markerVO.getName()); Boolean selected = this.markersSelectionStatus.get(markerVO.getName()); String name = marker.getLabel().split(":")[0]; if (marker instanceof ValueMarker && markerVO instanceof ValueMarkerVO) { ValueMarker valueMarker = (ValueMarker) marker; ValueMarkerVO valueMarkerVO = (ValueMarkerVO) markerVO; valueMarker.setValue(valueMarkerVO.getValue()); marker.setLabel(name + ": " + valueMarkerVO.getValue()); marker.setAlpha(selected ? 1.0f : 0.0f); } else if (marker instanceof IntervalMarker && markerVO instanceof IntervalMarkerVO) { IntervalMarker intervalMarker = (IntervalMarker) marker; IntervalMarkerVO intervalMarkerVO = (IntervalMarkerVO) markerVO; intervalMarker.setStartValue(intervalMarkerVO.getStartValue()); intervalMarker.setEndValue(intervalMarkerVO.getEndValue()); marker.setLabel( name + ": " + intervalMarkerVO.getStartValue() + " - " + intervalMarkerVO.getEndValue()); marker.setAlpha(selected ? 0.5f : 0.0f); } else { throw new RuntimeException(marker.getClass() + " does not match " + markerVO.getClass()); } } // update annotations for (AnnotationVO annotationVO : chartData.getAnnotations()) { AbstractXYAnnotation annotation; if (annotationVO instanceof PointerAnnotationVO) { PointerAnnotationVO pointerAnnotationVO = (PointerAnnotationVO) annotationVO; XYPointerAnnotation pointerAnnotation = new XYPointerAnnotation(pointerAnnotationVO.getText(), pointerAnnotationVO.getDateTime().getTime(), pointerAnnotationVO.getValue(), 3.926990816987241D); pointerAnnotation.setTipRadius(0); pointerAnnotation.setBaseRadius(20); pointerAnnotation.setTextAnchor(TextAnchor.BOTTOM_RIGHT); pointerAnnotation.setFont(new Font("SansSerif", 0, 9)); pointerAnnotation.setToolTipText("<html>" + formatter.format(pointerAnnotationVO.getDateTime()) + "<br>" + pointerAnnotationVO.getValue() + "</html>"); annotation = pointerAnnotation; } else if (annotationVO instanceof BoxAnnotationVO) { BoxAnnotationVO boxAnnotationVO = (BoxAnnotationVO) annotationVO; XYBoxAnnotation boxAnnotation = new XYBoxAnnotation(boxAnnotationVO.getStartDateTime().getTime(), boxAnnotationVO.getStartValue(), boxAnnotationVO.getEndDateTime().getTime(), boxAnnotationVO.getEndValue(), null, null, new java.awt.Color(0, 0, 0, 60)); boxAnnotation.setToolTipText("<html>" + formatter.format(boxAnnotationVO.getStartDateTime()) + " - " + formatter.format(boxAnnotationVO.getEndDateTime()) + "<br>" + boxAnnotationVO.getStartValue() + " - " + boxAnnotationVO.getEndValue() + "</html>"); annotation = boxAnnotation; } else { throw new RuntimeException("unkown annotation type" + annotationVO.getClass()); } if (!getPlot().getAnnotations().contains(annotation)) { getPlot().addAnnotation(annotation); } } // update description for (Title title : (List<Title>) this.getChart().getSubtitles()) { if (title instanceof TextTitle) { TextTitle textTitle = ((TextTitle) title); if (chartData.getDescription() != null && !("".equals(chartData.getDescription()))) { textTitle.setText(chartData.getDescription()); textTitle.setVisible(true); } else { textTitle.setVisible(false); } } } initAxis(); }
From source file:info.puzz.trackprofiler.gui.TrackProfilerFrame.java
private void prepareWaypontOnChart(XYPlot xyplot, Waypoint waypoint) { Vector positions = waypoint.getPositionsOnTrack(); for (int i = 0; i < positions.size(); i++) { double position = ((Double) positions.get(i)).doubleValue(); double elevation = waypoint.getElevation(); if (position > 0 && waypoint.isVisible()) { String waypointLabel; if (TrackProfilerAppContext.getInstance().isWaypointLabelFromTitle()) { waypointLabel = waypoint.getTitle(); } else { waypointLabel = waypoint.getDescription(); }/* w ww. j a v a2 s . co m*/ double arrowAngle = Math.PI * 1.5; if (waypoint.getArrowLength() < 0) { arrowAngle += Math.PI; } XYPointerAnnotation xypointerannotation = new XYPointerAnnotation(waypointLabel, position, elevation, arrowAngle); xypointerannotation.setTipRadius(3.0D); xypointerannotation.setBaseRadius(Math.abs(waypoint.getArrowLength())); xypointerannotation.setFont(GUIConstants.SANS_SERIF_11); xypointerannotation.setPaint(Color.blue); xypointerannotation.setTextAnchor(TextAnchor.BASELINE_CENTER); xyplot.addAnnotation(xypointerannotation); ValueMarker valuemarker = new ValueMarker(position); valuemarker.setLabelOffsetType(LengthAdjustmentType.NO_CHANGE); valuemarker.setStroke(new BasicStroke(1.0F)); // TODO: u postavke da li ispisivati ovdje if (false) { valuemarker.setLabel(waypoint.getTitle()); } valuemarker.setLabelFont(GUIConstants.SANS_SERIF_11); if (waypoint instanceof TrackExtreeme) { valuemarker.setPaint(Color.blue); } else { valuemarker.setPaint(new Color(220, 220, 220)); } valuemarker.setLabelPaint(Color.red); valuemarker.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT); valuemarker.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT); // xyplot.addRangeMarker(valuemarker); xyplot.addDomainMarker(valuemarker); } } }
From source file:info.puzz.trackprofiler.gui.TrackProfilerFrame.java
private void _drawSelectedPoint(XYPlot xyplot, int position) { TrackPoint point = this.getTrack().getPointAt(position); // Strelicu crtamo samo ako je samo jedna tocka oznacena: if (this.startSelectedPoints < 0 || this.endSelectedPoints < 0 || this.startSelectedPoints == this.endSelectedPoints) { double angle = point.getAngle(); XYPointerAnnotation xypointerannotation = new XYPointerAnnotation("", point.getPosition(), //$NON-NLS-1$ point.getElevation(), Math.PI - angle); xypointerannotation.setTipRadius(3.0D); xypointerannotation.setBaseRadius(30); xypointerannotation.setTextAnchor(TextAnchor.BASELINE_RIGHT); xypointerannotation.setFont(GUIConstants.SANS_SERIF_11); if (angle > 0) { xypointerannotation.setPaint(Color.red); } else if (angle < 0) { xypointerannotation.setPaint(Color.green); } else {/*from w ww. j a va 2s . co m*/ xypointerannotation.setPaint(Color.gray); } xypointerannotation.setText((TrackProfilerMath.round(100 * angle, 1)) + " %"); //$NON-NLS-1$ xyplot.addAnnotation(xypointerannotation); } ValueMarker valuemarker = new ValueMarker(point.getPosition()); valuemarker.setLabelOffsetType(LengthAdjustmentType.NO_CHANGE); valuemarker.setStroke(new BasicStroke(1.0F)); if (this.startSelectedPoints != this.endSelectedPoints && position == this.startSelectedPoints) { valuemarker.setLabelPaint(Color.blue); valuemarker.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT); valuemarker.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT); // Ispisuje udaljenost i kut: TrackPoint t1 = this.getTrack().getPointAt(this.startSelectedPoints); TrackPoint t2 = this.getTrack().getPointAt(this.endSelectedPoints); double distance3D = TrackProfilerMath.round(t1.getPosition() - t2.getPosition(), 1); String angle = Math.abs(TrackProfilerMath.round(t1.getAngle(t2) * 100, 1)) + "%"; //$NON-NLS-1$ String label = Message.get(Messages.SELECTED_DISTANCE_LABEL) + distance3D + ", " //$NON-NLS-1$ + Message.get(Messages.SELECTED_ANGLE_LABEL) + angle; valuemarker.setLabel(" " + label); //$NON-NLS-1$ valuemarker.setLabelFont(GUIConstants.SANS_SERIF_11); } xyplot.addDomainMarker(valuemarker); }
From source file:com.chart.SwingChart.java
/** * //ww w.j a v a 2 s .c om * @param name Chart name * @param parent Skeleton parent * @param axes Configuration of axes * @param abcissaName Abcissa name */ public SwingChart(String name, final Skeleton parent, List<AxisChart> axes, String abcissaName) { this.skeleton = parent; this.axes = axes; this.name = name; this.abcissaFormat = NumberFormat.getInstance(Locale.getDefault()); this.ordinateFormat = NumberFormat.getInstance(Locale.getDefault()); plot = new XYPlot(); plot.setBackgroundPaint(scene2awtColor(javafx.scene.paint.Color.web(strChartBackgroundColor))); plot.setDomainGridlinePaint(scene2awtColor(javafx.scene.paint.Color.web(strGridlineColor))); plot.setRangeGridlinePaint(scene2awtColor(javafx.scene.paint.Color.web(strGridlineColor))); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); abcissaAxis = new NumberAxis(abcissaName); ((NumberAxis) abcissaAxis).setAutoRangeIncludesZero(false); abcissaAxis.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12)); abcissaAxis.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); abcissaAxis.setLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor))); abcissaAxis.setTickLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor))); abcissaAxis.setAutoRange(true); abcissaAxis.setLowerMargin(0.0); abcissaAxis.setUpperMargin(0.0); abcissaAxis.setTickLabelsVisible(true); abcissaAxis.setLabelFont(abcissaAxis.getLabelFont().deriveFont(fontSize)); abcissaAxis.setTickLabelFont(abcissaAxis.getLabelFont().deriveFont(fontSize)); plot.setDomainAxis(abcissaAxis); for (int i = 0; i < axes.size(); i++) { AxisChart categoria = axes.get(i); addAxis(categoria.getName()); for (int j = 0; j < categoria.configSerieList.size(); j++) { SimpleSeriesConfiguration cs = categoria.configSerieList.get(j); addSeries(categoria.getName(), cs); } } chart = new JFreeChart("", new Font("SansSerif", Font.BOLD, 16), plot, false); chart.setBackgroundPaint(scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor))); chartPanel = new ChartPanel(chart); chartPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createLineBorder(scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor))))); chartPanel.getInputMap().put(KeyStroke.getKeyStroke("ESCAPE"), "escape"); chartPanel.getActionMap().put("escape", new AbstractAction() { @Override public void actionPerformed(java.awt.event.ActionEvent e) { for (int i = 0; i < plot.getDatasetCount(); i++) { XYDataset test = plot.getDataset(i); XYItemRenderer r = plot.getRenderer(i); r.removeAnnotations(); } } }); chartPanel.addChartMouseListener(cml = new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent event) { } @Override public void chartMouseMoved(ChartMouseEvent event) { try { XYItemEntity xyitem = (XYItemEntity) event.getEntity(); // get clicked entity XYDataset dataset = (XYDataset) xyitem.getDataset(); // get data set double x = dataset.getXValue(xyitem.getSeriesIndex(), xyitem.getItem()); double y = dataset.getYValue(xyitem.getSeriesIndex(), xyitem.getItem()); final XYPlot plot = chart.getXYPlot(); for (int i = 0; i < plot.getDatasetCount(); i++) { XYDataset test = plot.getDataset(i); XYItemRenderer r = plot.getRenderer(i); r.removeAnnotations(); if (test == dataset) { NumberAxis ejeOrdenada = AxesList.get(i); double y_max = ejeOrdenada.getUpperBound(); double y_min = ejeOrdenada.getLowerBound(); double x_max = abcissaAxis.getUpperBound(); double x_min = abcissaAxis.getLowerBound(); double angulo; if (y > (y_max + y_min) / 2 && x > (x_max + x_min) / 2) { angulo = 3.0 * Math.PI / 4.0; } else if (y > (y_max + y_min) / 2 && x < (x_max + x_min) / 2) { angulo = 1.0 * Math.PI / 4.0; } else if (y < (y_max + y_min) / 2 && x < (x_max + x_min) / 2) { angulo = 7.0 * Math.PI / 4.0; } else { angulo = 5.0 * Math.PI / 4.0; } CircleDrawer cd = new CircleDrawer((Color) r.getSeriesPaint(xyitem.getSeriesIndex()), new BasicStroke(2.0f), null); //XYAnnotation bestBid = new XYDrawableAnnotation(dataset.getXValue(xyitem.getSeriesIndex(), xyitem.getItem()), dataset.getYValue(xyitem.getSeriesIndex(), xyitem.getItem()), 11, 11, cd); String txt = "X:" + abcissaFormat.format(x) + ", Y:" + ordinateFormat.format(y); XYPointerAnnotation anotacion = new XYPointerAnnotation(txt, dataset.getXValue(xyitem.getSeriesIndex(), xyitem.getItem()), dataset.getYValue(xyitem.getSeriesIndex(), xyitem.getItem()), angulo); anotacion.setTipRadius(10.0); anotacion.setBaseRadius(35.0); anotacion.setFont(new Font("SansSerif", Font.PLAIN, 10)); if (Long.parseLong((strChartBackgroundColor.replace("#", "")), 16) > 0xffffff / 2) { anotacion.setPaint(Color.black); anotacion.setArrowPaint(Color.black); } else { anotacion.setPaint(Color.white); anotacion.setArrowPaint(Color.white); } //bestBid.setPaint((Color) r.getSeriesPaint(xyitem.getSeriesIndex())); r.addAnnotation(anotacion); } } //LabelValorVariable.setSize(LabelValorVariable.getPreferredSize()); } catch (NullPointerException | ClassCastException ex) { } } }); chartPanel.setPopupMenu(null); chartPanel.setBackground(scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor))); SwingNode sn = new SwingNode(); sn.setContent(chartPanel); chartFrame = new VBox(); chartFrame.getChildren().addAll(sn, legendFrame); VBox.setVgrow(sn, Priority.ALWAYS); VBox.setVgrow(legendFrame, Priority.NEVER); chartFrame.getStylesheets().addAll(SwingChart.class.getResource("overlay-chart.css").toExternalForm()); legendFrame.setStyle("marco: " + strBackgroundColor + ";-fx-background-color: marco;"); MenuItem mi; mi = new MenuItem("Print"); mi.setOnAction((ActionEvent t) -> { print(chartFrame); }); contextMenuList.add(mi); sn.setOnMouseClicked((MouseEvent t) -> { if (menu != null) { menu.hide(); } if (t.getClickCount() == 2) { backgroundEdition(); } }); mi = new MenuItem("Copy to clipboard"); mi.setOnAction((ActionEvent t) -> { copyClipboard(chartFrame); }); contextMenuList.add(mi); mi = new MenuItem("Export values"); mi.setOnAction((ActionEvent t) -> { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Export to file"); fileChooser.getExtensionFilters() .addAll(new FileChooser.ExtensionFilter("Comma Separated Values", "*.csv")); Window w = null; try { w = parent.getScene().getWindow(); } catch (NullPointerException e) { } File file = fileChooser.showSaveDialog(w); if (file != null) { export(file); } }); contextMenuList.add(mi); chartFrame.setOnContextMenuRequested((ContextMenuEvent t) -> { if (menu != null) { menu.hide(); } menu = new ContextMenu(); menu.getItems().addAll(contextMenuList); menu.show(chartFrame, t.getScreenX(), t.getScreenY()); }); }