适用于 Android 的 GPL 兼容图形库
采用与这个问题类似的方法,我正在寻找一种绘制方法数据指向 Android 中的视图。最好是一个库,它将针对任意范围的输入执行此操作,并允许平移和缩放(通过捏合或缩放栏)。
现在,我对一个视图进行了子类化,该视图执行以下标准化:
final int width = View.MeasureSpec.getSize(this.widthMeasureSpec);
final int height = View.MeasureSpec.getSize(this.heightMeasureSpec);
final float factorA = width / (maxA - minA);
final float factorS = height / (maxS - minS);
final float constFactorA = factorA * minA;
final float constFactorS = factorS * minS;
final int dataLength = data.length;
for (int i = 0; i < dataLength; ++i) {
if (i % 2 == 0)
_data[i] = _data[i] * factorA - constFactorA;
else
_data[i] = _data[i] * factorS - constFactorS;
}
并在 onDraw() 中调用画布的 drawPoints 方法(另外,我在 onMeasure() 中更新了 this.widthMeasureSpec 和 this.heightMeasureSpec )。
这是以 minA/maxA 作为自变量的界限,以 minS/maxS 作为因变量的界限。
这对于显示数据来说效果很好,但我希望其他人已经解决了绘制轴和平移/缩放的问题。
我有大约 150,000 个数据点,我更愿意将它们保留为浮点数以节省一半的内存。我不知道 JavaScript 中的十进制数字有多大,但为了记忆起见,我真的不想通过 JavaScript 为 Google Charts API 或基于 HTML 的解决方案传递数据。
我在 MyTouch 3g(原来的,3.5 毫米插孔之前的版本,它的 RAM 升级)上运行它,所以性能是一个问题。我想在 GPLv3 下发布最终项目,因此这不包括 GraphView。
这些图表的类型与此相同,因此通过排除点进行的任何优化距离太近而无法显示在屏幕上肯定会产生影响。
In a similar approach to this question, I am looking for a way to plot data points on to a view in Android. Preferably, a library which will do this for arbitrary-ranged input, as well as allow panning and zooming (via pinch or zoom bar).
Right now, I have subclass-ed a view which does the following normalization:
final int width = View.MeasureSpec.getSize(this.widthMeasureSpec);
final int height = View.MeasureSpec.getSize(this.heightMeasureSpec);
final float factorA = width / (maxA - minA);
final float factorS = height / (maxS - minS);
final float constFactorA = factorA * minA;
final float constFactorS = factorS * minS;
final int dataLength = data.length;
for (int i = 0; i < dataLength; ++i) {
if (i % 2 == 0)
_data[i] = _data[i] * factorA - constFactorA;
else
_data[i] = _data[i] * factorS - constFactorS;
}
and a call in onDraw() to the drawPoints method of a canvas (also, I update this.widthMeasureSpec and this.heightMeasureSpec in onMeasure()).
This is with minA/maxA as the bounds for my independent variable and minS/maxS as the bounds for my dependent variable.
This works fine for displaying the data, but I am hoping someone else has solved the problem of drawing the axes and panning/zooming.
I have ~150,000 data points, and I would prefer to keep these as floats to save half the memory. I don't know how big decimal numbers are in JavaScript, but I really don't want to resort to passing data in through JavaScript for the Google Charts API or an HTML-based solution for memory's sake.
I'm running this on a MyTouch 3g (the original, before 3.5mm jack and it's RAM upgrade), so performance is an issue. I'd like to release the final project under the GPLv3, so this excludes GraphView.
The graphs are of the same type as this, so any optimization by excluding points that are too close together to show up on screen would definitely make a difference.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
sargas ,请检查 android-misc-widgets。它包含一个名为 < code>PlotView 以及示例
TestInterPolator
。希望有帮助。
sargas , do check android-misc-widgets.It contains a widget named
PlotView
with an exampleTestInterPolator
.Hope it helps.
原帖:Android 图表和图形库
使用GraphView库可以创建折线图和条形图。
GraphView 是一个 Android 库,用于以编程方式创建灵活且美观的折线图和条形图。它很容易理解、集成和定制。
首先签出该库并将其集成到您的项目中。
源代码托管在 github 上。
github上的GraphView库
还可以让图表可缩放(缩放)和可滚动。有关此库的更多信息,请参见原始文章:图表和Android 图形库
这就是它的样子:
然后您可以使用几行代码轻松创建它(参见代码片段):
Original post: Chart and Graph Library for Android
With the library GraphView it's possible to create a line and bar graphs.
GraphView is a library for Android to programmatically create flexible and nice-looking line and bar diagramms. It is easy to understand, to integrate and to customize it.
First checkout the library and integrate it into your project.
Source code is hosted on github.
GraphView library on github
It's also possible to let the graph be scalable (zooming) and scrollable. More information about this library on Original post: Chart and Graph Library for Android
This is how it will look like:
Then you can easily create it with a few lines of code (see snippet):
有 http://www.jfree.org/jfreechart/ 可以满足您的需求,它是一个 Java 库,所以它应该很适合 Android。而且它是 LGPL。
如果你可以走 JavaScript 路线,那么你可以查看 ProtoVis http://vis.stanford.edu/protovis/
There is http://www.jfree.org/jfreechart/ which can suit your needs, it is a Java library so it should fit nice to Android. And it is LGPL.
If you can go the JavaScript route, then you could check out ProtoVis http://vis.stanford.edu/protovis/