Page 1 of 1
NearestPoint-problem
Posted: Fri Feb 15, 2008 9:34 am
by 7667185
Hi. I am experiencing a problem when using the NearestPoint-tool: For some reason, it keeps drawing lines to points of series not present in the chart. So the question is, have you experienced before that Series that are removed still triggers the NearestPoint's listener?
I have created a small program which I will upload on your pages, illustrating the problem. Observe what happens after you enter a new Series. It might be related to the code but I explisitly remove all series.
Thanks in advance
M
Posted: Fri Feb 15, 2008 12:39 pm
by narcis
Hi Marius,
Thank you very much for the example project. I could reproduce the issue there but couldn't reproduce it using TeeChart.Features.jar, shipped with TeeChart for Java, going to the Tools\Nearest Point example and adding an additional series there.
Can you reproduce the problem in the demo (click the edit button for adding a new series and populating it)? If the problem can not be reproduced in the demo, could you please send us the full sources of the project you posted at the upload page so that we can reproduce and debug the problem here?
Thanks in advance.
Posted: Fri Feb 15, 2008 12:42 pm
by 7667185
Thanks for reply.
Sure, I'll test it now. But if the best way for you to check this is using the source of the dummy-project you can have it here right away, unless you'd rather want me to try it in the TCDemo first?
Posted: Fri Feb 15, 2008 12:44 pm
by narcis
Hi Marius,
Full test project sources would be fine.
Thanks in advance.
Posted: Fri Feb 15, 2008 12:46 pm
by 7667185
Enjoy
Code: Select all
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.steema.teechart.TChart;
import com.steema.teechart.styles.PointerStyle;
import com.steema.teechart.styles.Points;
import com.steema.teechart.tools.NearestPoint;
import com.steema.teechart.tools.NearestPointStyle;
public class PointTest extends JFrame implements ActionListener
{
JPanel dmb = new JPanel();
TChart myChart = new TChart();
JButton newSerButton = new JButton("Press for new series. Notice what happens when a new series is included");
NearestPoint tool = null;
int indicator = 0;
double[] testData = new double[50];
double[] testX = new double[50];
double[] testData1 = new double[50];
double[] testX1 = new double[50];
double[] testData2 = new double[50];
double[] testX2 = new double[50];
public static void main(String[] args)
{
new PointTest().setVisible(true);
}
public PointTest()
{
initialize();
}
public void initialize()
{
/******************/
for(int i=0;i<50;i++)
{
testData[i] = (i+50)*Math.pow(Math.random(),Math.random());
testX[i] = i;
testData1[i] = (i+50)*Math.pow(1,Math.random());
testX1[i] = i*Math.random()*7;
testData2[i] = (i+50)*Math.pow(2,Math.random());
testX2[i] = i*Math.random()*3;
}
/******************/
myChart.getChart().getAspect().setView3D(false);
newSerButton.addActionListener(this);
dmb.add(myChart);
dmb.add(newSerButton);
super.add(dmb);
super.setSize(600,400);
}
public void addSeries()
{
// I am removing all series, and invalidating the tool...
myChart.removeAllSeries();
if(tool != null)
{
myChart.doInvalidate();
tool = null;
}
Points p = new Points(myChart.getChart().chart);
if(indicator == 0)
{
p.add(testData);
p.getXValues().setValues(testX);
indicator ++;
}
else if(indicator == 1)
{
p.add(testData1);
p.getXValues().setValues(testX1);
indicator ++;
}
else
{
p.add(testData2);
p.getXValues().setValues(testX2);
indicator = 0;
}
// Newing the tool, to re-bind the listeners...
tool = new NearestPoint(myChart.getChart());
tool.getBrush().setVisible(true);
tool.setSeries(p);
tool.getBrush().setColor(new com.steema.teechart.drawing.Color(0,0,100));
tool.setStyle(NearestPointStyle.NONE);
tool.setSize(10);
tool.getPen().setColor(new com.steema.teechart.drawing.Color(50,100,150));
tool.setDrawLine(true);
p.getPointer().setStyle(PointerStyle.DIAMOND);
p.getPointer().getPen().setVisible(false);
myChart.getChart().addSeries(p);
myChart.repaint();
}
public void actionPerformed(ActionEvent e)
{
addSeries();
}
}
Posted: Fri Feb 15, 2008 3:19 pm
by narcis
Hi Marius,
Thanks for the example code. We could reproduce the issue here. What happens is that every time you click the button and therefore
addSeries() is called a new NearestPoint tool is created and assigned to the new series. So you have a tool for each series.
You have severial options here:
1. Only add one NearestPoint tool in the chart and assign it to the last series:
Code: Select all
if (tChart.getTools().size()==0)
{
tool = new NearestPoint(tChart.getChart());
}
2. Disable existing tools and only enable last series tool:
Code: Select all
for (int i=0; i<tChart.getTools().size(); i++)
{
tChart.getTools().getTool(i).setActive(false);
}
tool = new NearestPoint(tChart.getChart());
There are some other combinations based on what I told you above. You'll have to decide for the option more suitable to your needs.
Hope this helps!
Posted: Mon Feb 18, 2008 8:26 am
by 7667185
Ahhh entiendo! It worked when inactivating the previous tools
Muchos gracias
Posted: Mon Feb 18, 2008 10:37 am
by narcis
Hi Marius,
You're welcome. I'm glad to hear that helped.