Hi,
I am experiencing a lag in performance when performing action similar to the Curve Fitting Demo Application in the TeeChart live demo.
To summarize:
I have n Series on a chart, and i have also a ShapeSerie for each of them in a form of a little circle that is moving according to the mouse motion on the curves. The calculations are the ones used in the demo (where it shows good results) with one difference that the circle is drawn on the original series and not on a fitted curve.
Can it be that the lag is happening because of the fact that the MouseMotionListener is taking up way too much CPU time so the drawing is lagged?
The code that I'm using for the calculations is the following:
(x is the current x position of the mouse)
double tmpX = mainChart.getAxes().getBottom().calcPosPoint(x);
int i = (int)Math.round(tmpX);
double tmpY;
try
{
tmpY = mainSeries.getYValues().getValue(i);
}
catch(ArrayIndexOutOfBoundsException e)
{
return;
}
int yValue = mainChart.getAxes().getLeft().calcPosValue(tmpY);
int xValue = mainChart.getAxes().getBottom().calcPosValue(i);
Thank you in advance to all the responses.
UniCoders
Problems with late drawing response
Hello,
We have tried your code in a new project and found it to work without any apparent time overhead.
To confirm the code we used:
Is it possible there is another element in your project that is adding a check whilst the mouse moves?
If you are able to use the above code and find it to show the same performance issue after any modification please let us know, or send us more information about other aspects of the project/form that may influence the result.
With thanks.
Regards,
Marc Meumann
We have tried your code in a new project and found it to work without any apparent time overhead.
To confirm the code we used:
Code: Select all
private void initTChart(){
tChart.setHeight(100);
tChart.setMinimumSize(new java.awt.Dimension(100, 100));
tChart.setPreferredSize(new java.awt.Dimension(100, 100));
tChart.setWidth(100);
shapeSeries = new Shape(tChart.getChart());
shapeSeries.setActive(true);
shapeSeries.getMarks().setVisible(false);
shapeSeries.setXYStyle(ShapeXYStyle.PIXELS);
shapeSeries.setTitle("Shape");
shapeSeries.setShowInLegend(false);
shapeSeries.setX0(0);
shapeSeries.setX1(1);
shapeSeries.setY0(0);
shapeSeries.setY1(1);
mat = new double[15][24];
for(int i=0; i<3; i++){
lineSeries = new com.steema.teechart.styles.Line(tChart.getChart());
lineSeries.setClickableLine(false);
for(int j=0; j<24; j++){
lineSeries.add(10*Math.random());
}
tChart.addMouseMotionListener( new MouseMotionAdapter() {
public void mouseMoved(MouseEvent e) {
double tmpX = tChart.getAxes().getBottom().calcPosPoint(e.getX());
int i = (int)Math.round(tmpX);
double tmpY;
try
{
tmpY = lineSeries.getYValues().getValue(i);
}
catch(ArrayIndexOutOfBoundsException ee)
{
return;
}
int yValue = tChart.getAxes().getLeft().calcPosValue(tmpY);
//int xValue = tChart.getAxes().getBottom().calcPosValue(i);
// set the "circle shape" bounds...
shapeSeries.setX0(e.getX()-10.0);
shapeSeries.setX1(e.getX()+10.0);
shapeSeries.setY0(yValue-10.0);
shapeSeries.setY1(yValue+10.0);
}
});
}
tChart.getFooter().setVisible(true);
tChart.getHeader().setVisible(true);
tChart.getAspect().setView3D(false);
tChart.getLegend().setVisible(false);
tChart.setBackground(Color.WHITE);
jFrameTeeChartCommander = new Commander(tChart.getChart());
jFrameTeeChartCommander.setFloatable(false);
jFrameTeeChartCommander.setVisible(true);
jFrameTeeChartCommander.setRollover(true);
jPanel1.setLayout(new BorderLayout());
jPanel1.add(jFrameTeeChartCommander, BorderLayout.PAGE_START);
jPanel1.add(tChart, BorderLayout.CENTER);
jPanel1.repaint();
jPanel1.validate();
}
If you are able to use the above code and find it to show the same performance issue after any modification please let us know, or send us more information about other aspects of the project/form that may influence the result.
With thanks.
Regards,
Marc Meumann
Steema Support