2014-06-06 70 views
0

我是Android和iOS中構建的應用程序的非開發人員產品經理。我們在iOS中有一個條形圖,爲圖表的內容提供文本。它會顯示每個小節的總計以及每個小節的每個小節的百分比。AndroidPlot - 標籤和文本

在Android中,使用AndroidPlot(所以我知道),我們只顯示不同顏色段的條形圖,沒有百分比總數或總數。開發者告訴我們,我們無法展示更多。

我會在這裏顯示圖像,但stackoverflow告訴我我沒有足夠的信譽點來做到這一點。我創建了一個鏈接到我的保管箱與圖像https://www.dropbox.com/sh/2uocm5bn79rerbe/AAB7s9QEEYIRIgXhKbUAaOyDa

是否有可能使用AndroidPlot來模擬此iOS圖表或至少向最終用戶表示相同的信息?

回答

1

你的開發者或多或少正確,但你有選擇。默認情況下,Androidplot的BarRenderer僅在每個欄的頂部提供了一個可選標籤,這些標籤在iOS圖像中被「可用」,「新」,「已用」和「租用」標籤佔據。該標籤似乎未在您的Android屏幕截圖中使用,因此一種選擇是利用這些標籤來顯示您的總數。

就iOS實現與Androidplot完全匹配而言,缺失的部分是可以沿着每個條的側面水平和垂直添加其他標籤。您可以通過覆蓋它的onRender(...)方法來擴展BarRenderer。 Here's a link爲您的開發人員顯示了代碼中他想要修改onRender(...)的位置。

我建議這些修改,添加垂直標籤:

  1. 調用Canvas.save(Canvas.ALL_SAVE_FLAG)來存儲畫布的默認方向。
  2. 使用Canvas.translate(leftX,底部)到中心上的條形碼
  3. 旋轉畫布的左下點使用Canvas.rotate(90)90度,以使垂直文本繪製任何需要文本
  4. 繪製沿着劇情的一側; 0,0現在對應於條的左下角,因此在調用canvas.drawText(x,y)時從那裏開始。
  5. 調用Canvas.restore()來恢復畫布的原始方向。

執行上述操作後,添加橫向「%」標籤應該是不言而喻的,但如果遇到麻煩,隨時可以隨時提出更多問題。

更新: 這是上述的一個非常基本的實現。首先是drawVerticalText方法:

/** 
    * 
    * @param canvas 
    * @param paint paint used to draw the text 
    * @param text the text to be drawn 
    * @param x x-coord of where the text should be drawn 
    * @param y y-coord of where the text should be drawn 
    */ 
    protected void drawVerticalText(Canvas canvas, Paint paint, String text, float x, float y) { 

     // record the state of the canvas before the draw: 
     canvas.save(Canvas.ALL_SAVE_FLAG); 

     // center the canvas on our drawing coords: 
     canvas.translate(x, y); 

     // rotate into the desired "vertical" orientation: 
     canvas.rotate(-90); 

     // draw the text; note that we are drawing at 0, 0 and *not* x, y. 
     canvas.drawText(text, 0, 0, paint); 

     // restore the canvas state: 
     canvas.restore(); 
    } 

剩下的就是在必要時調用此方法。在你的情況下,它應該爲每個BarGroup完成一次,並且應該在y軸上保持一致的位置。我下面的代碼添加到堆疊的情況BarRenderer.onRender(...),馬上突破上方:

   // needed some paint to draw with so I'll just create it here for now:     
       Paint paint = new Paint(); 
       paint.setColor(Color.WHITE); 
       paint.setTextSize(PixelUtils.spToPix(20)); 
       drawVerticalText(
         canvas, 
         paint, 
         "test", 
         barGroup.leftX, 
         basePositionY - PixelUtils.dpToPix(50)); // offset so the text doesnt intersect with the origin 

這裏的結果的截圖...對不起,它是如此巨大: enter image description here

就我個人而言,我不關心這些垂直標籤的固定y位置,並希望他們漂浮在酒吧的上部。要做到這一點我修改我的drawVerticalText的調用(...)看起來像這樣:

   // needed some paint to draw with so I'll just create it here for now: 
       Paint paint = new Paint(); 
       paint.setColor(Color.WHITE); 
       paint.setTextSize(PixelUtils.spToPix(20)); 

       // right-justify the text so it doesnt extend beyond the top of the bar 
       paint.setTextAlign(Paint.Align.RIGHT); 
       drawVerticalText(
         canvas, 
         paint, 
         "test", 
         barGroup.leftX, 
         bottom); 

將會產生這樣的結果: enter image description here

+0

尼克,謝謝。我會通過這個。 – user3042855