I have a graph like this . I want to add button on each point of the graph like in (1,1) , (2,4) and so on. I want do different thing when i click on this button.How can i do it?
Asked
Active
Viewed 597 times
1
-
Please don't keep repeating the same question; instead, edit your [original question](http://stackoverflow.com/questions/29192514/drawing-line-chart-in-java) to include a [complete example](http://stackoverflow.com/help/mcve) that exhibits any problem you encounter. – trashgod Mar 23 '15 at 01:49
1 Answers
1
First of all, you should provide some code of your existing project, it is much easier to help you!
I am not completely sure about this code, but pls give it a try:
JFreeChart chart = ChartFactory.createXYLineChart(...);
chart.addChartMouseListener(new ChartMouseListener() {
@Override
public void chartMouseClicked(ChartMouseEvent e) {
System.out.println("Click event!");
if(e.getChartEntity != null){
System.out.println("clicked directly on the chart");
}
}
});
regards me

Christian
- 609
- 8
- 22
-
i will use the same code of this [link](http://www.java2s.com/Code/Java/Chart/JFreeChartLineChartDemo6.htm) your code works but it works for the whole panel but what i want is to click on specific point and do specific things like the graph in [this](http://codeforces.com/profile/tourist) link. – Mahmudur Rahman Mar 22 '15 at 20:52
-
Hey. Oh I am sorry that my answer wasn't correct. I only had the documentation on hand but couldn't try it myself. But I'm glad you worked it out. – Christian Mar 22 '15 at 21:36