List of usage examples for org.jfree.chart ChartPanel getEntityForPoint
public ChartEntity getEntityForPoint(int viewX, int viewY)
From source file:nextapp.echo.chart.testapp.testscreen.PieChartTest.java
public PieChartTest() { super(SplitPane.ORIENTATION_HORIZONTAL, new Extent(250, Extent.PX)); setStyleName("DefaultResizable"); ButtonColumn controlsColumn = new ButtonColumn(); controlsColumn.setStyleName("TestControlsColumn"); add(controlsColumn);/*www.j a va2s . com*/ DefaultKeyedValues values = new DefaultKeyedValues(); values.addValue("Widgets", 500.2); values.addValue("Cubits", 216.0); values.addValue("Zonkits", 125.9); final DefaultPieDataset pieDataset = new DefaultPieDataset(new DefaultPieDataset(values)); PiePlot piePlot = new PiePlot(pieDataset); piePlot.setToolTipGenerator(new StandardPieToolTipGenerator()); final ChartDisplay chartDisplay = new ChartDisplay(piePlot); add(chartDisplay); chartDisplay.setActionCommands(new String[] { "Widgets", "Cubits", "Zonkits" }); chartDisplay.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { WindowPane window = new WindowPane("Chart series clicked", new Extent(300), new Extent(200)); window.add(new Label("You clicked on " + arg0.getActionCommand())); Component contentPane = getParent(); while (!(contentPane instanceof ContentPane)) { contentPane = contentPane.getParent(); } contentPane.add(window); } }); ChartPanel chartPanel = new ChartPanel(new JFreeChart(piePlot)); chartPanel.setRefreshBuffer(true); ChartEntity entity = chartPanel.getEntityForPoint(50, 50); System.out.println("Entity: " + entity); controlsColumn.addButton("Set Width = 800px", new ActionListener() { public void actionPerformed(ActionEvent e) { synchronized (chartDisplay) { chartDisplay.setWidth(new Extent(800)); } } }); controlsColumn.addButton("Set Width = null", new ActionListener() { public void actionPerformed(ActionEvent e) { synchronized (chartDisplay) { chartDisplay.setWidth(null); } } }); controlsColumn.addButton("Set Height = 600px", new ActionListener() { public void actionPerformed(ActionEvent e) { synchronized (chartDisplay) { chartDisplay.setHeight(new Extent(600)); } } }); controlsColumn.addButton("Set Height = null", new ActionListener() { public void actionPerformed(ActionEvent e) { synchronized (chartDisplay) { chartDisplay.setHeight(null); } } }); controlsColumn.addButton("Update a Value", new ActionListener() { public void actionPerformed(ActionEvent e) { synchronized (chartDisplay) { pieDataset.setValue("Cubits", Math.random() * 500); } } }); }
From source file:jgnash.ui.report.compiled.IncomeExpensePieChart.java
private void setChartCursor(final ChartPanel chartPanel, final ChartEntity e, final Point point) { lastPoint = point;//www. j a v a 2 s.c o m EventQueue.invokeLater(new Runnable() { ChartEntity entity = e; @Override public void run() { if (entity == null && point != null) { entity = chartPanel.getEntityForPoint(lastPoint.x, lastPoint.y); } Account parent = currentAccount; if (entity instanceof PieSectionEntity) { // change cursor if section is interesting Account a = (Account) ((PieSectionEntity) entity).getSectionKey(); if (a.getChildCount() > 0 && a != parent) { chartPanel.setCursor(ZOOM_IN); } else { chartPanel.setCursor(Cursor.getDefaultCursor()); } return; } else if (entity == null && parent != null) { parent = parent.getParent(); if (parent != null && !(parent instanceof RootAccount)) { chartPanel.setCursor(ZOOM_OUT); return; } } chartPanel.setCursor(Cursor.getDefaultCursor()); } }); }