List of usage examples for org.jfree.chart ChartPanel setRefreshBuffer
public void setRefreshBuffer(boolean flag)
From source file:nextapp.echo.chart.testapp.testscreen.PieChartTest.java
public PieChartTest() { super(SplitPane.ORIENTATION_HORIZONTAL, new Extent(250, Extent.PX)); setStyleName("DefaultResizable"); ButtonColumn controlsColumn = new ButtonColumn(); controlsColumn.setStyleName("TestControlsColumn"); add(controlsColumn);//from w w w . ja va 2 s . c o m DefaultKeyedValues values = new DefaultKeyedValues(); values.addValue("Widgets", 500.2); values.addValue("Cubits", 216.0); values.addValue("Zonkits", 125.9); final DefaultPieDataset pieDataset = new DefaultPieDataset(new DefaultPieDataset(values)); PiePlot piePlot = new PiePlot(pieDataset); piePlot.setToolTipGenerator(new StandardPieToolTipGenerator()); final ChartDisplay chartDisplay = new ChartDisplay(piePlot); add(chartDisplay); chartDisplay.setActionCommands(new String[] { "Widgets", "Cubits", "Zonkits" }); chartDisplay.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { WindowPane window = new WindowPane("Chart series clicked", new Extent(300), new Extent(200)); window.add(new Label("You clicked on " + arg0.getActionCommand())); Component contentPane = getParent(); while (!(contentPane instanceof ContentPane)) { contentPane = contentPane.getParent(); } contentPane.add(window); } }); ChartPanel chartPanel = new ChartPanel(new JFreeChart(piePlot)); chartPanel.setRefreshBuffer(true); ChartEntity entity = chartPanel.getEntityForPoint(50, 50); System.out.println("Entity: " + entity); controlsColumn.addButton("Set Width = 800px", new ActionListener() { public void actionPerformed(ActionEvent e) { synchronized (chartDisplay) { chartDisplay.setWidth(new Extent(800)); } } }); controlsColumn.addButton("Set Width = null", new ActionListener() { public void actionPerformed(ActionEvent e) { synchronized (chartDisplay) { chartDisplay.setWidth(null); } } }); controlsColumn.addButton("Set Height = 600px", new ActionListener() { public void actionPerformed(ActionEvent e) { synchronized (chartDisplay) { chartDisplay.setHeight(new Extent(600)); } } }); controlsColumn.addButton("Set Height = null", new ActionListener() { public void actionPerformed(ActionEvent e) { synchronized (chartDisplay) { chartDisplay.setHeight(null); } } }); controlsColumn.addButton("Update a Value", new ActionListener() { public void actionPerformed(ActionEvent e) { synchronized (chartDisplay) { pieDataset.setValue("Cubits", Math.random() * 500); } } }); }
From source file:org.trade.ui.chart.CandlestickChart.java
/** * A demonstration application showing a candlestick chart. * //from w w w . jav a2 s . co m * @param title * the frame title. * @param strategyData * StrategyData */ public CandlestickChart(final String title, StrategyData strategyData, Tradingday tradingday) { this.strategyData = strategyData; this.setLayout(new BorderLayout()); // Used to mark the current price stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 10, 3 }, 0); valueMarker = new ValueMarker(0.00, Color.black, stroke); this.chart = createChart(this.strategyData, title, tradingday); BlockContainer container = new BlockContainer(new BorderArrangement()); container.add(titleLegend1, RectangleEdge.LEFT); container.add(titleLegend2, RectangleEdge.RIGHT); container.add(new EmptyBlock(2000, 0)); CompositeTitle legends = new CompositeTitle(container); legends.setPosition(RectangleEdge.BOTTOM); this.chart.addSubtitle(legends); final ChartPanel chartPanel = new ChartPanel(this.chart); chartPanel.setFillZoomRectangle(true); chartPanel.setMouseZoomable(true, true); chartPanel.setRefreshBuffer(true); chartPanel.setDoubleBuffered(true); chartPanel.setVerticalAxisTrace(true); chartPanel.setHorizontalAxisTrace(true); chartPanel.addChartMouseListener(new ChartMouseListener() { public void chartMouseMoved(ChartMouseEvent e) { } public void chartMouseClicked(final ChartMouseEvent e) { CombinedDomainXYPlot combinedXYplot = (CombinedDomainXYPlot) e.getChart().getPlot(); @SuppressWarnings("unchecked") List<XYPlot> subplots = combinedXYplot.getSubplots(); if (e.getTrigger().getClickCount() == 2) { double xItem = 0; double yItem = 0; if (e.getEntity() instanceof XYItemEntity) { XYItemEntity xYItemEntity = ((XYItemEntity) e.getEntity()); xItem = xYItemEntity.getDataset().getXValue(xYItemEntity.getSeriesIndex(), xYItemEntity.getItem()); yItem = xYItemEntity.getDataset().getYValue(xYItemEntity.getSeriesIndex(), xYItemEntity.getItem()); } else { PlotEntity plotEntity = ((PlotEntity) e.getEntity()); XYPlot plot = (XYPlot) plotEntity.getPlot(); xItem = plot.getDomainCrosshairValue(); yItem = plot.getRangeCrosshairValue(); } for (XYPlot xyplot : subplots) { double x = xyplot.getDomainCrosshairValue(); double y = xyplot.getRangeCrosshairValue(); /* * If the cross hair is from a right-hand y axis we need * to convert this to a left-hand y axis. */ String rightAxisName = ", Price: "; double rangeLowerLeft = 0; double rangeUpperLeft = 0; double rangeLowerRight = 0; double rangeUpperRight = 0; double yRightLocation = 0; for (int index = 0; index < xyplot.getRangeAxisCount(); index++) { AxisLocation axisLocation = xyplot.getRangeAxisLocation(index); Range range = xyplot.getRangeAxis(index).getRange(); if (axisLocation.equals(AxisLocation.BOTTOM_OR_LEFT) || axisLocation.equals(AxisLocation.TOP_OR_LEFT)) { rangeLowerLeft = range.getLowerBound(); rangeUpperLeft = range.getUpperBound(); rightAxisName = ", " + xyplot.getRangeAxis(index).getLabel() + ": "; } if (y >= range.getLowerBound() && y <= range.getUpperBound() && (axisLocation.equals(AxisLocation.BOTTOM_OR_RIGHT) || axisLocation.equals(AxisLocation.TOP_OR_RIGHT))) { rangeUpperRight = range.getUpperBound(); rangeLowerRight = range.getLowerBound(); } } if ((rangeUpperRight - rangeLowerRight) > 0) { yRightLocation = rangeLowerLeft + ((rangeUpperLeft - rangeLowerLeft) * ((y - rangeLowerRight) / (rangeUpperRight - rangeLowerRight))); } else { yRightLocation = y; } String text = " Time: " + dateFormatShort.format(new Date((long) (x))) + rightAxisName + new Money(y); if (x == xItem && y == yItem) { titleLegend1.setText(text); if (null == clickCrossHairs) { clickCrossHairs = new XYTextAnnotation(text, x, yRightLocation); clickCrossHairs.setTextAnchor(TextAnchor.BOTTOM_LEFT); xyplot.addAnnotation(clickCrossHairs); } else { clickCrossHairs.setText(text); clickCrossHairs.setX(x); clickCrossHairs.setY(yRightLocation); } } } } else if (e.getTrigger().getClickCount() == 1 && null != clickCrossHairs) { for (XYPlot xyplot : subplots) { if (xyplot.removeAnnotation(clickCrossHairs)) { clickCrossHairs = null; titleLegend1.setText(" Time: 0, Price :0.0"); break; } } } } }); this.add(chartPanel, null); this.strategyData.getCandleDataset().getSeries(0).addChangeListener(this); }
From source file:net.sf.maltcms.chromaui.chromatogram1Dviewer.ui.Chromatogram1DHeatmapViewTopComponent.java
private Chromatogram1DHeatmapViewerPanel createPanel(ADataset2D<IChromatogram1D, IScan> ds) { XYPlot p = createPlot(ds);// w w w . jav a2 s. com final PaintScale ps = ((XYBlockRenderer) p.getRenderer()).getPaintScale(); p.setDomainGridlinesVisible(false); p.setRangeGridlinesVisible(false); JFreeChart jfc = new JFreeChart(p); final ChartPanel cp = new ChartPanel(jfc, true); cp.setZoomFillPaint(new Color(192, 192, 192, 96)); cp.setZoomOutlinePaint(new Color(220, 220, 220, 192)); cp.setFillZoomRectangle(false); cp.getChart().getLegend().setVisible(true); Chromatogram1DHeatmapViewerPanel panel = new Chromatogram1DHeatmapViewerPanel(content, getLookup(), ds); if (panel.getBackgroundColor() == null) { panel.setBackgroundColor((Color) ps.getPaint(ps.getLowerBound())); } cp.addKeyListener(panel); cp.setFocusable(true); cp.setDisplayToolTips(true); cp.setDismissDelay(3000); cp.setInitialDelay(0); cp.setReshowDelay(0); cp.setVisible(true); cp.setRefreshBuffer(true); cp.setMouseWheelEnabled(true); //FIXME fix peak overlay // if (project != null) { // for (Peak1DContainer peaks : project.getPeaks(chromatogram)) { // Peak1DHeatmapOverlay overlay = new Peak1DHeatmapOverlay(chromatogram, peaks.getName(), peaks.getDisplayName(), peaks.getShortDescription(), true, peaks); // cp.addOverlay(overlay); // content.add(overlay); // } // } panel.setChartPanel(cp); if (ps != null) { panel.setPaintScale(ps); } panel.setPlot(p); return panel; }