3

在与此问题类似的方法中,我正在寻找一种将数据点绘制到 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 中的十进制数字有多大,但我真的不想为了 Google Charts API 或基于 HTML 的解决方案为了内存而通过 JavaScript 传递数据。

我在 MyTouch 3g 上运行它(原来的,在 3.5 毫米插孔和它的 RAM 升级之前),所以性能是一个问题。我想在 GPLv3 下发布最终项目,所以这不包括GraphView

这些图表与此类型相同,因此通过排除靠得太近而无法显示在屏幕上的点的任何优化肯定会有所作为。

4

3 回答 3

2

sargas,请检查android-misc-widgets 。它包含一个以PlotView示例命名的小部件TestInterPolator

希望能帮助到你。

于 2011-01-27T08:29:10.137 回答
1

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: line graph

Then you can easily create it with a few lines of code (see snippet):

// graph with dynamically genereated horizontal and vertical labels
GraphView graphView = new LineGraphView(
  this // context
  , new GraphViewData[] {
    new GraphViewData(1, 2.0d)
    , new GraphViewData(2, 1.5d)
    , new GraphViewData(2.5, 3.0d) // another frequency
    , new GraphViewData(3, 2.5d)
    , new GraphViewData(4, 1.0d)
    , new GraphViewData(5, 3.0d)
  } // data
  , "GraphViewDemo" // heading
  , null // dynamic labels
  , null // dynamic labels
);
LinearLayout layout = (LinearLayout) findViewById(R.id.graph1);
layout.addView(graphView);
于 2011-07-28T10:12:01.337 回答
-1

http://www.jfree.org/jfreechart/可以满足你的需要,它是一个 Java 库,所以它应该很适合 Android。它是 LGPL。

如果您可以走 JavaScript 路线,那么您可以查看 ProtoVis http://vis.stanford.edu/protovis/

于 2011-01-26T23:13:46.847 回答