Example usage for org.jfree.chart.entity LegendItemEntity getDataset

List of usage examples for org.jfree.chart.entity LegendItemEntity getDataset

Introduction

In this page you can find the example usage for org.jfree.chart.entity LegendItemEntity getDataset.

Prototype

public Dataset getDataset() 

Source Link

Document

Returns a reference to the dataset that this legend item is derived from.

Usage

From source file:ec.util.chart.swing.Charts.java

/**
 * Finds the series selected by a click on a ChartPanel (from JFreeChart)
 *
 * @param pt Point where the mouse click happened
 * @param cp ChartPanel being clicked on
 * @return Index of the series in the chart; -1 if no series found
 * @deprecated use {@link #getSeriesForPoint(java.awt.Point, org.jfree.chart.ChartPanel)
 * } instead//from  w  w  w . j  ava2s. c  o  m
 */
@Deprecated
public static int getSelectedSeries(@Nonnull Point pt, @Nonnull ChartPanel cp) {
    LegendItemEntity result = getSeriesForPoint(pt, cp);
    return result != null ? ((SeriesDataset) result.getDataset()).indexOf(result.getSeriesKey())
            : NO_SERIES_FOUND_INDEX;
}

From source file:net.sf.maltcms.chromaui.charts.events.ChartPanelMouseListener.java

/**
 *
 * @param arg0/*from   w  w  w . ja 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) {
            //                        
            //                    }
            //                };
        }
    }
}