org.jfree.chart.ChartPanel Java Examples

The following examples show how to use org.jfree.chart.ChartPanel. 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: MultipleAxisChart.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void finish(java.awt.Dimension preferredSize) {
  ChartUtilities.applyCurrentTheme(chart);

  XYPlot plot = (XYPlot) chart.getPlot();
  for (int i = 0; i < axisNum; i++) {
    XYItemRenderer renderer = plot.getRenderer(i);
    if (renderer == null)
      continue;

    renderer.setSeriesPaint(0, colors[i]);

    ValueAxis axis = plot.getRangeAxis(i);
    axis.setLabelPaint(colors[i]);
    axis.setTickLabelPaint(colors[i]);
  }

  ChartPanel chartPanel = new ChartPanel(chart);
  chartPanel.setPreferredSize(preferredSize);
  chartPanel.setDomainZoomable(true);
  chartPanel.setRangeZoomable(true);
}
 
Example #2
Source File: ChartLogics.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Find chartentities like JFreeChartEntity, AxisEntity, PlotEntity, TitleEntity, XY...
 * 
 * @param chart
 * @param mx mouse coordinates
 * @param my mouse coordinates
 * @return
 */
public static ChartEntity findChartEntity(ChartPanel chart, double mx, double my) {
  // TODO check if insets were needed
  // coordinates to find chart entities
  Insets insets = chart.getInsets();
  int x = (int) ((mx - insets.left) / chart.getScaleX());
  int y = (int) ((my - insets.top) / chart.getScaleY());

  ChartRenderingInfo info = chart.getChartRenderingInfo();
  ChartEntity entity = null;
  if (info != null) {
    EntityCollection entities = info.getEntityCollection();
    if (entities != null) {
      entity = entities.getEntity(x, y);
    }
  }
  return entity;
}
 
Example #3
Source File: ChartWriter.java    From kurento-java with Apache License 2.0 6 votes vote down vote up
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));
}
 
Example #4
Source File: IndustriesPanel.java    From computational-economy with GNU General Public License v3.0 6 votes vote down vote up
protected ChartPanel createProductionPanel(final Currency currency, final GoodType outputGoodType) {
	final TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection();

	timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
			.getNationalEconomyModel(currency).getIndustryModel(outputGoodType).outputModel.getTimeSeries());
	for (final GoodType inputGoodType : ApplicationContext.getInstance().getModelRegistry()
			.getNationalEconomyModel(currency).getIndustryModel(outputGoodType).inputModels.keySet()) {
		timeSeriesCollection
				.addSeries(ApplicationContext.getInstance().getModelRegistry().getNationalEconomyModel(currency)
						.getIndustryModel(outputGoodType).inputModels.get(inputGoodType).getTimeSeries());
	}

	final JFreeChart chart = ChartFactory.createTimeSeriesChart(outputGoodType.toString() + " Production", "Date",
			"Output", timeSeriesCollection, true, true, false);
	configureChart(chart);
	chart.addSubtitle(new TextTitle("Inputs: " + ApplicationContext.getInstance().getInputOutputModel()
			.getProductionFunction(outputGoodType).getInputGoodTypes().toString()));
	return new ChartPanel(chart);
}
 
Example #5
Source File: MouseListenerTimelapse.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
MouseListenerTimelapse( final ChartPanel panel, final int referenceTimePoint, final boolean enableReferenceTimePoint )
{
	this.panel = panel;
	this.referenceTimePoint = referenceTimePoint;
	this.enableReferenceTimePoint = enableReferenceTimePoint;
	
	if ( enableReferenceTimePoint || referenceTimePoint != -1 ) // at least show it if it is not -1
	{
		valueMarker = makeMarker( referenceTimePoint );
		
		if ( referenceTimePoint >= 0 )
		{
			((XYPlot)panel.getChart().getPlot()).addDomainMarker( valueMarker );
			markerShown = true;
		}
	}
}
 
Example #6
Source File: PanHandler.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Handles a mouse pressed event.
 *
 * @param e  the event.
 */
