High Performance Apps
Tooltip not displayed when Shapes only are shown
I have try this XYRenderer and found to work almost correctly, I am still having some problems to display the tooltips on the when the lines are not displayed. It is working when the shapes and lines are drawn or when the lines only are plotted, but not when the shapes are plotted by themself. Does anyone would know how to fix this? This problem does not happen when the native XYLinesAndShapesRenderer is used.
BTW, I have added the two methods below for completness:
BTW, I have added the two methods below for completness:
public void setToolTipGenerator(XYToolTipGenerator toolTipGenerator) {
super.setToolTipGenerator(toolTipGenerator);
}
public void setURLGenerator(XYURLGenerator urlGenerator) {
super.setURLGenerator(urlGenerator);
}
[/code][/code]
-
- Posts: 58
- Joined: Wed Jun 02, 2004 1:37 pm
Re: Tooltip not displayed when Shapes only are shown
That does nothing but generate useless code bloat. A function that does nothing but call the its super implementation might as well not be there.nclemeur wrote:BTW, I have added the two methods below for completness:
Code: Select all
public void setToolTipGenerator(XYToolTipGenerator toolTipGenerator) { super.setToolTipGenerator(toolTipGenerator); } public void setURLGenerator(XYURLGenerator urlGenerator) { super.setURLGenerator(urlGenerator); }
I think I have found the reason why the tooltip are not generated when only the Shapes are drawn. The bAddEntity is never set to true when only shapes are drawn. So modifying the code like below solves the problem:
Code: Select all
if (getPlotShapes()) {
...
if (shape.intersects(dataArea)) {
bAddEntity = true;//<------------------------------Added
if (getItemShapeFilled(series, item)) {
g2.fill(shape);
}
else {
g2.draw(shape);
}
}
entityArea = shape;
}
Oops; my instructions failed to make it clear that you have to make a copy of StandardXYItemRenderer called StandardXYItemRendererProtected which has a number of its private members changed to protected (you can let the IDE figure out which ones are needed or just make them all protected). The optimzed class derives from this and overloads just one method. I figured this was cleaner than posting the whole class again plus it should be easier to update in the future if changes are made to StandardXYItemRenderer.
Theres is a remaining bug, which is also located in StandardXYItemRenderer.
Try to render a dataseries containing at least one Double.NaN (not at the border) with drawSeriesLineAsPath=true. The chart is empty.
I have posted the bug (#1380480) including a fix. I hope that David will integrate the fix in 1.0.1.
Testprogramm:
Try to render a dataseries containing at least one Double.NaN (not at the border) with drawSeriesLineAsPath=true. The chart is empty.
I have posted the bug (#1380480) including a fix. I hope that David will integrate the fix in 1.0.1.
Testprogramm:
Code: Select all
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardXYToolTipGenerator;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
/**
* A simple demo showing a dataset created using the {@link XYSeriesCollection} class.
*/
public class XYRendererNaNValuesTest
extends ApplicationFrame
{
/**
* A demonstration application showing an XY series containing a null value.
*
* @param title the frame title.
*/
public XYRendererNaNValuesTest(String title)
{
super(title);
XYDataset dataset = createDataset();
JFreeChart chart = createChart(dataset);
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
setContentPane(chartPanel);
}
private static JFreeChart createChart(XYDataset dataset)
{
JFreeChart chart = ChartFactory.createXYLineChart("XY Series Demo", "X", "Y", dataset,
PlotOrientation.VERTICAL, true, true, false);
StandardXYItemRenderer renderer = new StandardXYItemRenderer();
renderer.setDrawSeriesLineAsPath(true);
renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
chart.getXYPlot().setRenderer(renderer);
return chart;
}
private static XYDataset createDataset()
{
XYSeries series = new XYSeries("Random Data");
double t = 0.0;
double x = 0.0;
for (int i = 0; i < 10; i++)
{
t += Math.random();
series.add(t, Double.NaN);
}
for (int i = 0; i < 200; i++)
{
t += Math.random();
if (i == 120)
{
series.add(t, Double.NaN);
continue;
}
double r = Math.random();
if (r < 0.33)
{
x += Math.random();
}
else if (r < 0.66)
{
x -= Math.random();
}
series.add(t, x);
}
t += Math.random();
series.add(t, Double.NaN);
return new XYSeriesCollection(series);
}
public static JPanel createDemoPanel()
{
JFreeChart chart = createChart(createDataset());
return new ChartPanel(chart);
}
public static void main(String[] args)
{
XYRendererNaNValuesTest demo = new XYRendererNaNValuesTest("XY Series Demo");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}
}
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Too late! But I've just committed a fix for this bug which will be included in 1.0.2.uvoigt wrote:I have posted the bug (#1380480) including a fix. I hope that David will integrate the fix in 1.0.1.
Now to rescan the rest of this thread...
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader

