【问题标题】:How i can fix legend ? (MPAndroidChart)我怎样才能修复传奇? (MPAndroidChart)
【发布时间】:2018-03-07 08:58:47
【问题描述】:

我使用了legend.setPosition(Legend.LegendPosition.RIGHT_OF_CHART_CENTER); 它有效,但我希望图例位于顶部

如果我使用legend.setPosition(Legend.LegendPosition.RIGHT_OF_CHART); 图例和图形重叠

也许有办法改变图表的位置?

【问题讨论】:

    标签: android mpandroidchart


    【解决方案1】:

    不推荐使用此方法以更好地使用它。

    l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
    l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    l.setDrawInside(false);
    

    参考你可以在这里查看The legend can't display when call setPosition(LegendPosition.BELOW_CHART_CENTER)

    【讨论】:

      【解决方案2】:

      我能够使用

      得到想要的结果
      legend.setPosition(Legend.LegendPosition.ABOVE_CHART_LEFT); 
      legend.setWordWrapEnabled(true); 
      legend.setMaxSizePercent(0.20f);
      

      【讨论】:

        【解决方案3】:

        尝试在所有自定义后将所有数据设置为图表,一切都会正常工作..像这样:

         l.setCustom(arrayOf(firstLegend, secondLegend))
            l.verticalAlignment = Legend.LegendVerticalAlignment.BOTTOM
            l.horizontalAlignment = Legend.LegendHorizontalAlignment.LEFT
            l.orientation = Legend.LegendOrientation.HORIZONTAL
            l.setDrawInside(false) 
        

        然后将数据设置为图表..

                chart.data = data // set the data and list of labels into chart
        

        【讨论】:

          【解决方案4】:

          使用下面的行:

             legend.setPosition(Legend.LegendPosition.ABOVE_CHART_RIGHT);
          

          【讨论】:

          • 但是名字是排成一行而不是垂直的
          【解决方案5】:

          是的,您可以在更改偏移量的值时:

              pieChart.setExtraTopOffset(15);
              pieChart.setExtraBottomOffset(15);
              pieChart.setExtraLeftOffset(0);
              pieChart.setExtraRightOffset(50);
          

          或者用一行

              setExtraOffsets(float left, float top, float right, float bottom)
          

          结果:

          一个很好的例子,它的参数和一些描述: https://www.programmersought.com/article/99524092993/

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2023-01-28
            • 2018-07-09
            相关资源
            最近更新 更多