List of usage examples for org.jfree.chart.plot XYPlot getRangeCrosshairValue
public double getRangeCrosshairValue()
From source file:org.openaltimeter.desktopapp.annotations.AltimeterChartMouseListener.java
@Override public void chartMouseClicked(final ChartMouseEvent event) { SwingUtilities.invokeLater(new Runnable() { public void run() { XYPlot xyplot = (XYPlot) cp.getChart().getPlot(); double x, y; x = xyplot.getDomainCrosshairValue(); y = xyplot.getRangeCrosshairValue(); am.addUserHeightAnnotation(x, y); int onmask = InputEvent.SHIFT_DOWN_MASK; if ((event.getTrigger().getModifiersEx() & (onmask)) == onmask) am.addUserVarioAnnotation(lastAnnotationX, lastAnnotationY, x, y); lastAnnotationX = x;// w ww.j a va 2 s. co m lastAnnotationY = y; } }); }
From source file:org.jfree.chart.demo.Graphic.java
public ChartPanel get_ChartPanel(int width, int height) { chr = new ChartPanel(chart); chr.setBackground(Color.blue); chr.setBounds(5, 5, width - 5, height - 10); chr.setVisible(true);//from w w w . ja va 2 s.co m chr.setMouseWheelEnabled(true); chr.addChartMouseListener(new ChartMouseListener() { public void chartMouseMoved(ChartMouseEvent chartmouseevent) { } public void chartMouseClicked(ChartMouseEvent chartmouseevent) { SwingUtilities.invokeLater(new Runnable() { public void run() { XYPlot xyplot = (XYPlot) chr.getChart().getPlot(); xyplot.clearAnnotations(); double x, y; x = new BigDecimal(xyplot.getDomainCrosshairValue()).setScale(3, RoundingMode.UP) .doubleValue(); y = new BigDecimal(xyplot.getRangeCrosshairValue()).setScale(3, RoundingMode.UP) .doubleValue(); XYTextAnnotation annotation = new XYTextAnnotation("(" + x + ", " + y + ")", new BigDecimal(x).setScale(3, RoundingMode.UP).doubleValue(), y); annotation.setFont(new Font("serif", Font.BOLD, 15)); annotation.setTextAnchor(TextAnchor.BOTTOM_CENTER); xyplot.addAnnotation(annotation); } }); } }); return chr; }
From source file:org.trade.ui.chart.CandlestickChart.java
/** * A demonstration application showing a candlestick chart. * /* w w w . j a v a 2 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:com.android.ddmuilib.log.event.EventDisplay.java
private void processClick(XYPlot xyPlot) { double rangeValue = xyPlot.getRangeCrosshairValue(); if (rangeValue != 0) { double domainValue = xyPlot.getDomainCrosshairValue(); Millisecond msec = new Millisecond(new Date((long) domainValue)); // look for values in the dataset that contains data at this TimePeriod Set<ValueDisplayDescriptor> descKeys = mValueDescriptorSeriesMap.keySet(); for (ValueDisplayDescriptor descKey : descKeys) { HashMap<Integer, TimeSeries> map = mValueDescriptorSeriesMap.get(descKey); Set<Integer> pidKeys = map.keySet(); for (Integer pidKey : pidKeys) { TimeSeries series = map.get(pidKey); Number value = series.getValue(msec); if (value != null) { // found a match. lets check against the actual value. if (value.doubleValue() == rangeValue) { return; }//w w w . j a va 2s . c om } } } } }