chartMouseClicked(ChartMouseEvent event)

chartMouseClicked(ChartMouseEvent event)

Hi deepak ihave draw a piechart using jfreechart with tooltip.Now i need click event (chartMouseClicked(ChartMouseEvent event)) in this chart. can u help me plz....

View Answers

February 18, 2011 at 3:40 PM

Java JFreechart MouseEvent

import java.awt.*;
import javax.swing.*;
import org.jfree.ui.*;
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import org.jfree.data.general.*;
import org.jfree.chart.entity.*;

public class PieChart extends ApplicationFrame implements ChartMouseListener {
private JFreeChart chart; 
private PiePlot plot;
private int angle=270;
private static double explodePercent = 0.99;
private static long count=0;

public PieChart(String title){
    super(title);
        this.chart = ChartFactory.createPieChart("Pie Chart Demo",createDataset(),  true,  true, false);
        this.plot = (PiePlot) chart.getPlot();
        this.plot.setSectionOutlinesVisible(false);
        this.plot.setNoDataMessage("No data available");
        this.plot.setBackgroundAlpha(0.2f);
        this.plot.setBackgroundPaint(Color.WHITE); 
        this.angle=270;
        ChartPanel chartpanel = new ChartPanel(chart, false, false, false, false, false);   
        chartpanel.setVisible(true);
        chartpanel.addChartMouseListener(this);
        chartpanel.setPreferredSize(new Dimension(500, 270));
        setContentPane(chartpanel);
}
private static PieDataset createDataset() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("One", new Double(10.0));
    dataset.setValue("Two", new Double(20.0));
    dataset.setValue("Three", new Double(30.0));
    dataset.setValue("Four", new Double(40.0));
    dataset.setValue("Five", new Double(10.0));
    return dataset;
}
private static JFreeChart createChart(PieDataset dataset) {

    JFreeChart chart = ChartFactory.createPieChart3D("Pie Chart Demo",dataset, true, true,false);

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionOutlinesVisible(false);
    plot.setNoDataMessage("No data available");
    plot.setBackgroundAlpha(0.2f);
    return chart;
}
public static JPanel createDemoPanel() {
    JFreeChart chart = createChart(createDataset());
    ChartPanel chartpanel = new ChartPanel(chart, false, false, false, false, false);   
    chartpanel.setVisible(true);      
    chartpanel.setPreferredSize(new Dimension(500, 270));
    return new JPanel();
}
public static void main(String[] args) {
    PieChart demo = new PieChart("Pie Chart");
    demo.pack();
    RefineryUtilities.centerFrameOnScreen(demo);
    demo.setVisible(true);
}
public void chartMouseClicked(ChartMouseEvent chartmouseevent){
ChartEntity chartentity = chartmouseevent.getEntity();
if (chartentity != null){
   System.out.println("Mouse clicked: " + chartentity.toString());
}
else
System.out.println("Mouse clicked: null entity.");
}

public void chartMouseMoved(ChartMouseEvent chartmouseevent){
}
}









