List of usage examples for org.jfree.chart ChartMouseEvent getChart
public JFreeChart getChart()
From source file:dbseer.gui.events.InformationChartMouseListener.java
@Override public void chartMouseMoved(ChartMouseEvent event) { Rectangle2D dataArea = chartPanel.getScreenDataArea(); JFreeChart chart = event.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis xAxis = plot.getDomainAxis(); double x = xAxis.java2DToValue(event.getTrigger().getX(), dataArea, RectangleEdge.BOTTOM); chartPanel.getVerticalCrossHair().setValue(x); }
From source file:dbseer.gui.events.InformationChartMouseListener.java
@Override public void chartMouseClicked(ChartMouseEvent event) { Rectangle2D dataArea = chartPanel.getScreenDataArea(); JFreeChart chart = event.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis xAxis = plot.getDomainAxis(); int x = (int) Math.round(xAxis.java2DToValue(event.getTrigger().getX(), dataArea, RectangleEdge.BOTTOM)); XYDataset dataset = plot.getDataset(); int maxX = DatasetUtilities.findMaximumDomainValue(dataset).intValue(); if (x >= 1 && x <= maxX) { int seriesCount = dataset.getSeriesCount(); int[] mixtures = new int[seriesCount - 1]; int total = 0; for (int i = 0; i < seriesCount - 1; ++i) { mixtures[i] = (int) dataset.getYValue(i, x - 1); total += mixtures[i];//from w w w. j a va 2s .c o m } for (int i = 0; i < seriesCount - 1; ++i) { mixtures[i] = (int) Math.round((double) mixtures[i] / (double) total * 100.0); tpsMixturePanel.setMixture(i, mixtures[i]); } } }
From source file:edu.cmu.sv.modelinference.eventtool.charting.DataChart.java
private void createChartPanel(JFreeChart chart) { chartPanel = new ChartPanel(chart); chartPanel.addChartMouseListener(new ChartMouseListener() { @Override/*from w ww. j a va 2 s.c om*/ public void chartMouseClicked(ChartMouseEvent arg0) { //ignore } @Override public void chartMouseMoved(ChartMouseEvent event) { Rectangle2D dataArea = chartPanel.getScreenDataArea(); JFreeChart chart = event.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis xAxis = plot.getDomainAxis(); double x = xAxis.java2DToValue(event.getTrigger().getX(), dataArea, RectangleEdge.BOTTOM); ValueAxis yAxis = plot.getRangeAxis(); double y = yAxis.java2DToValue(event.getTrigger().getY(), dataArea, RectangleEdge.LEFT); //Alternatively, obtain y for one of the subplots, which would be very neat. //We should find the "nearest" subplot to the cursor -- this is easy //double y = DatasetUtilities.findYValue(plot.getDataset(), 0, x); xCrosshair.setValue(x); yCrosshair.setValue(y); } }); CrosshairOverlay crosshairOverlay = new CrosshairOverlay(); xCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f)); xCrosshair.setLabelVisible(true); yCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f)); yCrosshair.setLabelVisible(true); crosshairOverlay.addDomainCrosshair(xCrosshair); crosshairOverlay.addRangeCrosshair(yCrosshair); chartPanel.addOverlay(crosshairOverlay); chartPanel.setPreferredSize(new java.awt.Dimension(800, 600)); setContentPane(chartPanel); }
From source file:edu.ucla.stat.SOCR.motionchart.MotionMouseListener.java
/** * Callback method for receiving notification of a mouse movement on a * chart.//from w ww .j a v a 2 s . c om * * @param event information about the event. */ public void chartMouseMoved(ChartMouseEvent event) { if (!(event.getChart().getXYPlot().getRenderer() instanceof MotionBubbleRenderer)) { return; } MotionBubbleRenderer renderer = (MotionBubbleRenderer) event.getChart().getXYPlot().getRenderer(); if (!(event.getEntity() instanceof XYItemEntity)) { renderer.setHighlightedItem(-1, -1); return; } XYItemEntity item = (XYItemEntity) event.getEntity(); renderer.setHighlightedItem(item.getSeriesIndex(), item.getItem()); }
From source file:edu.ucla.stat.SOCR.motionchart.MotionMouseListener.java
protected JPanel getSeriesPanel(final JDialog dialog, ChartMouseEvent event) { MotionDataSet dataset = (MotionDataSet) event.getChart().getXYPlot().getDataset(); MotionBubbleRenderer renderer = (MotionBubbleRenderer) event.getChart().getXYPlot().getRenderer(); MotionTableModel model = dataset.getTableModel(); DefaultTableModel tModel = new DefaultTableModel(); ArrayList<Integer> visibleSeries = renderer.getVisibleSeries(); ArrayList<String> rowIds = new ArrayList<String>(); int columnCount = model.getColumnCount(); int r = 0;/*ww w. j a v a 2s . c o m*/ for (int c = 0; c < columnCount; c++) { tModel.addColumn(model.getColumnName(c)); } Iterator<Integer> itr = visibleSeries.iterator(); while (itr.hasNext()) { ArrayList<Integer> rows = model.getKeyMap().get(dataset.getSeriesKey(itr.next())); Iterator<Integer> rItr = rows.iterator(); while (rItr.hasNext()) { int row = rItr.next(); tModel.addRow(new Object[0]); rowIds.add(new String(row + ":")); for (int c = 0; c < columnCount; c++) { tModel.setValueAt(model.getValueAt(row, c), r, c); } r++; } } return getPanel(dialog, tModel, rowIds); }
From source file:edu.ucla.stat.SOCR.motionchart.MotionMouseListener.java
protected JPanel getItemPanel(final JDialog dialog, XYItemEntity item, ChartMouseEvent event) { MotionDataSet dataset = (MotionDataSet) event.getChart().getXYPlot().getDataset(); MotionTableModel model = dataset.getTableModel(); DefaultTableModel tModel = new DefaultTableModel(2, 0); ArrayList<String> rowIds = new ArrayList<String>(); Integer row = model.getKeyMap().get(dataset.getSeriesKey(item.getSeriesIndex())).get(item.getItem()); rowIds.add(row + ":"); int columnCount = model.getColumnCount(); for (int c = 0; c < columnCount; c++) { tModel.addColumn(model.getColumnName(c)); tModel.setValueAt(model.getValueAt(row, c), 0, c); }/*w w w . j a v a 2 s . c o m*/ rowIds.add("Mappings:"); Object category = dataset.getCategory(item.getSeriesIndex(), item.getItem()); if (category != null) { tModel.setValueAt(category, 1, model.getCategoryMapping()); } Object key = dataset.getSeriesKey(item.getSeriesIndex()); if (key != null) { tModel.setValueAt(key, 1, model.getKeyMapping()); } Object x = dataset.getX(item.getSeriesIndex(), item.getItem()); if (x != null) { tModel.setValueAt(x, 1, model.getXAxisMapping()); } Object y = dataset.getY(item.getSeriesIndex(), item.getItem()); if (y != null) { tModel.setValueAt(y, 1, model.getYAxisMapping()); } Object size = dataset.getSize(item.getSeriesIndex(), item.getItem()); if (size != null) { tModel.setValueAt(size, 1, model.getSizeMapping()); } Color color = dataset.getColor(item.getSeriesIndex(), item.getItem()); if (color != null) { //String colorText = "RGB(" + color.getRed() + "," + color.getGreen() + "," + color.getBlue() + ")"; tModel.setValueAt(color, 1, model.getColorMapping()); } return getPanel(dialog, tModel, rowIds); }
From source file:com.haskins.cloudtrailviewer.feature.MetricsFeature.java
@Override public void chartMouseMoved(ChartMouseEvent event) { Rectangle2D dataArea = this.chartPanel.getScreenDataArea(); JFreeChart chart = event.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis xAxis = plot.getDomainAxis(); double x = xAxis.java2DToValue(event.getTrigger().getX(), dataArea, RectangleEdge.BOTTOM); this.xCrosshair.setValue(x); }
From source file:net.sf.maltcms.chromaui.charts.events.ChartPanelMouseListener.java
/** * * @param arg0//w ww.j a v a2 s. co m */ @Override public void chartMouseMoved(final ChartMouseEvent arg0) { final ChartPanelMouseListener cpml = this; if (arg0.getEntity() != null) { if (arg0.getEntity() instanceof XYItemEntity) { if (arg0.getTrigger().isAltDown()) { XYPlot xyp = arg0.getChart().getXYPlot(); if (xyp != null) { fireEvent(new XYItemEntityClickedEvent((XYItemEntity) arg0.getEntity(), cpml)); } XYItemEntityMovedEvent xyie = new XYItemEntityMovedEvent((XYItemEntity) arg0.getEntity(), cpml); fireEvent(xyie); } } if (arg0.getEntity() instanceof XYAnnotationEntity) { ChartRenderingInfo cri = cp.getChartRenderingInfo(); EntityCollection entities = cri.getEntityCollection(); ChartEntity ce = entities.getEntity(arg0.getTrigger().getX(), arg0.getTrigger().getY()); if (ce instanceof XYItemEntity) { // System.out.println("Entity at position: " + ce.getClass(). // getName() + " " + ((XYItemEntity) ce)); XYItemEntityMouseOverEvent xyie = new XYItemEntityMouseOverEvent((XYItemEntity) ce, cpml); fireEvent(xyie); } } } }
From source file:fr.crnan.videso3d.formats.plns.PLNSChartMouseListener.java
@Override public void chartMouseClicked(ChartMouseEvent evt) { if (evt.getEntity() instanceof CategoryItemEntity) { CategoryItemEntity entity = (CategoryItemEntity) evt.getEntity(); //try to guess the type of the entity if (entity.getColumnKey() instanceof String && ((String) entity.getColumnKey()).matches("C.")) { this.context.showInfo(DatasManager.Type.STPV, StpvController.CATEGORIE_CODE, (String) entity.getColumnKey()); } else if (entity.getColumnKey() instanceof Integer && evt.getChart().getPlot() instanceof CategoryPlot && ((CategoryPlot) evt.getChart().getPlot()).getDomainAxis().getLabel().equals("LP")) { this.context.showInfo(DatasManager.Type.STPV, StpvController.LIAISON_PRIVILEGIEE, ((Integer) entity.getColumnKey()).toString()); }// w w w. j a va 2 s. c o m } else if (evt.getEntity() instanceof CategoryLabelEntity) { CategoryLabelEntity entity = (CategoryLabelEntity) evt.getEntity(); if (entity.getKey() instanceof String && ((String) entity.getKey()).matches("C.")) { this.context.showInfo(DatasManager.Type.STPV, StpvController.CATEGORIE_CODE, (String) entity.getKey()); } else if (entity.getKey() instanceof Integer && evt.getChart().getPlot() instanceof CategoryPlot && ((CategoryPlot) evt.getChart().getPlot()).getDomainAxis().getLabel().equals("LP")) { this.context.showInfo(DatasManager.Type.STPV, StpvController.LIAISON_PRIVILEGIEE, ((Integer) entity.getKey()).toString()); } } }
From source file:org.trade.ui.chart.CandlestickChart.java
/** * A demonstration application showing a candlestick chart. * //from w ww .j a v a 2 s . c o 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); }