Hi everybody, i am new to JFreeChart and have been playing a bit with its features over the last several days.
It is amazing what you have developed.
Now to my question, which i could not answer via a forumsearch.
I want to use a scatterplot for displaying several items. The user should be able to select items displayed on the scatterplot.
Is there something like that already developed? I found nearly nothing about user interaction.
The idea is, that a user can select multiple items and than press a button to see more details conserning this item.
Interaction, getting mouseclicks
Re: Interaction, getting mouseclicks
Hey, okay it seems, that JFChart has a way to check for user interaction 
Where would i now manipulate the renderer to paint a circle for example round the clicked entity?

Code: Select all
chartPanel.addChartMouseListener(this);
Code: Select all
public void chartMouseClicked(ChartMouseEvent event) {
if (event.getEntity() != null) {
System.out.println("Entity: "+event.getEntity());
System.out.println(event.getEntity().getToolTipText());
XYItemEntity entity = (XYItemEntity) event.getEntity();
System.out.println("Entity item: " + entity.getItem());
System.out.println("Entity seriesindex: " + entity.getSeriesIndex());
System.out.println("Entity dataset: " + entity.getDataset())
}
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: Interaction, getting mouseclicks
Some interaction features are being developed right now, you can see some of this in the Subversion trunk (code that will eventually get released as JFreeChart 1.2.0). I need to get some demos of this posted, and get people interested in testing it out. The idea is to have the option to attach selection status to datasets and then to allow the user to interactively select / deselect data items from a dataset, and also to be able to control how the renderer highlights selected items.
You could write your own stuff just using the ChartMouseListener mechanism, but you'll probably get further faster by just following what is happening with the code in the Subversion trunk.
You could write your own stuff just using the ChartMouseListener mechanism, but you'll probably get further faster by just following what is happening with the code in the Subversion trunk.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Re: Interaction, getting mouseclicks
Tank you for your fast answer.
I will check it out tomorrow
I will check it out tomorrow

-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: Interaction, getting mouseclicks
Great. If you tell me some more about what you are trying to achieve, I'll give you some hints about what is already working, and what is being worked on. I have some demos scattered around too that I can try to post.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Re: Interaction, getting mouseclicks
Hey i checked out the SVN and found some selection support. I will try to test it in the next hours.
What i want to do:
I have a system with Entities with 6-7 parameters. To visualize all attributes in a way, that humans can analyse it i will use different plotters in different frames.
The idea is, that when the user identifies odd-entities he can click on it, it will highlight/be selected in all plots in all frames and the user can see all underlaying informations.
So what i need is a way, that a user can select one or many items in the plot. Rightclick on it to use a special popup menü to use things like "select on all other plots" or "open detailview window".

This is one possible Scatterplot. So when the user clicks for example on a green rectangle, he can see this item be highlighted in every other plot, and can access specialcommands via a popup frame
What i want to do:
I have a system with Entities with 6-7 parameters. To visualize all attributes in a way, that humans can analyse it i will use different plotters in different frames.
The idea is, that when the user identifies odd-entities he can click on it, it will highlight/be selected in all plots in all frames and the user can see all underlaying informations.
So what i need is a way, that a user can select one or many items in the plot. Rightclick on it to use a special popup menü to use things like "select on all other plots" or "open detailview window".

This is one possible Scatterplot. So when the user clicks for example on a green rectangle, he can see this item be highlighted in every other plot, and can access specialcommands via a popup frame
Re: Interaction, getting mouseclicks
Hi it seems very nice what you are doing.
The problem is, that much has changed with the new version and so it is not so easy to upgrade to the newest version without changing many of ourcomponents, cause we currenty on an very old version
I found a way to "simulate" selected ScatterPoints by using annotations. When clickt on an entity i will now use a circle annotation to simulate that it has been selected. It is not a very nice way to do so, but i hope it will function.
The problem is, that much has changed with the new version and so it is not so easy to upgrade to the newest version without changing many of ourcomponents, cause we currenty on an very old version

I found a way to "simulate" selected ScatterPoints by using annotations. When clickt on an entity i will now use a circle annotation to simulate that it has been selected. It is not a very nice way to do so, but i hope it will function.
Re: Interaction, getting mouseclicks
Hi, David and all,
I would like to use mouse click to switch plotting 2 datasets.
The listener response ok. However, I could not switch to
dataset 'A'.
How to make this work? Thanks
Honglin
===========================
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.JFrame;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartMouseEvent;
import org.jfree.chart.ChartMouseListener;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYErrorRenderer;
import org.jfree.data.xy.XYIntervalSeries;
import org.jfree.data.xy.XYIntervalSeriesCollection;
public class SwitchAB {
private XYIntervalSeriesCollection dataset1 =
new XYIntervalSeriesCollection();
private XYIntervalSeriesCollection dataset2 =
new XYIntervalSeriesCollection();
private XYPlot plot = null;
JFreeChart chart = null;
private boolean isA = false;
public SwitchAB() {
}
public JFreeChart createChart() {
XYErrorRenderer renderer = new XYErrorRenderer();
NumberAxis rangeAxisX = new NumberAxis("X");
NumberAxis rangeAxisY = new NumberAxis("Y");
plot = new XYPlot(null, rangeAxisX, rangeAxisY, null);
plot.setRenderer(renderer);
String tp = "";
if (isA) {
tp = "A";
plot.setDataset(dataset1);
}
else {
tp = "B";
plot.setDataset(dataset2);
}
chart = new JFreeChart(tp, plot);
chart.setBackgroundPaint(Color.white);
return chart;
}
public ChartPanel getPanel() {
ChartPanel pnl = new ChartPanel(createChart()) {
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (chart == null) {
return;
}
}
};
pnl.addChartMouseListener(new ChartMouseListener() {
public void chartMouseClicked(ChartMouseEvent arg0) {
int seriesCount = dataset1.getSeriesCount();
if (seriesCount > 0) {
System.err.println("switch data set A/B");
isA = !isA;
createChart();
}
else {
isA = false;
}
}
public void chartMouseMoved(ChartMouseEvent arg0) {
}
});
pnl.setMouseZoomable(false);
return pnl;
}
public static void main(String[] args) {
JFrame frm = new JFrame();
frm.setTitle("Switch AB");
frm.setSize(new Dimension(400, 300));
SwitchAB switchAB = new SwitchAB();
XYIntervalSeries a = new XYIntervalSeries("A", false, true);
a.add(1, 0.9, 1.1, 2, 1.8, 2.3);
switchAB.dataset1.addSeries(a);
XYIntervalSeries b = new XYIntervalSeries("B", false, true);
b.add(4, 3.9, 4.1, 7, 6.8, 7.3);
switchAB.dataset2.addSeries(b);
frm.getContentPane().add(switchAB.getPanel());
frm.setVisible(true);
}
}
I would like to use mouse click to switch plotting 2 datasets.
The listener response ok. However, I could not switch to
dataset 'A'.
How to make this work? Thanks
Honglin
===========================
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.JFrame;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartMouseEvent;
import org.jfree.chart.ChartMouseListener;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYErrorRenderer;
import org.jfree.data.xy.XYIntervalSeries;
import org.jfree.data.xy.XYIntervalSeriesCollection;
public class SwitchAB {
private XYIntervalSeriesCollection dataset1 =
new XYIntervalSeriesCollection();
private XYIntervalSeriesCollection dataset2 =
new XYIntervalSeriesCollection();
private XYPlot plot = null;
JFreeChart chart = null;
private boolean isA = false;
public SwitchAB() {
}
public JFreeChart createChart() {
XYErrorRenderer renderer = new XYErrorRenderer();
NumberAxis rangeAxisX = new NumberAxis("X");
NumberAxis rangeAxisY = new NumberAxis("Y");
plot = new XYPlot(null, rangeAxisX, rangeAxisY, null);
plot.setRenderer(renderer);
String tp = "";
if (isA) {
tp = "A";
plot.setDataset(dataset1);
}
else {
tp = "B";
plot.setDataset(dataset2);
}
chart = new JFreeChart(tp, plot);
chart.setBackgroundPaint(Color.white);
return chart;
}
public ChartPanel getPanel() {
ChartPanel pnl = new ChartPanel(createChart()) {
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (chart == null) {
return;
}
}
};
pnl.addChartMouseListener(new ChartMouseListener() {
public void chartMouseClicked(ChartMouseEvent arg0) {
int seriesCount = dataset1.getSeriesCount();
if (seriesCount > 0) {
System.err.println("switch data set A/B");
isA = !isA;
createChart();
}
else {
isA = false;
}
}
public void chartMouseMoved(ChartMouseEvent arg0) {
}
});
pnl.setMouseZoomable(false);
return pnl;
}
public static void main(String[] args) {
JFrame frm = new JFrame();
frm.setTitle("Switch AB");
frm.setSize(new Dimension(400, 300));
SwitchAB switchAB = new SwitchAB();
XYIntervalSeries a = new XYIntervalSeries("A", false, true);
a.add(1, 0.9, 1.1, 2, 1.8, 2.3);
switchAB.dataset1.addSeries(a);
XYIntervalSeries b = new XYIntervalSeries("B", false, true);
b.add(4, 3.9, 4.1, 7, 6.8, 7.3);
switchAB.dataset2.addSeries(b);
frm.getContentPane().add(switchAB.getPanel());
frm.setVisible(true);
}
}