Read values on Jfreechart graph

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
marouene_
Posts: 15
Joined: Fri Apr 01, 2011 3:32 pm
antibot: No, of course not.

Read values on Jfreechart graph

Post by marouene_ » Fri Apr 22, 2011 10:45 am

Hello, i want to know if it's possible to read the values when i put the cursor on the graph like this

Image

marouene_
Posts: 15
Joined: Fri Apr 01, 2011 3:32 pm
antibot: No, of course not.

Re: Read values on Jfreechart graph

Post by marouene_ » Wed Apr 27, 2011 12:11 pm

no idea?

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Read values on Jfreechart graph

Post by paradoxoff » Sat Apr 30, 2011 7:37 am

In principle that is possible by using XYItemEntities and tool tips.
There is not much that you need to do to activate them.
Here is a code snippet:

Code: Select all

public class SimpleToolTipDemo {
	public static void main(String[] args) {
		DefaultXYDataset set = new DefaultXYDataset();
		set.addSeries("Values",new double[][]{{-10,-1,-0.1,0,0.1,1,10},{-0.1,-1,-10,Double.NaN,10,1,0.1}});		
		JFreeChart chart = ChartFactory.createXYLineChart(
			"Tool Tips","x","y",
			set,PlotOrientation.VERTICAL,true, true, false);
		XYItemRenderer r = chart.getXYPlot().getRenderer();
		r.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
		JFrame frame = new JFrame("Test");
		frame.setContentPane(new ChartPanel(chart));
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}
}

Locked