I'm developing a simple statistical graphics class for my application. I've tried aChartEngine and others more, but I prefer use my own classes. I'm drawing the graphics with the Canvas class that includes Android, but the problem is that I don't know how to fill the area between the line and the bottom border. Right now, the rectangles don't fill all the area, obviously, do You know any solution? Thanks a lot.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Use a Path
, with a Paint
which has .setStyle(Paint.Style.FILL);
called.
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 */);
++ Thanks to @TheCapn for this bit.