org.jfree.chart.fx.ChartViewer Java Examples

The following examples show how to use org.jfree.chart.fx.ChartViewer. 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: ChartLogicsFX.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Zoom in (negative yzoom) or zoom out of range axis.
 * 
 * @param myChart
 * @param yzoom percentage zoom factor
 * @param holdLowerBound if true only the upper bound will be zoomed
 */
public static void zoomRangeAxis(ChartViewer myChart, double yzoom, boolean holdLowerBound) {
  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  ValueAxis rangeAxis = plot.getRangeAxis();

  double lower = rangeAxis.getLowerBound();
  double upper = rangeAxis.getUpperBound();
  double dist = upper - lower;

  if (holdLowerBound) {
    upper += dist * yzoom;
  } else {
    lower -= dist * yzoom / 2;
    upper += dist * yzoom / 2;
  }

  if (lower < upper) {
    Range range = new Range(lower, upper);
    setZoomAxis(rangeAxis, keepRangeWithinAutoBounds(rangeAxis, range));
  }
}
 
Example #2
Source File: ChartLogicsFX.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Zoom in (negative yzoom) or zoom out of range axis.
 * 
 * @param myChart
 * @param yzoom percentage zoom factor
 * @param holdLowerBound if true only the upper bound will be zoomed
 */
public static void zoomRangeAxis(ChartViewer myChart, double yzoom, boolean holdLowerBound) {
  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  ValueAxis rangeAxis = plot.getRangeAxis();

  double lower = rangeAxis.getLowerBound();
  double upper = rangeAxis.getUpperBound();
  double dist = upper - lower;

  if (holdLowerBound) {
    upper += dist * yzoom;
  } else {
    lower -= dist * yzoom / 2;
    upper += dist * yzoom / 2;
  }

  if (lower < upper) {
    Range range = new Range(lower, upper);
    setZoomAxis(rangeAxis, keepRangeWithinAutoBounds(rangeAxis, range));
  }
}
 
Example #3
Source File: ChartLogicsFX.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Zoom in (negative yzoom) or zoom out of range axis.
 * 
 * @param myChart
 * @param yzoom percentage zoom factor
 * @param holdLowerBound if true only the upper bound will be zoomed
 */
public static void zoomRangeAxis(ChartViewer myChart, double yzoom, boolean holdLowerBound) {
  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  ValueAxis rangeAxis = plot.getRangeAxis();

  double lower = rangeAxis.getLowerBound();
  double upper = rangeAxis.getUpperBound();
  double dist = upper - lower;

  if (holdLowerBound) {
    upper += dist * yzoom;
  } else {
    lower -= dist * yzoom / 2;
    upper += dist * yzoom / 2;
  }

  if (lower < upper) {
    Range range = new Range(lower, upper);
    setZoomAxis(rangeAxis, keepRangeWithinAutoBounds(rangeAxis, range));
  }
}
 
Example #4
Source File: JFreeChartUtils.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
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());
      }
    });
  }
 
Example #5
Source File: ChartLogicsFX.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Data width to pixel width on screen
 * 
 * @param myChart
 * @param dataWidth width of data
 * @param axis for width calculation
 * @return
 */
public static double calcWidthOnScreen(ChartViewer myChart, double dataWidth, ValueAxis axis,
    RectangleEdge axisEdge) {
  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  ChartRenderingInfo info = myChart.getRenderingInfo();
  Rectangle2D dataArea = info.getPlotInfo().getDataArea();

  // width 2D
  return axis.lengthToJava2D(dataWidth, dataArea, axisEdge);
}
 
Example #6
Source File: ChartLogicsFX.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 
 * @param ChartViewer
 * @return
 */
// TODO
public static boolean isMouseZoomable(ChartViewer chart) {
  // return chartPanel instanceof EChartPanel ? ((EChartPanel) chartPanel).isMouseZoomable()
  // : chartPanel.isRangeZoomable() && chartPanel.isDomainZoomable();
  return chart.getCanvas().isRangeZoomable() && chart.getCanvas().isDomainZoomable();
}
 
Example #7
Source File: ChartLogicsFX.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Move a chart by a percentage x-offset if xoffset is <0 the shift will be negativ (xoffset>0
 * results in a positive shift)
 * 
 * @param myChart
 * @param xoffset in percent
 * @param autoRangeY if true the range (Y) axis auto bounds will be restored
 */
public static void offsetDomainAxis(ChartViewer myChart, double xoffset, boolean autoRangeY) {
  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  ValueAxis domainAxis = plot.getDomainAxis();
  // apply offset on x
  double distance = (domainAxis.getUpperBound() - domainAxis.getLowerBound()) * xoffset;

  Range range =
      new Range(domainAxis.getLowerBound() + distance, domainAxis.getUpperBound() + distance);
  setZoomDomainAxis(myChart, keepRangeWithinAutoBounds(domainAxis, range), autoRangeY);
}
 
Example #8
Source File: ChartLogicsFX.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Auto range the range axis
 * 
 * @param myChart
 * @param zoom
 * @param autoRangeY if true the range (Y) axis auto bounds will be restored
 */