public void mousePressed(MouseEvent e) {
    ChartPanel panel = (ChartPanel) e.getSource();
    Plot plot = panel.getChart().getPlot();
    if (!(plot instanceof Pannable)) {
        return;  // there's nothing for us to do
    }
    Pannable pannable = (Pannable) plot;
    if (pannable.isDomainPannable() || pannable.isRangePannable()) {
        Rectangle2D screenDataArea = panel.getScreenDataArea(e.getX(),
                e.getY());
        if (screenDataArea != null && screenDataArea.contains(
                e.getPoint())) {
            this.panW = screenDataArea.getWidth();
            this.panH = screenDataArea.getHeight();
            this.panLast = e.getPoint();
            panel.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
        }
    }
    // the actual panning occurs later in the mouseDragged() method
}
 
Example #7
Source File: RegionSelectionHandler.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Handles a mouse dragged event.
 *
 * @param e  the event.
 */
public void mouseDragged(MouseEvent e) {
    if (this.lastPoint == null) {
        return;  // we never started a selection
    }
    ChartPanel panel = (ChartPanel) e.getSource();
    Point pt = e.getPoint();
    Point2D pt2 = ShapeUtilities.getPointInRectangle(pt.x, pt.y,
            panel.getScreenDataArea());
    if (pt2.distance(this.lastPoint) > 5) {
        this.selection.lineTo((float) pt2.getX(), (float) pt2.getY());
        this.lastPoint = pt2;
    }
    panel.setSelectionShape(selection);
    panel.setSelectionFillPaint(this.fillPaint);
    panel.setSelectionOutlinePaint(this.outlinePaint);
    panel.repaint();
}
 
Example #8
Source File: PanamaHitek_SingleDialChart.java    From PanamaHitek_Arduino with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void buildChart2() {
    dataset = new DefaultValueDataset(0);
    DialPlot dialplot = new DialPlot();
    dialplot.setView(0.20D, 0.0D, 0.6D, 0.3D);
    dialplot.setDataset(dataset);
    ArcDialFrame arcdialframe = new ArcDialFrame(60D, 60D);
    arcdialframe.setInnerRadius(0.6D);
    arcdialframe.setOuterRadius(0.9D);
    arcdialframe.setForegroundPaint(Color.darkGray);
    arcdialframe.setStroke(new BasicStroke(3F));
    dialplot.setDialFrame(arcdialframe);
    GradientPaint gradientpaint = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(), new Color(240, 240, 240));
    DialBackground dialbackground = new DialBackground(gradientpaint);
    dialbackground.setGradientPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
    dialplot.addLayer(dialbackground);
    StandardDialScale standarddialscale = new StandardDialScale(chartBottonLimit, chartTopLimit, 115D, -50D, majorDivisions, minorDivisions);
    standarddialscale.setTickRadius(0.88D);
    standarddialscale.setTickLabelOffset(0.07D);
    dialplot.addScale(0, standarddialscale);
    org.jfree.chart.plot.dial.DialPointer.Pin pin = new org.jfree.chart.plot.dial.DialPointer.Pin();
    pin.setRadius(0.8D);
    dialplot.addLayer(pin);
    JFreeChart jfreechart = new JFreeChart(dialplot);
    jfreechart.setTitle(chartTitle);
    add(new ChartPanel(jfreechart));
}
 
Example #9
Source File: ChartGestureMouseAdapter.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
  if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.MOUSE_WHEEL))
    return;

  if (e.getComponent() instanceof ChartPanel) {
    ChartPanel chartPanel = (ChartPanel) e.getComponent();
    ChartEntity entity = findChartEntity(chartPanel, e);
    ChartGesture.Entity gestureEntity = ChartGesture.getGestureEntity(entity);
    Button button = Button.getButton(e.getButton());

    // handle event
    handleEvent(new ChartGestureEvent(chartPanel, e, entity,
        new ChartGesture(gestureEntity, Event.MOUSE_WHEEL, button)));
  }
}
 
