Achartengineline Chart In Android - Line Disappears While Panning
I am facing an issue in AchartEngine Scatter chart in android. The line between each point, disappears when panning after set zoom to a level. I had tried hardwareAcceleration to
Solution 1:
After two days of effort, I was able to solve the issue. It was due to Float.NaN for one of the Path value, while drawing the line.
Issue was AbstractChart -> drawPath method. In that calculateDrawPoints() method returns a float array, which contains Float.NaN in one case. I dont know the issue behind it. But I could overcome that with Canvas.drawLine method.
Thanks
JRH
Solution 2:
Its because AbstarctChart==> calculateDrawPoints() method returns float array which contains Float.NaN
Its because during calculation, sometimes value returns 0, and after dividing value with 0, we get Float.NaN Anything divided by zero is undefined
So update your calculateDrawPoints() method code with following
privatestaticfloat[] calculateDrawPoints(float p1x, float p1y, float p2x, float p2y,
int screenHeight, int screenWidth) {
floatdrawP1x=0;
float drawP1y;
floatdrawP2x=0;
float drawP2y;
if (p1y > screenHeight) {
// Intersection with the top of the screenfloatm= (p2y - p1y) / (p2x - p1x);
if (m != 0) {
drawP1x = (screenHeight - p1y + m * p1x) / m;
} else {
drawP1x = (screenHeight - p1y + m * p1x);
}
drawP1y = screenHeight;
if (drawP1x < 0) {
// If Intersection is left of the screen we calculate the intersection// with the left border
drawP1x = 0;
drawP1y = p1y - m * p1x;
} elseif (drawP1x > screenWidth) {
// If Intersection is right of the screen we calculate the intersection// with the right border
drawP1x = screenWidth;
drawP1y = m * screenWidth + p1y - m * p1x;
}
} elseif (p1y < 0) {
floatn= p2x - p1x;
floatm=0;
if (n != 0) {
m = (p2y - p1y) / n;
} else {
m = (p2y - p1y);
}
if (m != 0) {
drawP1x = (-p1y + m * p1x) / m;
} else {
drawP1x = (-p1y + m * p1x);
}
drawP1y = 0;
if (drawP1x < 0) {
drawP1x = 0;
drawP1y = p1y - m * p1x;
} elseif (drawP1x > screenWidth) {
drawP1x = screenWidth;
drawP1y = m * screenWidth + p1y - m * p1x;
}
} else {
// If the point is in the screen use it
drawP1x = p1x;
drawP1y = p1y;
}
if (p2y > screenHeight) {
floatn= (p2x - p1x);
floatm=0;
if (n != 0) {
m = (p2y - p1y) / n;
} else {
m = (p2y - p1y);
}
if (m != 0) {
drawP2x = (screenHeight - p1y + m * p1x) / m;
} else {
drawP2x = (screenHeight - p1y + m * p1x);
}
drawP2y = screenHeight;
if (drawP2x < 0) {
drawP2x = 0;
drawP2y = p1y - m * p1x;
} elseif (drawP2x > screenWidth) {
drawP2x = screenWidth;
drawP2y = m * screenWidth + p1y - m * p1x;
}
} elseif (p2y < 0) {
floatn= (p2x - p1x);
floatm=0;
if (n != 0) {
m = (p2y - p1y) / n;
} else {
m = (p2y - p1y);
}
if (m != 0) {
drawP2x = (-p1y + m * p1x) / m;
} else {
drawP2x = (-p1y + m * p1x);
}
drawP2y = 0;
if (drawP2x < 0) {
drawP2x = 0;
drawP2y = p1y - m * p1x;
} elseif (drawP2x > screenWidth) {
drawP2x = screenWidth;
drawP2y = m * screenWidth + p1y - m * p1x;
}
} else {
// If the point is in the screen use it
drawP2x = p2x;
drawP2y = p2y;
}
returnnewfloat[] { drawP1x, drawP1y, drawP2x, drawP2y };
}
That will resolve your issue
Post a Comment for "Achartengineline Chart In Android - Line Disappears While Panning"