Java Code Examples for org.jfree.chart.entity.ChartEntity#getClass()
The following examples show how to use
org.jfree.chart.entity.ChartEntity#getClass() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BarChartPanel.java From nmonvisualizer with Apache License 2.0 | 5 votes |
@Override public void highlightElement(int row, int column) { if ((getChart() != null) && (getChart().getClass() == HighlightableBarChart.class)) { boolean highlightWholeBar = ((DataTupleCategoryDataset) getChart().getCategoryPlot().getDataset()) .categoriesHaveDifferentStats(); // find the CategoryItemEntity that matches the given row and column // assume there are not that many entities in the chart and this will be relatively fast @SuppressWarnings("rawtypes") java.util.Iterator i = getChartRenderingInfo().getEntityCollection().iterator(); while (i.hasNext()) { ChartEntity entity = (ChartEntity) i.next(); if (entity.getClass() == CategoryItemEntity.class) { CategoryItemEntity categoryEntity = (CategoryItemEntity) entity; int currentRow = categoryEntity.getDataset().getRowIndex(categoryEntity.getRowKey()); int currentColumn = categoryEntity.getDataset().getColumnIndex(categoryEntity.getColumnKey()); if (highlightWholeBar) { // match all categories if (currentColumn == column) { ((HighlightableBarChart) getChart()).highlightEntity(categoryEntity); } } else { // match only a single category if ((currentRow == row) && (currentColumn == column)) { ((HighlightableBarChart) getChart()).highlightEntity(categoryEntity); break; } } } } } }
Example 2
Source File: LineChartPanel.java From nmonvisualizer with Apache License 2.0 | 4 votes |
@Override public final void chartMouseClicked(ChartMouseEvent event) { int series = -1; ChartEntity entity = event.getEntity(); if (entity == null) { return; } // users can click on either the line or the legend // regardless, figure out the series index if (entity.getClass() == XYItemEntity.class) { series = ((XYItemEntity) event.getEntity()).getSeriesIndex(); } else if (entity.getClass() == LegendItemEntity.class) { LegendItemEntity legendEntity = (LegendItemEntity) event.getEntity(); XYDataset dataset = (XYDataset) legendEntity.getDataset(); for (int i = 0; i < dataset.getSeriesCount(); i++) { if (dataset.getSeriesKey(i).equals(legendEntity.getSeriesKey())) { series = i; break; } } } if (series != -1) { XYItemRenderer renderer = getChart().getXYPlot().getRenderer(); Stroke oldHighlight = renderer.getSeriesStroke(series); // clear existing highlights ((AbstractRenderer) getChart().getXYPlot().getRenderer()).clearSeriesStrokes(false); // toggle series stroke if (oldHighlight != SELECTED_STROKE) { renderer.setSeriesStroke(series, SELECTED_STROKE); firePropertyChange("highlightedLine", null, series); } else { renderer.setSeriesStroke(series, null); firePropertyChange("highlightedLine", series, null); } // assume whatever fired the event will repaint the chart } }
Example 3
Source File: BarChartPanel.java From nmonvisualizer with Apache License 2.0 | 4 votes |
@Override protected void displayPopupMenu(int x, int y) { // only show annotation menu if the mouse if over an actual bar // find the CategoryItemEntity that matches the given x, y // assume there are not that many entities in the chart and this will be relatively // fast @SuppressWarnings("rawtypes") java.util.Iterator i = getChartRenderingInfo().getEntityCollection().iterator(); boolean valid = false; while (i.hasNext()) { ChartEntity entity = (ChartEntity) i.next(); if (entity.getClass() == CategoryItemEntity.class) { CategoryItemEntity categoryEntity = (CategoryItemEntity) entity; if (categoryEntity.getArea().contains(x, y)) { ((AnnotateBarAction) annotateBar.getActionListeners()[0]).categoryKey = (String) categoryEntity .getColumnKey(); valid = true; break; } } } if (valid) { if (!canAnnotate) { getPopupMenu().addSeparator(); getPopupMenu().add(annotateBar); canAnnotate = true; } // else menu already present } else { removeAnnotationMenu(); } super.displayPopupMenu(x, y); }