Example #10
Source File: CryptoSentimentGui.java    From hazelcast-jet-demos with Apache License 2.0 6 votes vote down vote up
private void startGui() {
    JFreeChart sentimentChart =
            chart("Cryptocurrency Sentiment in Tweets", "Sentiment Score", sentimentDataset, -1.0, 1.0);
    JFreeChart mentionsChart =
            chart("Mentions of Cryptocurrency in Tweets", "Tweets per Minute", mentionsDataset, 0, 100);

    JFrame frame = new JFrame();
    frame.setBackground(Color.WHITE);
    frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
    frame.setTitle("Hazelcast Jet Cryptocurrency Popularity and Sentiment");
    frame.setBounds(WINDOW_X, WINDOW_Y, WINDOW_WIDTH, WINDOW_HEIGHT);
    frame.setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.X_AXIS));
    frame.add(new ChartPanel(mentionsChart));
    frame.add(new ChartPanel(sentimentChart));
    frame.setVisible(true);
}
 
Example #11
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 #12
Source File: ChartGestureMouseAdapter.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void mouseReleased(MouseEvent e) {
  if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.RELEASED))
    return;

  if (e.getComponent() instanceof ChartPanel) {
    ChartPanel chartPanel = (ChartPanel) e.getComponent();
    ChartEntity entity = findChartEntity(chartPanel, e);
    ChartGesture.Entity gestureEntity = ChartGesture.getGestureEntity(entity);
    Button button = Button.getButton(e.getButton());

    // last gesture was dragged? keep the same chartEntity
    if (lastDragEvent != null) {
      entity = lastDragEvent.getEntity();
      gestureEntity = lastDragEvent.getGesture().getEntity();
    }
    // handle event
    handleEvent(new ChartGestureEvent(chartPanel, e, entity,
        new ChartGesture(gestureEntity, Event.RELEASED, button)));

    // reset drag
    lastDragEvent = null;
  }
}
 
Example #13
Source File: DerivedCounter.java    From mts with GNU General Public License v3.0 6 votes vote down vote up
public ChartPanel getChartPanel()
{
    ChartPanel chartPanel = new ChartPanel(null);
    chartPanel.setLayout(new javax.swing.BoxLayout(chartPanel, javax.swing.BoxLayout.Y_AXIS));
    chartPanel.setAlignmentX(java.awt.Component.LEFT_ALIGNMENT);
    chartPanel.setAlignmentY(java.awt.Component.TOP_ALIGNMENT);

    if(timeChart == null)
    {
        timeChart = getTimeChart();
    }
    chartPanel.add(new ChartPanel(timeChart));

    if(this instanceof StatValue)
    {
        if(histogramChart == null)
        {
            histogramChart = getHistogramChart();                
        }
        chartPanel.add(new ChartPanel(histogramChart));
    }
    
    return chartPanel;
}
 
Example #14
Source File: ChartLogics.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(ChartPanel myChart) {
  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
  // trick. Otherwise auto range will fail sometimes
  rangeAxis.setRange(rangeAxis.getRange());
  rangeAxis.setAutoRangeIncludesZero(true);
  myChart.restoreAutoRangeBounds();
}
 
Example #15
Source File: ChartPanelTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks that a call to the zoomOutRange() method, for a plot with more
 * than one range axis, generates just one ChartChangeEvent.
 */
public void test2502355_zoomOutRange() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X",
            "Y", dataset, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRangeAxis(1, new NumberAxis("X2"));
    ChartPanel panel = new ChartPanel(chart);
    chart.addChangeListener(this);
    this.chartChangeEvents.clear();
    panel.zoomOutRange(1.0, 2.0);
    assertEquals(1, this.chartChangeEvents.size());
}
 
Example #16
Source File: MultiTimestepRegressionExample.java    From dl4j-tutorials with MIT License 5 votes vote down vote up
/**
 * Generate an xy plot of the datasets provided.
 */
