List of usage examples for org.jfree.data.category CategoryDataset getColumnIndex
public int getColumnIndex(Comparable key);
From source file:biz.ixnay.pivot.charts.skin.jfree.PolarChartViewSkin.java
public Element getElementAt(int x, int y) { ChartView.Element element = null; ChartEntity chartEntity = getChartEntityAt(x, y); if (chartEntity instanceof CategoryItemEntity) { CategoryItemEntity categoryItemEntity = (CategoryItemEntity) chartEntity; CategoryDataset dataset = categoryItemEntity.getDataset(); String columnKey = (String) categoryItemEntity.getColumnKey(); int columnIndex = dataset.getColumnIndex(columnKey); String rowKey = (String) categoryItemEntity.getRowKey(); int rowIndex = dataset.getRowIndex(rowKey); element = new ChartView.Element(rowIndex, columnIndex); } else if (chartEntity instanceof XYItemEntity) { XYItemEntity xyItemEntity = (XYItemEntity) chartEntity; element = new ChartView.Element(xyItemEntity.getSeriesIndex(), xyItemEntity.getItem()); }//from w w w . j ava 2 s .co m return element; }
From source file:biz.ixnay.pivot.charts.skin.jfree.AreaChartViewSkin.java
@Override public ChartView.Element getElementAt(int x, int y) { ChartView.Element element = null; ChartEntity chartEntity = getChartEntityAt(x, y); if (chartEntity instanceof CategoryItemEntity) { CategoryItemEntity categoryItemEntity = (CategoryItemEntity) chartEntity; CategoryDataset dataset = categoryItemEntity.getDataset(); String columnKey = (String) categoryItemEntity.getColumnKey(); int columnIndex = dataset.getColumnIndex(columnKey); String rowKey = (String) categoryItemEntity.getRowKey(); int rowIndex = dataset.getRowIndex(rowKey); element = new ChartView.Element(rowIndex, columnIndex); } else if (chartEntity instanceof XYItemEntity) { XYItemEntity xyItemEntity = (XYItemEntity) chartEntity; element = new ChartView.Element(xyItemEntity.getSeriesIndex(), xyItemEntity.getItem()); }/* w ww. ja v a 2 s.co m*/ return element; }
From source file:edu.cuny.jfree.chart.annotations.CategoryIntervalAnnotation.java
public void draw(final Graphics2D g2, final CategoryPlot plot, final Rectangle2D dataArea, final CategoryAxis domainAxis, final ValueAxis rangeAxis) { final AlphaComposite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, plot.getForegroundAlpha());// www . j a v a 2s. c om final Composite oldComposite = g2.getComposite(); g2.setComposite(alphaComposite); final CategoryDataset dataset = plot.getDataset(); final int catIndex = dataset.getColumnIndex(category); final int catCount = dataset.getColumnCount(); double lineX1 = 0.0D; double lineY = 0.0D; double lineX2 = 0.0D; final PlotOrientation orientation = plot.getOrientation(); final RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation); final RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation); if (orientation == PlotOrientation.HORIZONTAL) { lineY = domainAxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, catIndex, catCount, dataArea, domainEdge); lineX1 = rangeAxis.valueToJava2D(value1, dataArea, rangeEdge); lineX2 = rangeAxis.valueToJava2D(value2, dataArea, rangeEdge); } else if (orientation == PlotOrientation.VERTICAL) { lineY = rangeAxis.valueToJava2D(value1, dataArea, rangeEdge); lineX1 = domainAxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, catIndex, catCount, dataArea, domainEdge); lineX2 = domainAxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, catIndex, catCount, dataArea, domainEdge); } g2.setPaint(paint); g2.setStroke(stroke); g2.drawLine((int) lineX1, (int) lineY, (int) lineX2, (int) lineY); g2.setComposite(oldComposite); }
From source file:biz.ixnay.pivot.charts.skin.jfree.LineChartViewSkin.java
@Override public ChartView.Element getElementAt(int x, int y) { ChartView.Element element = null; ChartEntity chartEntity = getChartEntityAt(x, y); if (chartEntity instanceof CategoryItemEntity) { CategoryItemEntity categoryItemEntity = (CategoryItemEntity) chartEntity; CategoryDataset dataset = categoryItemEntity.getDataset(); String columnKey = (String) categoryItemEntity.getColumnKey(); int columnIndex = dataset.getColumnIndex(columnKey); String rowKey = (String) categoryItemEntity.getRowKey(); int rowIndex = dataset.getRowIndex(rowKey); element = new ChartView.Element(rowIndex, columnIndex); } else if (chartEntity instanceof XYItemEntity) { XYItemEntity xyItemEntity = (XYItemEntity) chartEntity; element = new ChartView.Element(xyItemEntity.getSeriesIndex(), xyItemEntity.getItem()); }//from ww w. j ava2 s . co m return element; }
From source file:net.sf.maltcms.chromaui.charts.events.ChartPanelMouseListener.java
/** * * @param arg0/*from w w w. j a v a 2s. c o m*/ */ @Override public void chartMouseClicked(final ChartMouseEvent arg0) { final ChartPanelMouseListener cpml = this; if (arg0.getEntity() != null) { if (arg0.getEntity() instanceof XYItemEntity) { XYItemEntity xyie = (XYItemEntity) arg0.getEntity(); if (arg0.getTrigger().getButton() == MouseEvent.BUTTON1) { // if (arg0.getTrigger().isAltDown() && arg0.getTrigger().isShiftDown()) { // System.out.println("Item removed"); fireEvent(new XYItemEntityRemovedEvent((XYItemEntity) arg0.getEntity(), cpml)); } else if (arg0.getTrigger().isAltDown()) { // System.out.println("Item added"); fireEvent(new XYItemEntityAddedEvent((XYItemEntity) arg0.getEntity(), cpml)); } else { setTarget(arg0); // System.out.println("Item clicked"); fireEvent(new XYItemEntityClickedEvent((XYItemEntity) arg0.getEntity(), cpml)); } } } else if (arg0.getEntity() instanceof LegendItemEntity) { JPopupMenu jpm = new JPopupMenu(); final LegendItemEntity lie = (LegendItemEntity) arg0.getEntity(); Dataset ds = lie.getDataset(); Comparable skey = lie.getSeriesKey(); Plot plot = arg0.getChart().getPlot(); if (plot instanceof XYPlot) { XYPlot xyplot = arg0.getChart().getXYPlot(); if (xyplot.getSeriesCount() > 1) { XYDataset xyds = (XYDataset) ds; XYItemRenderer xyir = xyplot.getRendererForDataset(xyds); xyir.setSeriesVisible(xyds.indexOf(skey), !xyir.isSeriesVisible(xyds.indexOf(skey))); xyir.setSeriesVisibleInLegend(xyds.indexOf(skey), Boolean.TRUE); } } else if (plot instanceof CategoryPlot) { CategoryPlot cplot = arg0.getChart().getCategoryPlot(); if (cplot.getDatasetCount() > 1) { CategoryDataset cds = (CategoryDataset) ds; CategoryItemRenderer xyir = cplot.getRendererForDataset(cds); int seriesIndex = cds.getColumnIndex(skey); if (seriesIndex == -1) { seriesIndex = cds.getRowIndex(skey); } xyir.setSeriesVisible(seriesIndex, !xyir.isSeriesVisible(seriesIndex)); xyir.setSeriesVisibleInLegend(seriesIndex, Boolean.TRUE); } } // AbstractAction hse = new AbstractAction("Hide") { // // @Override // public void actionPerformed(ActionEvent ae) { // // } // }; // AbstractAction hse = new AbstractAction("Show") { // // @Override // public void actionPerformed(ActionEvent ae) { // // } // }; // AbstractAction hse = new AbstractAction("Remove") { // // @Override // public void actionPerformed(ActionEvent ae) { // // } // }; } } }
From source file:org.jfree.data.general.DatasetUtilities.java
/** * Creates a pie dataset from a table dataset by taking all the values * for a single column./*from ww w. j av a2 s. c om*/ * * @param dataset the dataset (<code>null</code> not permitted). * @param columnKey the column key. * * @return A pie dataset. */ public static PieDataset createPieDatasetForColumn(CategoryDataset dataset, Comparable columnKey) { int column = dataset.getColumnIndex(columnKey); return createPieDatasetForColumn(dataset, column); }
From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraphAction.java
/** * Add the action listener to the graph. *//* w ww . ja v a 2 s .co m*/ private void setAction() { gui.pnlGraph.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(final ChartMouseEvent e) { if (e.getEntity() instanceof PlotEntity) { Point2D p = gui.pnlGraph.translateScreenToJava2D(e.getTrigger().getPoint()); CategoryPlot plot = (CategoryPlot) gui.pnlGraph.getChart().getPlot(); Rectangle2D plotArea = gui.pnlGraph.getScreenDataArea(); DateAxis rangeAxis = (DateAxis) plot.getRangeAxis(); RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); CategoryAxis catAxis = plot.getDomainAxis(); RectangleEdge domainAxisEdge = plot.getDomainAxisEdge(); double chartY = rangeAxis.java2DToValue(p.getX(), plotArea, rangeAxisEdge); CategoryDataset categories = (CategoryDataset) plot.getDataset(0); int categoryCount = categories.getColumnCount(); for (int i = 0; i < categoryCount; i++) { double catStart = catAxis.getCategoryStart(i, categoryCount, plotArea, domainAxisEdge); double catEnd = catAxis.getCategoryEnd(i, categoryCount, plotArea, domainAxisEdge); if (e.getTrigger().getY() >= catStart && e.getTrigger().getY() < catEnd) { new EditAvailabilityController(gui.function, gui.function.getWorkers().get(i), new Day(new Date((long) chartY)), parent); } } } else { CategoryItemEntity item = (CategoryItemEntity) e.getEntity(); CategoryPlot plot = (CategoryPlot) gui.pnlGraph.getChart().getPlot(); Rectangle2D plotArea = gui.pnlGraph.getScreenDataArea(); RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); DateAxis dateAxis = (DateAxis) plot.getRangeAxis(); double d = dateAxis.java2DToValue(e.getEntity().getArea().getBounds2D().getX(), plotArea, rangeAxisEdge); double d2 = dateAxis.java2DToValue(e.getEntity().getArea().getBounds2D().getX() + e.getEntity().getArea().getBounds2D().getWidth(), plotArea, rangeAxisEdge); Date startDate = new Date((long) d); Date endDate = new Date((long) d2); CategoryDataset categories = (CategoryDataset) plot.getDataset(0); int workerIndex = categories.getColumnIndex(item.getColumnKey()); Worker worker = gui.function.getWorkers().get(workerIndex); Set<Availability> found = CalendarService.getAllWorkerAvailability(worker.getId(), startDate, endDate); Availability foundAv = found.toArray(new Availability[1])[0]; if (foundAv != null) { new EditAvailabilityController(gui.function, foundAv, parent); } else { found = CalendarService.getProjectAvailability(startDate, endDate); foundAv = found.toArray(new Availability[1])[0]; if (foundAv != null) { new EditAvailabilityController(gui.function, foundAv, parent); } else { JOptionPane.showMessageDialog( new JFrame(LocalizedStrings.getGeneralStrings().warning()), LocalizedStrings.getErrorMessages().availabilityCanNotBeChanged()); } } } } @Override public void chartMouseMoved(final ChartMouseEvent arg0) { } }); /** * ActionListener */ gui.btnNext.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { gui.function.increment(); } }); /** * ActionListener */ gui.btnPrev.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { gui.function.decrement(); } }); for (int i = 0; i < gui.buttons.length; i++) { addButtonListener(i); } /** * ActionListener */ gui.btnManualAv.addItemListener(new ItemListener() { @Override public void itemStateChanged(final ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { gui.function.setManualAv(true); } else { gui.function.setManualAv(false); } } }); }