List of usage examples for org.jfree.chart.plot XYPlot getDomainCrosshairValue
public double getDomainCrosshairValue()
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 w w .jav a 2 s . co m lastAnnotationY = y; } }); }
From source file:cgpanalyser.gui.chart.XYChartPanel.java
private int getDomainCrosshairValue(JFreeChart jfreechart) { XYPlot xyplot = (XYPlot) jfreechart.getPlot(); return (int) xyplot.getDomainCrosshairValue(); }
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 ww w. j av a 2s.c om 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:cgpanalyser.gui.chart.XYChartPanel.java
public void setNextCrosshairValue(JFreeChart jfreechart) { XYPlot plot = (XYPlot) jfreechart.getPlot(); XYDataset dataset = plot.getDataset(); //set crosshair to next value if not on last already for (int i = 0; i < dataSampler.getLastToDisplay().size() - 1; i++) { //find generation in datasampler.todisplay if ((int) plot.getDomainCrosshairValue() == dataSampler.getLastToDisplay().get(i).getGenNumber()) { plot.setDomainCrosshairValue(dataset.getXValue(0, i + 1)); plot.setRangeCrosshairValue(dataset.getYValue(0, i + 1)); break; }// w ww. j a v a 2s . co m } }
From source file:cgpanalyser.gui.chart.XYChartPanel.java
public void setPrevCrosshairValue(JFreeChart jfreechart) { XYPlot plot = (XYPlot) jfreechart.getPlot(); XYDataset dataset = plot.getDataset(); //set crosshair to previous value if not on first already for (int i = 0; i < dataSampler.getLastToDisplay().size(); i++) { //find generation in datasampler.todisplay if ((int) plot.getDomainCrosshairValue() == dataSampler.getLastToDisplay().get(i).getGenNumber()) { if (i > 0) { plot.setDomainCrosshairValue(dataset.getXValue(0, i - 1)); plot.setRangeCrosshairValue(dataset.getYValue(0, i - 1)); }//from www . j a v a 2 s .c om break; } } }
From source file:org.trade.ui.chart.CandlestickChart.java
/** * A demonstration application showing a candlestick chart. * /*from www . j av a 2s. c om*/ * @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.orange.atk.graphAnalyser.LectureJATKResult.java
/** * Handles a chart progress event.//from www . ja v a2s . c o m * * @param event * the event. */ public void chartProgress(ChartProgressEvent event) { if (event.getType() != ChartProgressEvent.DRAWING_FINISHED) { return; } if (this.chartPanel != null) { JFreeChart c = this.chartPanel.getChart(); if (c != null) { XYPlot plot = c.getXYPlot(); double xx = plot.getDomainCrosshairValue(); if (xx != 0 && mapPerfGraph != null) { Set<String> cles = mapPerfGraph.keySet(); Iterator<String> it = cles.iterator(); int index = 0; while (it.hasNext()) { String cle = (String) it.next(); PerformanceGraph graph = (PerformanceGraph) mapPerfGraph.get(cle); String Name = graph.getSerieName(); graph.getY(xx); double Yvalue = graph.getYvalue(); double Yvaluenext = graph.getNextyvalue(); double Yvalueprev = graph.getPrevousyValue(); Name = Name.replace("Series ", ""); this.modeltable.setValueAt(Name, index, 0); this.modeltable.setValueAt(new Double(Yvalue), index, 1); this.modeltable.setValueAt(new Double(Yvaluenext), index, 2); this.modeltable.setValueAt(new Double(Yvalueprev), index, 3); index++; } // update the table... } } } }
From source file:com.orange.atk.graphAnalyser.LectureJATKResult.java
/** * Receives notification of a {@link ChartChangeEvent}. * * @param event the event./*from www .j a v a 2 s .c om*/ */ public void chartChanged(ChartChangeEvent event) { if (this.chartPanel != null) { JFreeChart chart = this.chartPanel.getChart(); if (chart != null) { XYPlot plot = chart.getXYPlot(); //recupere X double xx = plot.getDomainCrosshairValue(); if (xx != 0 && mapPerfGraph != null) { Set<String> cles = mapPerfGraph.keySet(); Iterator<String> it = cles.iterator(); int index = 0; while (it.hasNext()) { String cle = (String) it.next(); PerformanceGraph graph = (PerformanceGraph) mapPerfGraph.get(cle); graph.getY(xx); double Xvalue = graph.getXvalue(); double xvaluenext = graph.getNextXvalue(); double xvalueprev = graph.getPrevousxValue(); this.modeltable.setValueAt(graph.getSerieName().replace("Series ", ""), index, 0); this.modeltable.setValueAt(new Double(Xvalue), index, 1); this.modeltable.setValueAt(new Double(xvaluenext), index, 2); this.modeltable.setValueAt(new Double(xvalueprev), index, 3); index++; } } } } }
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; }//from ww w. ja v a 2s . c om } } } } }
From source file:de.tor.tribes.ui.views.DSWorkbenchStatsFrame.java
private void setEndAnnotation() { XYPlot plot = ((XYPlot) chart.getPlot()); double x = plot.getDomainCrosshairValue(); if (endPointer != null) { plot.removeDomainMarker(endPointer); }/* w w w. j a v a 2 s .c o m*/ if (endPointer != null && endPointer.getValue() == x) { plot.removeDomainMarker(endPointer); endPointer = null; } else { if (startPointer != null) { if (startPointer.getValue() > x) { //flip start and end plot.removeDomainMarker(startPointer); endPointer = new ValueMarker(startPointer.getValue()); endPointer.setLabel("Ende"); endPointer.setPaint(Color.red); plot.addDomainMarker(endPointer); startPointer = new ValueMarker(x); startPointer.setLabel("Start"); startPointer.setPaint(Color.green); plot.addDomainMarker(startPointer); } else { endPointer = new ValueMarker(x); endPointer.setLabel("Ende"); endPointer.setPaint(Color.red); plot.addDomainMarker(endPointer); } } else { endPointer = new ValueMarker(x); endPointer.setLabel("Ende"); endPointer.setPaint(Color.red); plot.addDomainMarker(endPointer); } } jChartPanel.repaint(); }