private static void plotDataset(XYSeriesCollection c) {

    String title = "Regression example";
    String xAxisLabel = "Timestep";
    String yAxisLabel = "Number of passengers";
    PlotOrientation orientation = PlotOrientation.VERTICAL;
    boolean legend = true;
    boolean tooltips = false;
    boolean urls = false;
    JFreeChart chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, c, orientation, legend, tooltips, urls);

    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();

    // Auto zoom to fit time series in initial window
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRange(true);

    JPanel panel = new ChartPanel(chart);

    JFrame f = new JFrame();
    f.add(panel);
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    f.pack();
    f.setTitle("Training Data");

    RefineryUtilities.centerFrameOnScreen(f);
    f.setVisible(true);
}
 
Example #17
Source File: MultipleAxisChart.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * A demonstration application showing how to create a time series chart
 * with multiple axes.
 *
 * @param title1 the frame title.
 * @param xaxis1 xaxis title
 * @param yaxis1 yaxis title
 * @param series1 the data
 */
public MultipleAxisChart(String title1, String xaxis1, String yaxis1, TimeSeries series1) {

  TimeSeriesCollection dataset1 = new TimeSeriesCollection();
  dataset1.addSeries(series1);

  chart = ChartFactory.createTimeSeriesChart(title1, xaxis1, yaxis1, dataset1, true, true, false);

  // chart.addSubtitle(new TextTitle("Four datasets and four range axes."));
  XYPlot plot = (XYPlot) chart.getPlot();
  plot.setOrientation(PlotOrientation.VERTICAL);

  this.setLayout(new BorderLayout());
  this.add(new ChartPanel(chart), BorderLayout.CENTER);
}
 
Example #18
Source File: ChartLogics.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(ChartPanel myChart, double dataWidth, ValueAxis axis,
    RectangleEdge axisEdge) {
  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  ChartRenderingInfo info = myChart.getChartRenderingInfo();
  Rectangle2D dataArea = info.getPlotInfo().getDataArea();

  double width2D = axis.lengthToJava2D(dataWidth, dataArea, axisEdge);

  return width2D;
}
 
Example #19
Source File: TimeSeriesChartDemo1.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * A demonstration application showing how to create a simple time series
 * chart.  This example uses monthly data.
 *
 * @param title  the frame title.
 */
public TimeSeriesChartDemo1(String title) {
    super(title);
    ChartPanel chartPanel = (ChartPanel) createDemoPanel();
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);
}
 
Example #20
Source File: PieChartDemo1.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a panel for the demo (used by SuperDemo.java).
 *
 * @return A panel.
 */
public static JPanel createDemoPanel() {
    JFreeChart chart = createChart(createDataset());
    chart.setPadding(new RectangleInsets(4, 8, 2, 2));
    ChartPanel panel = new ChartPanel(chart);
    panel.setMouseWheelEnabled(true);
    panel.setPreferredSize(new Dimension(600, 300));
    return panel;
}
 
Example #21
Source File: ChartLogics.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(ChartPanel 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 #22
Source File: BenchmarkUI.java    From doov with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    final TimeSeriesCollection dataSet = new TimeSeriesCollection();
    final TimeSeries series_doov = new TimeSeries("dOOv");
    final TimeSeries series_bareMetal = new TimeSeries("Bare Metal");
    final TimeSeries series_beanValidation = new TimeSeries("Bean Validation - HV 6.0.7");
    dataSet.addSeries(series_doov);
    dataSet.addSeries(series_bareMetal);
    dataSet.addSeries(series_beanValidation);

    final JFrame f = new JFrame();
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    f.setSize(new Dimension(1280, 1024));
    f.getContentPane().add(new ChartPanel(createTimeSeriesChart("dOOv benchmark", "time", "hits", dataSet)), BorderLayout.CENTER);
    f.setVisible(true);

    final BareMetalRunnable bareRunnable = new BareMetalRunnable();
    final DoovRunnable doovRunnable = new DoovRunnable();
    final BeanValidationRunnable beanValidationRunnable = new BeanValidationRunnable();
    new Thread(beanValidationRunnable).start();
    new Thread(bareRunnable).start();
    new Thread(doovRunnable).start();

    new Timer().schedule(new TimerTask() {
        @Override
        public void run() {
            SwingUtilities.invokeLater(() -> {
                final Second second = new Second();
                series_doov.addOrUpdate(second, doovRunnable.hits.get());
                series_bareMetal.addOrUpdate(second, bareRunnable.hits.get());
                series_beanValidation.addOrUpdate(second, beanValidationRunnable.hits.get());
            });
        }
    }, 0, 200);
}
 
