コード例 #1
0
 private void init() {
   ChartPanel localChartPanel = new ChartPanel(chart, true);
   localChartPanel.setBorder(
       BorderFactory.createCompoundBorder(
           BorderFactory.createEmptyBorder(4, 4, 4, 4),
           BorderFactory.createLineBorder(Color.black)));
   add(localChartPanel);
 }
コード例 #2
0
  /**
   * Constructs a new demonstration application.
   *
   * @param title the frame title.
   */
  public DynamicDataDemo3(String title) {

    super(title);

    CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time"));
    this.datasets = new TimeSeriesCollection[SUBPLOT_COUNT];

    for (int i = 0; i < SUBPLOT_COUNT; i++) {
      this.lastValue[i] = 100.0;
      TimeSeries series = new TimeSeries("Random " + i, Millisecond.class);
      this.datasets[i] = new TimeSeriesCollection(series);
      NumberAxis rangeAxis = new NumberAxis("Y" + i);
      rangeAxis.setAutoRangeIncludesZero(false);
      XYPlot subplot = new XYPlot(this.datasets[i], null, rangeAxis, new StandardXYItemRenderer());
      subplot.setBackgroundPaint(Color.lightGray);
      subplot.setDomainGridlinePaint(Color.white);
      subplot.setRangeGridlinePaint(Color.white);
      plot.add(subplot);
    }

    JFreeChart chart = new JFreeChart("Dynamic Data Demo 3", plot);
    chart.getLegend().setAnchor(Legend.EAST);
    chart.setBorderPaint(Color.black);
    chart.setBorderVisible(true);
    chart.setBackgroundPaint(Color.white);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4));
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(60000.0); // 60 seconds

    JPanel content = new JPanel(new BorderLayout());

    ChartPanel chartPanel = new ChartPanel(chart);
    content.add(chartPanel);

    JPanel buttonPanel = new JPanel(new FlowLayout());

    for (int i = 0; i < SUBPLOT_COUNT; i++) {
      JButton button = new JButton("Series " + i);
      button.setActionCommand("ADD_DATA_" + i);
      button.addActionListener(this);
      buttonPanel.add(button);
    }
    JButton buttonAll = new JButton("ALL");
    buttonAll.setActionCommand("ADD_ALL");
    buttonAll.addActionListener(this);
    buttonPanel.add(buttonAll);

    content.add(buttonPanel, BorderLayout.SOUTH);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 470));
    chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setContentPane(content);
  }
コード例 #3
0
  public static ChartPanel createBubbleChart() {
    JFreeChart jfreechart = createChart(createXYZDataset());
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    chartpanel.setBorder(BorderFactory.createEtchedBorder());

    chartpanel.setDomainZoomable(true);
    chartpanel.setRangeZoomable(true);
    return chartpanel;
  }
コード例 #4
0
  /**
   * Update background, tick and gridline colors
   *
   * @param cfg cfg[0] Background, cfg[1] Chart background, cfg[2] y cfg[3] gridline
   */
  public void updateChartColors(String[] cfg) {
    strBackgroundColor = cfg[0];
    for (Node le : legendFrame.getChildren()) {
      if (le instanceof LegendAxis) {
        le.setStyle("-fx-background-color:" + strBackgroundColor);
        ((LegendAxis) le).selected = false;
      }
    }
    chart.setBackgroundPaint(scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor)));
    chartPanel.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createEmptyBorder(4, 4, 4, 4),
            BorderFactory.createLineBorder(
                scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor)))));
    chartPanel.setBackground(scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor)));

    legendFrame.setStyle("marco: " + strBackgroundColor + ";-fx-background-color: marco;");

    strChartBackgroundColor = cfg[1];
    ;
    plot.setBackgroundPaint(scene2awtColor(javafx.scene.paint.Color.web(strChartBackgroundColor)));

    for (Node le : legendFrame.getChildren()) {
      if (le instanceof LegendAxis) {
        le.setStyle("-fx-background-color:" + strBackgroundColor);
        ((LegendAxis) le).selected = false;
        for (Node nn : ((LegendAxis) le).getChildren()) {
          if (nn instanceof Label) {
            ((Label) nn)
                .setStyle(
                    "fondo: "
                        + strChartBackgroundColor
                        + ";-fx-background-color: fondo;-fx-text-fill: ladder(fondo, white 49%, black 50%);-fx-padding:5px;-fx-background-radius: 5;-fx-font-size: "
                        + String.valueOf(fontSize)
                        + "px");
          }
        }
      }
    }

    strGridlineColor = cfg[2];
    ;
    plot.setDomainGridlinePaint(scene2awtColor(javafx.scene.paint.Color.web(strGridlineColor)));
    plot.setRangeGridlinePaint(scene2awtColor(javafx.scene.paint.Color.web(strGridlineColor)));

    strTickColor = cfg[3];
    ;
    abcissaAxis.setLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
    abcissaAxis.setTickLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
    for (NumberAxis ejeOrdenada : AxesList) {
      ejeOrdenada.setLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
      ejeOrdenada.setTickLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
    }
  }
