【问题标题】:Android MPchart Piechart Legend setCustom errorAndroid MPchart Piechart Legend setCustom 错误
【发布时间】:2017-03-15 06:55:37
【问题描述】:

我正在使用 MPchart 饼图。当我设置自定义图例数组时,它不接受该数组。

我的代码...

Legend l = chart.getLegend();
    l.setCustom(ColorTemplate.VORDIPLOM_COLORS, new String[] { "aaaaa", "bbbbb", "ccccc"});

错误...

Cannot resolve method 'setCustom(int[],java.lang.String[])'

我的 MPchart 版本:v3.0.0

我该如何解决这个问题?

【问题讨论】:

  • 无论你在哪里找到使用 setCustom 这样的说明(大概是 wiki),它都已经过时了。 setCustom 现在与 LegendEntry 对象的数组或列表一起使用,其中包含有关如何格式化每个条目的详细信息。 wiki 应该可能会更新,并且至少应该有一个已弃用的方法,它采用原始参数并包装新的实现,但是您应该能够毫无问题地最终更改它。详细阅读 LegendEntry 和 setCustom 上的 JavaDoc。

标签: android charts mpandroidchart


【解决方案1】:

这对我设置自定义图例很有用:

 // Use Legend Entry

    LegendEntry l1=new LegendEntry("Bank", Legend.LegendForm.DEFAULT,10f,2f,null, Color.RED);
    LegendEntry l2=new LegendEntry("Chitfund", Legend.LegendForm.CIRCLE,10f,2f,null, Color.GREEN);
    LegendEntry l3=new LegendEntry("Mobile", Legend.LegendForm.LINE,10f,1f,null,Color.BLACK);
    LegendEntry l4=new LegendEntry("Internet", Legend.LegendForm.DEFAULT,10f,2f,null, Color.BLUE);
    LegendEntry l5=new LegendEntry("ATM", Legend.LegendForm.DEFAULT,10f,2f,null, Color.DKGRAY);
    LegendEntry l6=new LegendEntry("Check", Legend.LegendForm.SQUARE,10f,1f,null,Color.CYAN);

    Legend l=piechart.getLegend();
    l.setCustom(new LegendEntry[]{l1,l2,l3,l4,l5,l6});

    //For set the same color to chart
    piedataSet.setColors(new int[]{Color.RED, Color.GREEN, Color.BLACK, Color.BLUE, Color.DKGRAY, Color.CYAN});//Color is set based on your Legend entry color

图例输入参数说明:

 LegendEntry l1=new LegendEntry("Bank", Legend.LegendForm.DEFAULT,10f,2f,null, Color.RED);

         Parameter                   Example
   --------------------------------------------------------

         legend label         -      "Bank"
         legend form          -      Legend.LegendForm.DEFAULT[ (DEFAULT Shape is Square) Default instead of any (like Square, circle, line)]
         formsize             -      10f,2f [height of the width]
         dashboard effect     -      null
         color                -      Color.RED

【讨论】:

    【解决方案2】:

    为我工作试试这个

    为字符串数组添加颜色

    String[] array;
    
    array = new String[<**size of your color arraylist**>];
                for (int i = 0; i < **size of your color arraylist**; i++) {
                    array[i] = **color arraylist**.get(i);
                }
    

    设置自定义颜色

      if (array.length > 0 && array !=null) {
                l.setCustom(l.getColors(), array);
                }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-02
    • 2018-09-25
    • 1970-01-01
    • 2016-01-01
    • 2016-09-14
    • 2015-11-11
    • 2023-04-03
    相关资源
    最近更新 更多