Related Tutorials/Questions & Answers:
chartMouseClicked(ChartMouseEvent event)
chartMouseClicked(ChartMouseEvent event)  Hi deepak ihave draw a piechart using jfreechart with tooltip.Now i need click event (chartMouseClicked(ChartMouseEvent event)) in this chart. can u help me plz
event handling
event handling  diff btwn event handling in ASP.net and in HTML
Advertisements
Event Listeners
Event Listeners  I want to learn the Event Listeners in Java. Any... is the good tutorial and example of Event Listeners in Java. Please check the tutorial Java - Event Listeners Example in Java Applet. Thanks
Flex event
Flex event  Hi.... please tell me about How does Flex event system works? Thanks  Ans: When event are triggered there are three...: In the capturing phase, Flex examines an event target?s ancestors in the display list to see
Event management
Event management   Hi, I want event management application like maintaining email notifications while task creation and update in broader way using spring java
Event in flex
Event in flex  Hi..... I want to know about What does calling preventDefault() on an event do? How is this enforced?ADS_TO_REPLACE_1 please give... of the Event class can be used in event listener functions to affect the behavior
Flex event
Flex event  Hi... please give me the answer with example What is event Bubbling? Thanks in advance  Event Bubbling: In the bubbling phase, Flex examines an event?s ancestors for event listeners. Flex starts
Flex event
Flex event  hi...... How to capture and event if the component is disabled? please give an example..... Thanks in advance
Flex event
Flex event  Hi.... Please tell me about How to create your own event in flex? Thanks
Event in flex
Event in flex  Hi..... can you tell me about that How do you make component participate in event mechanism?ADS_TO_REPLACE_1 Thanks   Ans: Extend EventDispatcher or any subclass of it or implement IEventDispatcher
Version of d-haven-event>event dependency
List of Version of d-haven-event>event dependency
Version of excalibur-event>excalibur-event dependency
List of Version of excalibur-event>excalibur-event dependency
Click event
Click event  hi............ how to put a click event on a particular image, so that it can allow to open another form or allow to display result in tabular form????????/ can u tell me how to do that????????/ using java swings
Java event handling
Java event handling  What event results from the clicking of a button
How to Handle Event Handlers?
How to Handle Event Handlers?  How to Handle Event Handlers
handling Button Event in iphone
handling Button Event in iphone  handling Button Event in iphone
Java event-listener
Java event-listener  What is the relationship between an event-listener interface and an event-adapter class
Java event delegation model
Java event delegation model  What is the highest-level event class of the event-delegation model
Version of excalibur-event>excalibur-event-api dependency
List of Version of excalibur-event>excalibur-event-api dependency
Version of excalibur-event>excalibur-event-impl dependency
List of Version of excalibur-event>excalibur-event-impl dependency
Event listener in JavaScript with example
Event listener in JavaScript with example  What is event listener in JavaScript? Can anyone please post an example of Event listener?? Thanks in Advance
Java event-delegation model
Java event-delegation model  What is the advantage of the event-delegation model over the earlier eventinheritance model
Java event handling
Java event handling  Which java.util classes and interfaces support event handling
Event handling on an image
Event handling on an image  I want to divide an image into frames and want to do event handling on the frames
Event helpers
Event helpers       Event helpers As we all know events are actions or occurrences detected by a program. And event handlers are methods which handles
delegation event model
delegation event model  What is delegation event model?   delegation event model In the event-delegation model, specific objects are designated as event handlers for GUI components. These objects implement event
ModuleNotFoundError: No module named 'event'
ModuleNotFoundError: No module named 'event'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'event' How to remove the ModuleNotFoundError: No module named 'event'
Java AWT event hierarchy
Java AWT event hierarchy  What class is the top of the AWT event hierarchy?  The java.awt.AWTEvent class is the highest-level class in the AWT event-class hierarchy
event calendar sample
event calendar sample  creating a event calendar for my small app in PHP.. can any one explain about it's design with example php event calendar script
Java event handling
Java event handling  What is the purpose of the enableEvents() method
Version of d-haven-event>d-haven-event dependency
List of Version of d-haven-event>d-haven-event dependency
event tracking code
event tracking code  a javascript written that will help us to track sitewide, even tracking in Google Analytics
Event listeners in mxml
Event listeners in mxml  hi.. just tell me about How do you add event listeners in mxml components. Now AS3 components? Please give... for add a event listner in flex using action script. 1. addEventListener(type:String
Maven Dependency event >> 1.0.1
You should include the dependency code given in this page to add Maven Dependency of d-haven-event >> event version1.0.1 in your project
Maven Dependency event >> 1.0.2
You should include the dependency code given in this page to add Maven Dependency of d-haven-event >> event version1.0.2 in your project
Artifacts of d-haven-event
List of Artifacts of d-haven-event maven depenency
Artifacts of excalibur-event
List of Artifacts of excalibur-event maven depenency
KEY EVENT HANDLING
KEY EVENT HANDLING  I am trying to write a program that receives every key stroke even when the window is not active or it's minimized. Is there anyway to do
javascript event handling examples
javascript event handling examples  javascript event handling examples   var handleClick = function(e) { // Older IEs set the `event... event listeners. document.attachEvent('onclick', handleClick); } else
Maven Repository/Dependency: d-haven-event | event
Maven Repository/Dependency of Group ID d-haven-event and Artifact ID event. Latest version of d-haven-event:event dependencies. # Version Release Date 1 1.0.2 01 Aug
Maven Repository/Dependency: excalibur-event | excalibur-event
Maven Repository/Dependency of Group ID excalibur-event and Artifact ID excalibur-event. Latest version of excalibur-event:excalibur-event dependencies. # Version Release Date 1
Need an Example of calendar event in java
Need an Example of calendar event in java  can somebody give me an example of calendar event of java
jquery href onclick event
jquery href onclick event  jquery href onclick event   $('a').click(function (event) { event.preventDefault(); //here you can also do all sort of things });   <script type="text/javascript
onmouseover event in jsf
onmouseover event in jsf  hello friends, I am in the middle of the project, I have a requirement in my project. I am using jsf ,spring, hibernate... want to dispaly the list of some documents by using onmouseover event in jsf
Maven Dependency excalibur-event >> 1.0.3
You should include the dependency code given in this page to add Maven Dependency of excalibur-event >> excalibur-event version1.0.3 in your project
Maven Dependency excalibur-event >> 1.0a
You should include the dependency code given in this page to add Maven Dependency of excalibur-event >> excalibur-event version1.0a in your project
Maven Dependency excalibur-event >> 20030217.000000
You should include the dependency code given in this page to add Maven Dependency of excalibur-event >> excalibur-event version20030217.000000 in your project
JQuery-event working new element
JQuery-event working new element  I want to know- why not an event(in JQuery) works on my created element through jQuery
iphone button click event
iphone button click event  Hi, How to write iphone button click event? Thanks   Hi, Here the method declaration: -(IBAction) myMetod:(id) sender; and implementations is: -(IBAction) myMetod:(id) sender
uibutton touch up event
uibutton touch up event   UIButton event "Touch up inside" under Gesture is not working in my app ..   [button addTarget:self action:@selector(BtnPressed:) forControlEvents:UIControlEventTouchUpInside];   

Ads