コード例 #5
0
 @Override
 public void queryPerformed(SampleEvent e) {
   JFreeChart chart = e.getHistogram().getChart(e.getTitle());
   if (chartPanel != null) {
     chartPanel.setChart(chart);
   } else {
     chartPanel = new ChartPanel(chart);
     chartPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
     add(chartPanel, BorderLayout.CENTER);
   }
   validate();
 }
コード例 #6
0
  /**
   * A demonstration application showing a scatter plot.
   *
   * @param title the frame title.
   */
  public ScatterPlotDemo4(String title) {

    super(title);
    XYSeries series = new XYSeries("Average Weight");
    series.add(-20.0, 20.0);
    series.add(40.0, 25.0);
    series.add(55.0, 50.0);
    series.add(70.0, 65.0);
    series.add(270.0, 65.0);
    series.add(570.0, 55.0);
    XYDataset data = new XYSeriesCollection(series);
    JFreeChart chart =
        ChartFactory.createScatterPlot(
            "Scatter Plot Demo", "X", "Y", data, PlotOrientation.VERTICAL, true, true, false);
    XYPlot plot = chart.getXYPlot();
    LogElemRenderer render = new LogElemRenderer();
    render.setDotWidth(25);
    render.setDotHeight(25);
    plot.setRenderer(render);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(800, 470));

    Border border =
        BorderFactory.createCompoundBorder(
            BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createEtchedBorder());
    chartPanel.setBorder(border);
    add(chartPanel);

    JPanel dashboard = new JPanel(new BorderLayout());
    dashboard.setBorder(BorderFactory.createEmptyBorder(0, 4, 4, 4));
    // make the slider units "minutes"
    slider = new JSlider(-200, 200, 0);
    slider.setPaintLabels(true);
    slider.setMajorTickSpacing(50);
    slider.setPaintTicks(true);
    slider.addChangeListener(this);
    dashboard.add(slider);
    add(dashboard, BorderLayout.SOUTH);

    // setContentPane(chartPanel);

  }
コード例 #7
0
ファイル: DynamicDataDemo3.java プロジェクト: kylebyrne/Agora
    public MyDemoPanel() {
      super(new BorderLayout());
      lastValue = new double[3];
      CombinedDomainXYPlot combineddomainxyplot = new CombinedDomainXYPlot(new DateAxis("Time"));
      datasets = new TimeSeriesCollection[3];
      for (int i = 0; i < 3; i++) {
        lastValue[i] = 100D;
        TimeSeries timeseries = new TimeSeries("Random " + i);
        datasets[i] = new TimeSeriesCollection(timeseries);
        NumberAxis numberaxis = new NumberAxis("Y" + i);
        numberaxis.setAutoRangeIncludesZero(false);
        XYPlot xyplot = new XYPlot(datasets[i], null, numberaxis, new StandardXYItemRenderer());
        xyplot.setBackgroundPaint(Color.lightGray);
        xyplot.setDomainGridlinePaint(Color.white);
        xyplot.setRangeGridlinePaint(Color.white);
        combineddomainxyplot.add(xyplot);
      }

      JFreeChart jfreechart = new JFreeChart("Dynamic Data Demo 3", combineddomainxyplot);
      addChart(jfreechart);
      LegendTitle legendtitle = (LegendTitle) jfreechart.getSubtitle(0);
      legendtitle.setPosition(RectangleEdge.RIGHT);
      legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D));
      jfreechart.setBorderPaint(Color.black);
      jfreechart.setBorderVisible(true);
      ValueAxis valueaxis = combineddomainxyplot.getDomainAxis();
      valueaxis.setAutoRange(true);
      valueaxis.setFixedAutoRange(20000D);
      ChartUtilities.applyCurrentTheme(jfreechart);
      ChartPanel chartpanel = new ChartPanel(jfreechart);
      add(chartpanel);
      JPanel jpanel = new JPanel(new FlowLayout());
      for (int j = 0; j < 3; j++) {
        JButton jbutton1 = new JButton("Series " + j);
        jbutton1.setActionCommand("ADD_DATA_" + j);
        jbutton1.addActionListener(this);
        jpanel.add(jbutton1);
      }

      JButton jbutton = new JButton("ALL");
      jbutton.setActionCommand("ADD_ALL");
      jbutton.addActionListener(this);
      jpanel.add(jbutton);
      add(jpanel, "South");
      chartpanel.setPreferredSize(new Dimension(500, 470));
      chartpanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    }