public static void autoDomainAxis(ChartViewer myChart) {
  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  if (plot instanceof Zoomable) {
    Zoomable z = plot;
    Point2D endPoint = new Point2D.Double(0, 0);
    PlotRenderingInfo pri = myChart.getRenderingInfo().getPlotInfo();
    z.zoomDomainAxes(0, pri, endPoint);
  }
}
 
Example #9
Source File: ChartLogicsFX.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Auto range the range axis
 * 
 * @param myChart
 * @param zoom
 * @param autoRangeY if true the range (Y) axis auto bounds will be restored
 */
public static void autoRangeAxis(ChartViewer myChart) {
  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  if (plot instanceof Zoomable) {
    Zoomable z = plot;
    Point2D endPoint = new Point2D.Double(0, 0);
    PlotRenderingInfo pri = myChart.getRenderingInfo().getPlotInfo();
    z.zoomRangeAxes(0, pri, endPoint);
  }
}
 
Example #10
Source File: ChartLogicsFX.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Zoom into a chart panel
 * 
 * @param myChart
 * @param zoom
 * @param autoRangeY if true the range (Y) axis auto bounds will be restored
 */
public static void setZoomDomainAxis(ChartViewer myChart, Range zoom, boolean autoRangeY) {
  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  ValueAxis domainAxis = plot.getDomainAxis();
  setZoomAxis(domainAxis, keepRangeWithinAutoBounds(domainAxis, zoom));

  if (autoRangeY) {
    autoRangeAxis(myChart);
  }
}
 
Example #11
Source File: ChartLogicsFX.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Calculates the size of a chart for a given fixed plot width Domain and Range axes need to share
 * the same unit (e.g. mm)
 * 
 * @param chart
 * @param plotWidth
 * @return
 */
public static Dimension calcSizeForPlotWidth(ChartViewer myChart, double plotWidth,
    int iterations) {
  // ranges
  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  ValueAxis domainAxis = plot.getDomainAxis();
  Range x = domainAxis.getRange();
  ValueAxis rangeAxis = plot.getRangeAxis();
  Range y = rangeAxis.getRange();

  // plot height is fixed
  double plotHeight = plotWidth / x.getLength() * y.getLength();
  return calcSizeForPlotSize(myChart, plotWidth, plotHeight, iterations);
}
 
Example #12
Source File: ChartLogicsFX.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Translates screen (pixel) values to plot values
 * 
 * @param myChart
 * @return width in data space for x and y
 */
public static Point2D screenValueToPlotValue(ChartViewer myChart, int val) {
  Point2D p = mouseXYToPlotXY(myChart, 0, 0);
  Point2D p2 = mouseXYToPlotXY(myChart, val, val);
  // inverted y
  return new Point2D.Double(p2.getX() - p.getX(), p.getY() - p2.getY());
}
 
Example #13
Source File: PieChartFXDemo1.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
@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(); 
}
 
Example #14
Source File: ChartLogicsFX.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Apply an absolute offset to domain (x) axis and move it
 * 
 * @param myChart
 * @param xoffset
 * @param autoRangeY
 */
public static void offsetDomainAxisAbsolute(ChartViewer myChart, double xoffset,
    boolean autoRangeY) {
  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  ValueAxis domainAxis = plot.getDomainAxis();
  // apply offset on x

  Range range =
      new Range(domainAxis.getLowerBound() + xoffset, domainAxis.getUpperBound() + xoffset);
  setZoomDomainAxis(myChart, keepRangeWithinAutoBounds(domainAxis, range), autoRangeY);
}
 
Example #15
Source File: TimeSeriesChartFXDemo1.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
@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();
}
 
Example #16
Source File: ChartLogicsFX.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 
 * Domain and Range axes need to share the same unit (e.g. mm)
 * 
 * @param myChart
 * @return
 */
public static double calcWidthToHeight(ChartViewer myChart, double chartHeight) {
  makeChartResizable(myChart);

  myChart.getCanvas().draw();

  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  ChartRenderingInfo info = myChart.getRenderingInfo();
  Rectangle2D dataArea = info.getPlotInfo().getDataArea();
  Rectangle2D chartArea = info.getChartArea();


  // calc title space: will be added later to the right plot size
  double titleWidth = chartArea.getWidth() - dataArea.getWidth();
  double titleHeight = chartArea.getHeight() - dataArea.getHeight();

  // calc right plot size with axis dim.
  // real plot width is given by factor;
  double realPH = chartHeight - titleHeight;

  // ranges
  ValueAxis domainAxis = plot.getDomainAxis();
  org.jfree.data.Range x = domainAxis.getRange();
  ValueAxis rangeAxis = plot.getRangeAxis();
  org.jfree.data.Range y = rangeAxis.getRange();

  // real plot height can be calculated by
  double realPW = realPH / y.getLength() * x.getLength();

  double width = realPW + titleWidth;

  return width;
}
 
