【问题标题】:MPAndroidChart - Remove Top and Bottom SpacesMPAndroidChart - 删除顶部和底部空格
【发布时间】:2015-01-14 14:47:16
【问题描述】:

我正在使用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>

【问题讨论】:

    标签: android mpandroidchart


    【解决方案1】:

    您是否尝试过在Chart 上拨打setOffsets(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(...)方法时会自动调整其偏移量,为了保持偏移量,每次为图表设置新的数据对象时都需要调用该方法。

    我也知道这很复杂,以后我会简化这个过程。

    【讨论】:

    • 此时(2016)PieChart没有setOffset方法,我用setMinOffset方法试过了,但这里还是有空格,有什么帮助吗?
    • @RosendoRopher,我知道这是一种解决方法,但请尝试使用带有负值的 setExtraOffsets。它对我有用。
    【解决方案2】:

    试试这个...

    pieChart.setExtraOffsets(-10,-10,-10,-10);
    

    【讨论】:

    • 请注意,如果生成的偏移量小于默认最小值 15,您可能还需要调用 chart.setMinOffset()
    【解决方案3】:

    饼图不仅有 10 的默认偏移量,而且还增加了额外的空间,让您突出显示 selected 条目 (see this comment on GitHub。要删除所有填充,您需要删除所选条目的空间:

    pieChart.setExtraOffsets(0, 0, 0, 0);
    
    PieDataSet dataSet = new PieDataSet([..]);
    dataSet.setSelectionShift(0f);
    

    【讨论】:

      【解决方案4】:

      Half Pie Chart Image using MPCHART

      您可以将偏移量设置为负值,如下所示:- transactionTrendPieChart.setExtraOffsets(0,-100,0,-150);

      【讨论】:

      • 我遇到了与您在屏幕截图中描述的完全相同的问题。但是extraOffset 的行为很奇怪。好像有问题。你如何找到偏移量?
      【解决方案5】:

      Andrew Briggschart.setMinOffset(0); 答案对我有用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-12-08
        • 2021-09-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-08-11
        • 2011-09-29
        • 1970-01-01
        相关资源
        最近更新 更多