2010-06-29 61 views
3

在類似this question的方法中,我正在尋找一種將數據點繪製到Android視圖上的方法。最好是一個庫,它可以執行任意範圍的輸入,並允許平移和縮放(通過捏或縮放欄)。適用於Android的GPL兼容圖形庫

現在,我有子類-ED它執行以下歸一化的圖:

  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法(也,我更新this.widthMeasureSpec和onMeasure()中的this.heightMeasureSpec)。

這是用minA/maxA作爲我自變量的邊界,minS/maxS作爲我的因變量的邊界。

這適用於顯示數據,但我希望別人已經解決了繪製座標軸和平移/縮放的問題。

我有大約150,000個數據點,我寧願將它們作爲浮點數來節省一半的內存。我不知道JavaScript中有多大的十進制數,但我真的不希望通過JavaScript爲Google Charts API或基於HTML的解決方案傳遞數據。

我在MyTouch 3g上運行(原來,3.5mm插孔之前,它是RAM升級),所以性能是一個問題。我想在GPLv3下發布最終的項目,因此這不包括GraphView

這些圖形與this的圖形屬於同一類型,所以任何通過排除過於靠近在屏幕上顯示的點來進行的優化肯定會有所作爲。

+0

對於200個rep點,我會很樂意幫你寫一個... :) FWW我強烈建議使用OpenGL來做這件事...一旦你的數據集在頂點緩衝區中,你不需要觸摸它,而h/w加速將使縮放和平移像黃油一樣平滑。但是如果你想使用普通的Canvas API(onDraw等),那麼建議你使用Matrix進行繪製。 – 2011-01-24 10:32:35

+0

我從來沒有使用過OpenGL。 http://blog.jayway.com/2009/12/03/opengl-es-tutorial-for-android-part-i/(以及後續的部分)看起來是一個很好的介紹嗎?我看不到什麼單位的座標(即,點(1,1)是什麼意思?) – sargas 2011-01-24 20:28:54

+0

在CUDA和其他加速技術之前的幾天,他們的確使用opengl/COGL和着色器來加強他們的編輯。 - 模因書。順便說一下,OpenGL實現本身可能太過CPU了 - 請記住,重繪可能需要時間。 – 2011-01-28 20:11:10

回答

-1

http://www.jfree.org/jfreechart/它可以滿足您的需求,它是一個Java庫,因此它應該適合Android。這是LGPL。

如果你可以去JavaScript的路線,那麼你可以檢查出ProtoVis http://vis.stanford.edu/protovis/

+0

對不起,jfreechart依賴於AWT,而ProtoVis已經出來了(從來沒有說過我對付javascript的原因),因爲它需要SVG(在android中的SVG支持非常糟糕:() – sargas 2011-01-26 23:27:02

2

SARGAS,做檢查android-misc-widgets。它包含了一個名爲PlotView用一個例子TestInterPolator部件。

希望它有幫助。

1

Original post: Chart and Graph Library for Android

與庫GraphView它可以創建一個行和條形圖。

GraphView是一個Android程序庫,用於以編程方式創建靈活且漂亮的線條和條形圖。很容易理解,集成和定製它。

首先檢查庫並將其集成到您的項目中。 源代碼託管在github上。 GraphView library on github

還可以讓圖形可縮放(縮放)和可滾動。關於Original post: Chart and Graph Library for Android

這個庫的更多信息,這是怎麼看起來像line graph

然後你就可以輕鬆地用幾行代碼創建(見片段):

// 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);