List of usage examples for org.jfree.chart JFreeChart addChangeListener
public void addChangeListener(ChartChangeListener listener)
From source file:org.jax.maanova.plot.RenderChartImageTask.java
/** * Setter for the chart//from w ww . ja va 2s . c om * @param chart the chart */ public void setChart(JFreeChart chart) { if (this.chart != null) { this.chart.removeChangeListener(this.chartChageListener); } this.chart = chart; if (chart != null) { chart.addChangeListener(this.chartChageListener); } this.renderRequestQueue.offer(new Object()); }
From source file:nextapp.echo.chart.app.ChartDisplay.java
/** * Sets the displayed <code>JFreeChart</code>. * //from w w w .java 2 s .com * param newValue the new <code>JFreeChart</code> to display */ public void setChart(JFreeChart newValue) { JFreeChart oldValue = chart; chart = newValue; if (oldValue != null) { oldValue.removeChangeListener(chartChangeListener); } if (newValue != null) { newValue.addChangeListener(chartChangeListener); } firePropertyChange(CHART_CHANGED_PROPERTY, oldValue, newValue); }
From source file:net.sf.maltcms.chromaui.msviewer.ui.panel.MassSpectrumPanel.java
private void initChartComponents() { this.sc = new XYSeriesCollection(); barDataset = new XYBarDataset(sc, barWidth); XYBarRenderer renderer = new XYBarRenderer(0.1d); StandardXYBarPainter sp = new StandardXYBarPainter(); renderer.setBarPainter(sp);// ww w. j a v a 2 s .co m renderer.setShadowVisible(false); renderer.setDrawBarOutline(false); NumberAxis intensityAxis = new NumberAxis("intensity"); intensityAxis.setNumberFormatOverride(defaultNumberFormat); intensityAxis.setUpperMargin(0.10d); NumberAxis mzAxis = new NumberAxis("m/z"); mzAxis.setAutoRangeIncludesZero(false); this.plot = new XYPlot(barDataset, mzAxis, intensityAxis, renderer); this.plot.setForegroundAlpha(0.85f); plot.setDomainCrosshairLockedOnData(true); plot.setDomainCrosshairVisible(true); ((XYBarRenderer) plot.getRenderer()).setShadowVisible(false); ((XYBarRenderer) plot.getRenderer()).setDrawBarOutline(false); ((XYBarRenderer) plot.getRenderer()).setBaseFillPaint(Color.RED); ((XYBarRenderer) plot.getRenderer()).setBarPainter(new StandardXYBarPainter()); plot.getRenderer().setBaseItemLabelsVisible(true); plot.getRenderer().setBaseToolTipGenerator(new XYToolTipGenerator() { @Override public String generateToolTip(XYDataset xyd, int i, int i1) { Comparable comp = xyd.getSeriesKey(i); double x = xyd.getXValue(i, i1); double y = xyd.getYValue(i, i1); StringBuilder sb = new StringBuilder(); sb.append(comp); sb.append(": "); sb.append("x="); sb.append(String.format("%.4f", x)); sb.append(" y="); sb.append(String.format("%.4f", y)); return sb.toString(); } }); plot.setDomainPannable(true); plot.setRangePannable(true); sc.addChangeListener(plot); JFreeChart msChart = new JFreeChart(this.plot); msChart.addChangeListener(this.defaultNumberFormat); // System.out.println("Creating ms chart 3"); this.cp = new ContextAwareChartPanel(msChart, true, true, true, true, true); this.cp.setInitialDelay(1); this.cp.getChart().getLegend().setVisible(true); this.cp.setMouseWheelEnabled(true); this.clearActionPerformed(null); this.jPanel2.removeAll(); this.jPanel2.add(cp); this.jPanel2.repaint(); this.massLabelsSpinner.setValue(topK); }
From source file:apidemo.PanScrollZoomDemo.java
/** * Creates a new demo instance./*from ww w . ja va 2 s .c o m*/ * * @param frameTitle the frame title. */ public PanScrollZoomDemo(final String frameTitle) { super(frameTitle); this.toolBar = createToolbar(); getContentPane().setLayout(new BorderLayout()); getContentPane().add(this.toolBar, BorderLayout.SOUTH); final JFreeChart chart = createChart(); this.scrollBar.setModel(new DefaultBoundedRangeModel()); recalcScrollBar(chart.getPlot()); this.chartPanel = new ChartPanel(chart) { public void autoRangeBoth() { System.out.println("Use 'Fit all' button"); } }; chart.addChangeListener(this); // enable zoom actionPerformed(new ActionEvent(this, 0, ACTION_CMD_ZOOM_BOX)); // MouseListeners for pan function this.chartPanel.addMouseListener(this); // this.chartPanel.addMouseMotionListener(this); // remove popup menu to allow panning // with right mouse pressed this.chartPanel.setPopupMenu(null); getContentPane().add(this.chartPanel); }
From source file:org.yccheok.jstock.gui.charting.ChartJDialog.java
/** * Creates a chart.// w w w .j a v a 2 s. com * * @param dataset the dataset. * * @return The dataset. */ private JFreeChart createCandlestickChart(OHLCDataset priceOHLCDataset) { final String title = getBestStockName(); final ValueAxis timeAxis = new DateAxis(GUIBundle.getString("ChartJDialog_Date")); final NumberAxis valueAxis = new NumberAxis(GUIBundle.getString("ChartJDialog_Price")); valueAxis.setAutoRangeIncludesZero(false); valueAxis.setUpperMargin(0.0); valueAxis.setLowerMargin(0.0); XYPlot plot = new XYPlot(priceOHLCDataset, timeAxis, valueAxis, null); final CandlestickRenderer candlestickRenderer = new CandlestickRenderer(); plot.setRenderer(candlestickRenderer); // Give good width when zoom in, but too slow in calculation. ((CandlestickRenderer) plot.getRenderer()).setAutoWidthMethod(CandlestickRenderer.WIDTHMETHOD_SMALLEST); CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(timeAxis); cplot.add(plot, 3); cplot.setGap(8.0); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, cplot, true); org.yccheok.jstock.charting.Utils.applyChartThemeEx(chart); // Handle zooming event. chart.addChangeListener(this.getChartChangeListner()); return chart; }
From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.diagnostics.ApproximationSetViewer.java
/** * Updates the display. This method must only be invoked on the event * dispatch thread./* ww w . java 2 s . c om*/ */ protected void update() { XYSeriesCollection dataset = new XYSeriesCollection(); //generate approximation set for (int seedIndex : seedList.getSelectedIndices()) { Accumulator accumulator = accumulators.get(seedIndex); int index = 0; if (!accumulator.keySet().contains("Approximation Set")) { continue; } while ((index < accumulator.size("NFE") - 1) && ((Integer) accumulator.get("NFE", index) < slider.getValue())) { index++; } List<?> list = (List<?>) accumulator.get("Approximation Set", index); XYSeries series = new XYSeries(localization.getString("text.seed", seedIndex + 1), false, true); for (Object object : list) { Solution solution = (Solution) object; series.add(getValue(solution, 0), getValue(solution, 1)); } dataset.addSeries(series); } //generate reference set if (referenceSet != null) { XYSeries series = new XYSeries(localization.getString("text.referenceSet"), false, true); for (Solution solution : referenceSet) { series.add(getValue(solution, 0), getValue(solution, 1)); } dataset.addSeries(series); } JFreeChart chart = ChartFactory.createScatterPlot(getTitle() + " @ " + slider.getValue() + " NFE", (String) xAxisSelection.getSelectedItem(), (String) yAxisSelection.getSelectedItem(), dataset, PlotOrientation.VERTICAL, true, true, false); //set the renderer to only display shapes XYPlot plot = chart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true); for (int i = 0; i < dataset.getSeriesCount(); i++) { Paint paint = paintHelper.get(dataset.getSeriesKey(i)); renderer.setSeriesPaint(i, paint); } plot.setRenderer(renderer); //set the zoom based on the user's preferences if ((initialRangeBounds == null) || (initialDomainBounds == null)) { initialRangeBounds = plot.getRangeAxis().getRange(); initialDomainBounds = plot.getDomainAxis().getRange(); } if (useInitialBounds.isSelected()) { plot.getRangeAxis().setRange(initialRangeBounds); plot.getDomainAxis().setRange(initialDomainBounds); } else if (useZoomBounds.isSelected()) { if ((zoomRangeBounds == null) || (zoomDomainBounds == null)) { zoomRangeBounds = initialRangeBounds; zoomDomainBounds = initialDomainBounds; } plot.getRangeAxis().setRange(zoomRangeBounds); plot.getDomainAxis().setRange(zoomDomainBounds); } else if (useReferenceSetBounds.isSelected()) { if (referenceRangeBounds.getLength() > 0.0) { plot.getRangeAxis().setRange(referenceRangeBounds); } if (referenceDomainBounds.getLength() > 0.0) { plot.getDomainAxis().setRange(referenceDomainBounds); } } //register with the chart to receive zoom events chart.addChangeListener(this); chartContainer.removeAll(); chartContainer.add(new ChartPanel(chart), BorderLayout.CENTER); chartContainer.revalidate(); chartContainer.repaint(); }
From source file:org.yccheok.jstock.gui.charting.ChartJDialog.java
/** * Creates a chart.// w w w .j a v a 2s . c o m * * @return a chart. */ private JFreeChart createPriceVolumeChart(XYDataset priceDataset, XYDataset volumeDataset) { final String title = getBestStockName(); final ValueAxis timeAxis = new DateAxis(GUIBundle.getString("ChartJDialog_Date")); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02); final NumberAxis rangeAxis1 = new NumberAxis(GUIBundle.getString("ChartJDialog_Price")); rangeAxis1.setAutoRangeIncludesZero(false); // override default rangeAxis1.setLowerMargin(0.40); // to leave room for volume bars DecimalFormat format = new DecimalFormat("0.00#"); rangeAxis1.setNumberFormatOverride(format); XYPlot plot = new XYPlot(priceDataset, timeAxis, rangeAxis1, null); XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false); renderer1.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00#"))); plot.setRenderer(0, renderer1); final NumberAxis rangeAxis2 = new NumberAxis("Volume"); rangeAxis2.setUpperMargin(1.00); // to leave room for price line plot.setRangeAxis(1, rangeAxis2); plot.setDataset(1, volumeDataset); plot.mapDatasetToRangeAxis(1, 1); XYBarRenderer renderer2 = new XYBarRenderer(0.20); renderer2.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0,000.00"))); plot.setRenderer(1, renderer2); CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(timeAxis); cplot.add(plot, 1); cplot.setGap(8.0); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, cplot, true); org.yccheok.jstock.charting.Utils.applyChartThemeEx(chart); // Only do it after applying chart theme. org.yccheok.jstock.charting.Utils.setPriceSeriesPaint(renderer1); org.yccheok.jstock.charting.Utils.setVolumeSeriesPaint(renderer2); // Handle zooming event. chart.addChangeListener(this.getChartChangeListner()); return chart; }