hellocharts-android
hellocharts-android copied to clipboard
When all y value are same, the chart draws nothing.
I am using hellochart. When I add some test data,I found the chart doesn't work if all y data are same. for example I set all y data to 11, then nothing was drawn on the chart. But if I adjust any one y data to 12, it works.
for(int i=0; i!=intervalMonth;++i){ beginDate.add(Calendar.MONTH,1);
mPointValues.add(new PointValue(i ,11));
}
//draws nothing
mPointValues.set(0,new PointValue(0,12)); //draws OK.
P.S. I am using the basic line chart BTW, how to set 0 as the starting point of y axis. By default it will be the smallest Y value.
I got the same issue.
me too. I got the same issue.
the same problem in LineChart, So I have try this fix in LineChartRenderer.java and it's nice to me:
private void calculateMaxViewport() {
tempMaximumViewport.set(Float.MAX_VALUE, Float.MIN_VALUE, Float.MIN_VALUE, Float.MAX_VALUE);
LineChartData data = dataProvider.getLineChartData();
boolean isYValueAllSame = true;
float yValRecord;
if (data.getLines().size() > 0
&& data.getLines().get(0) != null
&& data.getLines().get(0).getValues() != null
&& data.getLines().get(0).getValues().size() > 0) {
yValRecord = data.getLines().get(0).getValues().get(0).getY();
} else {
return;
}
for (Line line : data.getLines()) {
// Calculate max and min for viewport.
for (PointValue pointValue : line.getValues()) {
if (pointValue.getX() < tempMaximumViewport.left) {
tempMaximumViewport.left = pointValue.getX();
}
if (pointValue.getX() > tempMaximumViewport.right) {
tempMaximumViewport.right = pointValue.getX();
}
if (pointValue.getY() < tempMaximumViewport.bottom) {
tempMaximumViewport.bottom = pointValue.getY();
}
if (pointValue.getY() > tempMaximumViewport.top) {
tempMaximumViewport.top = pointValue.getY();
}
if (yValRecord != pointValue.getY()) {
isYValueAllSame = false;
}
}
}
if (isYValueAllSame) {
float offset = yValRecord / 10;
tempMaximumViewport.bottom -= offset;
tempMaximumViewport.top += offset;
}
}
I've moved to another chart Engine. But anyway thank you .
发自网易邮箱大师 On 4/28/2018 15:26,Lu Yang[email protected] wrote:
the same problem in LineChart, So I have try this fix in LineChartRenderer.java and it's nice to me:
`private void calculateMaxViewport() { tempMaximumViewport.set(Float.MAX_VALUE, Float.MIN_VALUE, Float.MIN_VALUE, Float.MAX_VALUE); LineChartData data = dataProvider.getLineChartData();
boolean isYValueAllSame = true;
float yValRecord;
if (data.getLines().size() > 0
&& data.getLines().get(0) != null
&& data.getLines().get(0).getValues() != null
&& data.getLines().get(0).getValues().size() > 0) {
yValRecord = data.getLines().get(0).getValues().get(0).getY();
} else {
return;
}
for (Line line : data.getLines()) {
// Calculate max and min for viewport.
for (PointValue pointValue : line.getValues()) {
if (pointValue.getX() < tempMaximumViewport.left) {
tempMaximumViewport.left = pointValue.getX();
}
if (pointValue.getX() > tempMaximumViewport.right) {
tempMaximumViewport.right = pointValue.getX();
}
if (pointValue.getY() < tempMaximumViewport.bottom) {
tempMaximumViewport.bottom = pointValue.getY();
}
if (pointValue.getY() > tempMaximumViewport.top) {
tempMaximumViewport.top = pointValue.getY();
}
if (yValRecord != pointValue.getY()) {
isYValueAllSame = false;
}
}
}
if (isYValueAllSame) {
float offset = yValRecord / 10;
tempMaximumViewport.bottom -= offset;
tempMaximumViewport.top += offset;
}
}`
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
When all the Y-axis data are 0, we need to add a judgment of 0 to the previous one
private void calculateMaxViewport() {
tempMaximumViewport.set(Float.MAX_VALUE, Float.MIN_VALUE, Float.MIN_VALUE, Float.MAX_VALUE);
LineChartData data = dataProvider.getLineChartData();
boolean isYValueAllSame = true;
float yValRecord;
if (data.getLines().size() > 0
&& data.getLines().get(0) != null
&& data.getLines().get(0).getValues() != null
&& data.getLines().get(0).getValues().size() > 0) {
yValRecord = data.getLines().get(0).getValues().get(0).getY();
} else {
return;
}
for (Line line : data.getLines()) {
// Calculate max and min for viewport.
for (PointValue pointValue : line.getValues()) {
if (pointValue.getX() < tempMaximumViewport.left) {
tempMaximumViewport.left = pointValue.getX();
}
if (pointValue.getX() > tempMaximumViewport.right) {
tempMaximumViewport.right = pointValue.getX();
}
if (pointValue.getY() < tempMaximumViewport.bottom) {
tempMaximumViewport.bottom = pointValue.getY();
}
if (pointValue.getY() > tempMaximumViewport.top) {
tempMaximumViewport.top = pointValue.getY();
}
if (yValRecord != pointValue.getY()) {
isYValueAllSame = false;
}
}
}
if (isYValueAllSame) {
float offset = 10;
if(yValRecord!=0) {
offset = yValRecord / 10;
}
tempMaximumViewport.bottom -= offset;
tempMaximumViewport.top += offset;
}
}
and In the case of only one piece of data, I choose modify the chartcomputator. java and it's nice to me
public float computeRawX(float valueX) {
// TODO: (contentRectMinusAllMargins.width() / currentViewport.width()) can be recalculated only when viewport
// change.
final float pixelOffset = (valueX - currentViewport.left) * (contentRectMinusAllMargins.width() /
currentViewport.width());
if (Float.isNaN(pixelOffset)||Float.isInfinite(pixelOffset)) {
return contentRectMinusAllMargins.left + 0;
}
return contentRectMinusAllMargins.left + pixelOffset;
}
the same problem in LineChart, So I have try this fix in LineChartRenderer.java and it's nice to me:
private void calculateMaxViewport() { tempMaximumViewport.set(Float.MAX_VALUE, Float.MIN_VALUE, Float.MIN_VALUE, Float.MAX_VALUE); LineChartData data = dataProvider.getLineChartData(); boolean isYValueAllSame = true; float yValRecord; if (data.getLines().size() > 0 && data.getLines().get(0) != null && data.getLines().get(0).getValues() != null && data.getLines().get(0).getValues().size() > 0) { yValRecord = data.getLines().get(0).getValues().get(0).getY(); } else { return; } for (Line line : data.getLines()) { // Calculate max and min for viewport. for (PointValue pointValue : line.getValues()) { if (pointValue.getX() < tempMaximumViewport.left) { tempMaximumViewport.left = pointValue.getX(); } if (pointValue.getX() > tempMaximumViewport.right) { tempMaximumViewport.right = pointValue.getX(); } if (pointValue.getY() < tempMaximumViewport.bottom) { tempMaximumViewport.bottom = pointValue.getY(); } if (pointValue.getY() > tempMaximumViewport.top) { tempMaximumViewport.top = pointValue.getY(); } if (yValRecord != pointValue.getY()) { isYValueAllSame = false; } } } if (isYValueAllSame) { float offset = yValRecord / 10; tempMaximumViewport.bottom -= offset; tempMaximumViewport.top += offset; } }
Didn't help me, still doesn't see the Y axis when Y values has same values
List values = new ArrayList(); values.add(new PointValue(0, 0.27256473)); values.add(new PointValue(1, 0.27256472)); values.add(new PointValue(2, 0.27256475)); values.add(new PointValue(3, 0.27256477));