我在Android中的AchartEngine Scatter图表中遇到了一个问题。在将缩放设置为某个级别后平移时,每个点之间的线条会消失。 我曾尝试将hardwareAcceleration设置为false,并将setLayerType设置为null和all。但问题仍然存在。
Achartengine版本1.1.0。 Android设备 - Galaxy S4,S3。 你能帮帮我吗?
屏幕截图位于http://i.stack.imgur.com/hq5r4.png
感谢
JRH
答案 0 :(得分:0)
经过两天的努力,我能够解决问题。这是由于Float.NaN的一个Path值,同时绘制线。
问题是AbstractChart - > drawPath方法。在那个calculateDrawPoints()方法中返回一个float数组,在一个case中包含Float.NaN。我不知道背后的问题。但我可以用Canvas.drawLine方法克服它。
由于
JRH
答案 1 :(得分:0)
因为AbstarctChart ==> calculateDrawPoints()方法返回包含Float.NaN
的float数组因为在计算过程中,有时值返回0,并且在将值除以0之后,我们得到Float.NaN 除以零的任何内容都是未定义的
因此,请使用以下
更新calculateDrawPoints()方法代码private static float[] calculateDrawPoints(float p1x, float p1y, float p2x, float p2y,
int screenHeight, int screenWidth) {
float drawP1x = 0;
float drawP1y;
float drawP2x = 0;
float drawP2y;
if (p1y > screenHeight) {
// Intersection with the top of the screen
float m = (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;
} else if (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;
}
} else if (p1y < 0) {
float n = p2x - p1x;
float m = 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;
} else if (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) {
float n = (p2x - p1x);
float m = 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;
} else if (drawP2x > screenWidth) {
drawP2x = screenWidth;
drawP2y = m * screenWidth + p1y - m * p1x;
}
} else if (p2y < 0) {
float n = (p2x - p1x);
float m = 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;
} else if (drawP2x > screenWidth) {
drawP2x = screenWidth;
drawP2y = m * screenWidth + p1y - m * p1x;
}
} else {
// If the point is in the screen use it
drawP2x = p2x;
drawP2y = p2y;
}
return new float[] { drawP1x, drawP1y, drawP2x, drawP2y };
}
这将解决您的问题