Example #17
Source File: ChartLogicsFX.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 
 * @param myChart
 * @return Range the domainAxis zoom (X-axis)
 */
public static Range getZoomDomainAxis(ChartViewer myChart) {
  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  ValueAxis domainAxis = plot.getDomainAxis();

  return new Range(domainAxis.getLowerBound(), domainAxis.getUpperBound());
}
 
Example #18
Source File: ChartLogicsFX.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Auto range the range axis
 * 
 * @param myChart
 * @param zoom
 * @param autoRangeY if true the range (Y) axis auto bounds will be restored
 */
public static void autoAxes(ChartViewer myChart) {
  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  if (plot instanceof Zoomable) {
    Zoomable z = plot;
    Point2D endPoint = new Point2D.Double(0, 0);
    PlotRenderingInfo pri = myChart.getRenderingInfo().getPlotInfo();
    boolean saved = plot.isNotify();
    plot.setNotify(false);
    z.zoomDomainAxes(0, pri, endPoint);
    z.zoomRangeAxes(0, pri, endPoint);
    plot.setNotify(saved);
  }
}
 
Example #19
Source File: ChartLogicsFX.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Zoom into a chart panel
 * 
 * @param myChart
 * @param zoom
 * @param autoRangeY if true the range (Y) axis auto bounds will be restored
 */
public static void setZoomDomainAxis(ChartViewer myChart, Range zoom, boolean autoRangeY) {
  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  ValueAxis domainAxis = plot.getDomainAxis();
  setZoomAxis(domainAxis, keepRangeWithinAutoBounds(domainAxis, zoom));

  if (autoRangeY) {
    autoRangeAxis(myChart);
  }
}
 
Example #20
Source File: TimeSeriesChartFXDemo1.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
@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();
}
 
Example #21
Source File: ChartLogicsFX.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Auto range the range axis
 * 
 * @param myChart
 * @param zoom
 * @param autoRangeY if true the range (Y) axis auto bounds will be restored
 */
public static void autoDomainAxis(ChartViewer myChart) {
  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  if (plot instanceof Zoomable) {
    Zoomable z = plot;
    Point2D endPoint = new Point2D.Double(0, 0);
    PlotRenderingInfo pri = myChart.getRenderingInfo().getPlotInfo();
    z.zoomDomainAxes(0, pri, endPoint);
  }
}
 
Example #22
Source File: ChartLogicsFX.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 
 * @param myChart
 * @return Range the domainAxis zoom (X-axis)
 */
public static Range getZoomDomainAxis(ChartViewer myChart) {
  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  ValueAxis domainAxis = plot.getDomainAxis();

  return new Range(domainAxis.getLowerBound(), domainAxis.getUpperBound());
}
 
Example #23
Source File: ChartLogicsFX.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Data width to pixel width on screen
 * 
 * @param myChart
 * @param dataWidth width of data
 * @param axis for width calculation
 * @return
 */
public static double calcWidthOnScreen(ChartViewer myChart, double dataWidth, ValueAxis axis,
    RectangleEdge axisEdge) {
  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  ChartRenderingInfo info = myChart.getRenderingInfo();
  Rectangle2D dataArea = info.getPlotInfo().getDataArea();

  // width 2D
  return axis.lengthToJava2D(dataWidth, dataArea, axisEdge);
}
 
Example #24
Source File: PieChartFXDemo1.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
@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(); 
}
 
Example #25
Source File: ChartLogicsFX.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Calculates the size of a chart for a given fixed plot width Domain and Range axes need to share
 * the same unit (e.g. mm)
 * 
 * @param chart
 * @param plotWidth
 * @return
 */
public static Dimension calcSizeForPlotWidth(ChartViewer myChart, double plotWidth,
    int iterations) {
  // ranges
  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  ValueAxis domainAxis = plot.getDomainAxis();
  Range x = domainAxis.getRange();
  ValueAxis rangeAxis = plot.getRangeAxis();
  Range y = rangeAxis.getRange();

  // plot height is fixed
  double plotHeight = plotWidth / x.getLength() * y.getLength();
  return calcSizeForPlotSize(myChart, plotWidth, plotHeight, iterations);
}
 
Example #26
Source File: TimeSeriesChartFXDemo1.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
@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();
}
 
Example #27
Source File: PieChartFXDemo1.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
@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(); 
}
 
Example #28
Source File: BarChartFXDemo1.java    From jfree-fxdemos with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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(); 
}
 
Example #29
Source File: PieChartFXDemo1.java    From jfree-fxdemos with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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(); 
}
 
Example #30
Source File: ChartLogicsFX.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 
 * @param ChartViewer
 * @return
 */
// TODO
public static boolean isMouseZoomable(ChartViewer chart) {
  // return chartPanel instanceof EChartPanel ? ((EChartPanel) chartPanel).isMouseZoomable()
  // : chartPanel.isRangeZoomable() && chartPanel.isDomainZoomable();
  return chart.getCanvas().isRangeZoomable() && chart.getCanvas().isDomainZoomable();
}