コード例 #8
0
 public DemoPanel() {
   super(new BorderLayout());
   chart = createChart();
   chart.addProgressListener(this);
   chartPanel = new ChartPanel(chart);
   chartPanel.setPreferredSize(new Dimension(600, 270));
   chartPanel.setDomainZoomable(true);
   chartPanel.setRangeZoomable(true);
   javax.swing.border.CompoundBorder compoundborder =
       BorderFactory.createCompoundBorder(
           BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createEtchedBorder());
   chartPanel.setBorder(compoundborder);
   add(chartPanel);
   JPanel jpanel = new JPanel(new BorderLayout());
   jpanel.setPreferredSize(new Dimension(400, 60));
   jpanel.setBorder(BorderFactory.createEmptyBorder(0, 4, 4, 4));
   model = new DemoTableModel(3);
   XYPlot xyplot = (XYPlot) chart.getPlot();
   model.setValueAt(xyplot.getDataset().getSeriesKey(0), 0, 0);
   model.setValueAt(new Double("0.00"), 0, 1);
   model.setValueAt(new Double("0.00"), 0, 2);
   model.setValueAt(new Double("0.00"), 0, 3);
   model.setValueAt(new Double("0.00"), 0, 4);
   model.setValueAt(new Double("0.00"), 0, 5);
   model.setValueAt(new Double("0.00"), 0, 6);
   JTable jtable = new JTable(model);
   DateCellRenderer datecellrenderer = new DateCellRenderer(new SimpleDateFormat("HH:mm"));
   NumberCellRenderer numbercellrenderer = new NumberCellRenderer();
   jtable.getColumnModel().getColumn(1).setCellRenderer(datecellrenderer);
   jtable.getColumnModel().getColumn(2).setCellRenderer(numbercellrenderer);
   jtable.getColumnModel().getColumn(3).setCellRenderer(datecellrenderer);
   jtable.getColumnModel().getColumn(4).setCellRenderer(numbercellrenderer);
   jtable.getColumnModel().getColumn(5).setCellRenderer(datecellrenderer);
   jtable.getColumnModel().getColumn(6).setCellRenderer(numbercellrenderer);
   jpanel.add(new JScrollPane(jtable));
   slider = new JSlider(0, 100, 50);
   slider.addChangeListener(this);
   jpanel.add(slider, "South");
   add(jpanel, "South");
 }
コード例 #9
0
ファイル: XYBlockHourChart.java プロジェクト: CaoAo/BeehiveZ
  private ChartPanel getChartPanel(DefaultXYZDataset dataset, int i) {
    String key = (String) dataset.getSeriesKey(0);
    DateAxis yAxis = new DateAxis("Date");
    yAxis.setLowerMargin(0.0);
    yAxis.setUpperMargin(0.0);
    yAxis.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 1));

    NumberAxis xAxis = new NumberAxis("Hour");
    xAxis.setUpperMargin(0.0);
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setBlockWidth(1000.0 * 60.0 * 60.0 * 24.0);
    renderer.setBlockAnchor(RectangleAnchor.BOTTOM_LEFT);

    // range scaling
    PaintScale paintScale;
    if (colorSort.getValue().equals("gray")) // gray scaling
    {
      paintScale = new GrayPaintScale(0.0, maxArray[i]);
    } else {

      int color_max, color_min;
      if (colorSort.getValue().equals("red")) { // red scaling
        color_max = 0xFF33FF;
        color_min = 0xFF3300;
      } else if (colorSort.getValue().equals("blue")) { // blue scaling
        color_max = 0x0033FF;
        color_min = 0x003300;
      } else { // yellow scaling
        color_max = 0xFFFFFF;
        color_min = 0xFFFF00;
      }
      paintScale = new LookupPaintScale(0.0, maxArray[i], new Color(color_max));
      int d = Math.max((color_max - color_min) / ((int) maxArray[i] + 1), 1);
      for (int k = 0; k <= maxArray[i]; k++) {
        ((LookupPaintScale) paintScale)
            .add(new Double(k + 0.5), new Color(color_max - (k + 1) * d));
      }
    }
    renderer.setPaintScale(paintScale);

    XYPlot plot = new XYPlot(dataset, yAxis, xAxis, renderer);
    plot.setOrientation(PlotOrientation.HORIZONTAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setForegroundAlpha(0.66F);
    JFreeChart chart = new JFreeChart(key, plot);
    chart.removeLegend();
    chart.setBackgroundPaint(Color.white);

    // adding data ranges
    NumberAxis scaleAxis = new NumberAxis(null);
    scaleAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    scaleAxis.setLowerBound(0.0);
    scaleAxis.setUpperBound(maxArray[i]);
    PaintScaleLegend psl = new PaintScaleLegend(paintScale, scaleAxis);
    psl.setAxisOffset(5.0);
    psl.setPosition(RectangleEdge.BOTTOM);
    psl.setMargin(new RectangleInsets(5, 5, 5, 5));
    chart.addSubtitle(psl);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setBorder(BorderFactory.createLineBorder(Color.lightGray));
    return chartPanel;
  }
コード例 #10
0
  /**
   * @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());
        });
  }