M
Mark
I have written a graphics program that generates a lot of data points
and as each data point is calculated, it is placed on the chart. I
decided to add each point as it is calculated, rather than to generate
all points and show the chart only when all points are done, as a bit of
eye-candy to keep the user interested.
The code fragments below shows how it is done:
===============
public void addPoint(DataPoint point)
{
// Vector of graph points
dataPoints.add(point);
repaint();
}
public void paint(Graphics g)
{
Graphics2D g2d = (Graphics2D)g;
// Draw X and Y axes, grid lines, and scale numbers.
// (some code here)
// Now draw the graph points in the dataPoints Vector.
int numPoints = dataPoints.size();
for (int i = 0; i < numPoints; i++)
{
// Various calculations to properply place each point
// in the g2d space...
}
}
================
As each point is generated, it is put into the dataPoints vector
(through the addPoint() method), and then a repaint() invokes the
paint() method. Note that the paint() method re-does everything. Even
if I already have 200 points on the chart, and I add the 201st point,
all 201 points are redrawn just to achieve the visual effect of adding a
201st point to the chart.
As more points are added, things seem slower, since all points have to
be redrawn in order to add the last new point.
Question: Is there a technique to just add one point to the EXISTING
chart without having to redraw the ENTIRE chart?
and as each data point is calculated, it is placed on the chart. I
decided to add each point as it is calculated, rather than to generate
all points and show the chart only when all points are done, as a bit of
eye-candy to keep the user interested.
The code fragments below shows how it is done:
===============
public void addPoint(DataPoint point)
{
// Vector of graph points
dataPoints.add(point);
repaint();
}
public void paint(Graphics g)
{
Graphics2D g2d = (Graphics2D)g;
// Draw X and Y axes, grid lines, and scale numbers.
// (some code here)
// Now draw the graph points in the dataPoints Vector.
int numPoints = dataPoints.size();
for (int i = 0; i < numPoints; i++)
{
// Various calculations to properply place each point
// in the g2d space...
}
}
================
As each point is generated, it is put into the dataPoints vector
(through the addPoint() method), and then a repaint() invokes the
paint() method. Note that the paint() method re-does everything. Even
if I already have 200 points on the chart, and I add the 201st point,
all 201 points are redrawn just to achieve the visual effect of adding a
201st point to the chart.
As more points are added, things seem slower, since all points have to
be redrawn in order to add the last new point.
Question: Is there a technique to just add one point to the EXISTING
chart without having to redraw the ENTIRE chart?