【发布时间】:2012-12-05 20:01:01
【问题描述】:
我正在为我的应用程序开发一个简单的统计图形类。我已经尝试过 aChartEngine 和其他更多,但我更喜欢使用我自己的类。 我正在使用包含 Android 的 Canvas 类绘制图形,但问题是我不知道如何填充线条和底部边框之间的区域。 现在,矩形并没有填满所有区域,显然,你知道任何解决方案吗?非常感谢。
【问题讨论】:
标签: android graphics canvas statistics
我正在为我的应用程序开发一个简单的统计图形类。我已经尝试过 aChartEngine 和其他更多,但我更喜欢使用我自己的类。 我正在使用包含 Android 的 Canvas 类绘制图形,但问题是我不知道如何填充线条和底部边框之间的区域。 现在,矩形并没有填满所有区域,显然,你知道任何解决方案吗?非常感谢。
【问题讨论】:
标签: android graphics canvas statistics
使用Path,与Paint 一起调用.setStyle(Paint.Style.FILL);。
Path fillPath = new Path();
fillPath.moveTo(0, 0); // Your origin point
fillPath.lineTo(x1, y1); // First point
// Repeat above line for all points on your line graph
fillPath.lineTo(xN, yN); // Final point
fillPath.lineTo(xN, 0); // Draw from final point to the axis ++
fillPath.lineTo(0, 0); // Same origin point
yourCanvas.drawPath(fillPath, /* Your paint */);
++ 感谢@TheCapn 的这一点。
【讨论】:
fillPath.lineTo(x,0); 这样的最后一行,如果在轴上方,不会减少留下未填充的区域。
lastPoint.y 将是 0。)
fillPath.close() 或以任何方式结束行回到开头。还是lineTo 回到起点足以让Path 弄清楚。
close()...这可能是最佳实践,但没有必要。