Example #23
Source File: ChartLogics.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(ChartPanel myChart) {
  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  ValueAxis domainAxis = plot.getDomainAxis();

  return new Range(domainAxis.getLowerBound(), domainAxis.getUpperBound());
}
 
Example #24
Source File: MoneyPanel.java    From computational-economy with GNU General Public License v3.0 5 votes vote down vote up
protected ChartPanel createMoneyCirculationPanel() {
	final TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection();

	for (final Currency currency : Currency.values()) {
		timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
				.getNationalEconomyModel(currency).moneyCirculationModel.getTimeSeries());
	}

	final JFreeChart chart = ChartFactory.createTimeSeriesChart("Money Circulation", "Date", "Money Circulation",
			timeSeriesCollection, true, true, false);
	configureChart(chart);
	return new ChartPanel(chart);
}
 
Example #25
Source File: JThermometer.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Default constructor.
 */
public JThermometer() {
    super(new CardLayout());
    this.plot.setInsets(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    this.data = new DefaultValueDataset();
    this.plot.setDataset(this.data);
    this.chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT,
            this.plot, false);
    this.panel = new ChartPanel(this.chart);
    add(this.panel, "Panel");
    setBackground(getBackground());
}
 
Example #26
Source File: ObdDataPlotter.java    From AndrOBD with GNU General Public License v3.0 5 votes vote down vote up
/**
 * create the graphing panel
 */
public ObdDataPlotter()
{
	setLayout(new BorderLayout());
	chart = createChart(dataset);
	ChartPanel chartPanel = new ChartPanel(chart);
	chartPanel.setMouseZoomable(true, false);
	add(chartPanel, BorderLayout.CENTER);
}
 
Example #27
Source File: SingleTimestepRegressionExample.java    From dl4j-tutorials with MIT License 5 votes vote down vote up
/**
 * Generate an xy plot of the datasets provided.
 */
private static void plotDataset(XYSeriesCollection c) {

    String title = "Regression example";
    String xAxisLabel = "Timestep";
    String yAxisLabel = "Number of passengers";
    PlotOrientation orientation = PlotOrientation.VERTICAL;
    boolean legend = true;
    boolean tooltips = false;
    boolean urls = false;
    JFreeChart chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, c, orientation, legend, tooltips, urls);

    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();

    // Auto zoom to fit time series in initial window
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRange(true);

    JPanel panel = new ChartPanel(chart);

    JFrame f = new JFrame();
    f.add(panel);
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    f.pack();
    f.setTitle("Training Data");

    RefineryUtilities.centerFrameOnScreen(f);
    f.setVisible(true);
}
 
Example #28
Source File: ChartLogics.java    From 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(ChartPanel myChart) {
  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  NumberAxis axis = (NumberAxis) plot.getDomainAxis();
  // trick. Otherwise auto range will fail sometimes
  axis.setRange(axis.getRange());
  axis.setAutoRangeIncludesZero(false);
  myChart.restoreAutoDomainBounds();
}
 
Example #29
Source File: JThermometer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Default constructor.
 */
public JThermometer() {
    super(new CardLayout());
    this.plot.setInsets(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    this.data = new DefaultValueDataset();
    this.plot.setDataset(this.data);
    this.chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, 
            this.plot, false);
    this.panel = new ChartPanel(this.chart);
    add(this.panel, "Panel");
    setBackground(getBackground());
}
 
Example #30
Source File: TimeSeriesChartDemo1.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A demonstration application showing how to create a simple time series
 * chart.  This example uses monthly data.
 *
 * @param title  the frame title.
 */
public TimeSeriesChartDemo1(String title) {
    super(title);
    ChartPanel chartPanel = (ChartPanel) createDemoPanel();
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);
}