2015-01-14 159 views
3

我正在使用MPAndroidChart庫。MPAndroidChart - 刪除頂部和底部空間

我在我的應用程序中實現了PieChart。一切工作正常,但在圖表頂部和底部有一個空白區域。 我需要刪除這個空間來想象我的活動佈局

我的問題是:

  • 可以以編程方式刪除呢?

P.D.在我的佈局中,沒有marginTop或marginBottom。

佈局的xml:

<com.github.mikephil.charting.charts.PieChart 
    android:id="@+id/pieChart" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/_home_consumed" > 
</com.github.mikephil.charting.charts.PieChart> 

回答

3

你試過呼籲ChartsetOffsets(float left, float top, float right, float bottom)

// add data... 
chart.setData(...); 

// define new offsets 
chart.setOffsets(0, 0, 0, 0); 

// update transformation matrix 
chart.getTransformer().prepareMatrixValuePx(chart); 
chart.getTransformer().prepareMatrixOffset(chart); 

chart.getContentRect().set(0, 0, chart.getWidth(), chart.getHeight()); 

// redraw 
chart.invalidate(); 

這應該通過編程來消除所有的偏移量。由於圖表在調用setData(...)方法時會自動調整偏移量,爲了保持偏移量,每次爲圖表設置新的數據對象時都需要調用此方法。

我也知道這很複雜,我會簡化將來的過程。

+0

好,非常感謝:d – alcaamado

+2

此時(2016)餅圖沒有'setOffset'方法,我試圖與'setMinOffset'方法,但空白仍然在這裏,有什麼幫助? –

+1

@RosendoRopher,我知道這是一種解決方法,但嘗試使用帶有負值的setExtraOffsets。它爲我工作。 – Daivid

0

嘗試......

pieChart.setExtraOffsets(-10,-10,-10,-10); 
相關問題