chartMouseClicked(ChartMouseEvent event)

Ads
 

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){
}
}

Ads









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
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
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
handling Button Event in iphone
handling Button Event in iphone  handling Button Event in iphone
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
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'
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
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
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
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
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
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];   
JQuery date change event
JQuery date change event  JQuery date change event I have been designing a date form in HTML and JQuery, wher i need two different date vales start date and end date for any event. I have already writen a function that allows

Ads