【问题标题】:MPAndroidChart PieChart Remove PercentsMPAndroidChart PieChart 删除百分比
【发布时间】:2015-07-01 07:09:35
【问题描述】:

我正在使用MPAndroidChart

我想删除饼图上的百分比值。我怎样才能做到这一点?

【问题讨论】:

    标签: android mpandroidchart


    【解决方案1】:

    为了不绘制入口值,调用: pieData.setDrawValues(false)

    为了不绘制 x 值,请调用: pieChart.setDrawSliceText(false)

    【讨论】:

      【解决方案2】:

      看看下面的代码

      PieEntry pe1 =   new PieEntry(float_percent, stingdata);
      entries.add(pe1);
      total_values =  total_values + float_percent;
      
      No 2: 
          
             PieData data = new PieData(dataSet);
                  data.setValueFormatter(new MyValueFormatter(chart));
                  chart.setUsePercentValues(true);
              enter code here
          
          No 3: 
          
           class MyValueFormatter  extends ValueFormatter
              {
          
                  public DecimalFormat mFormat;
                  private PieChart pieChart;
          
                  public MyValueFormatter() {
                      mFormat = new DecimalFormat("###,###,##0.0");
                  }
          
                  // Can be used to remove percent signs if the chart isn't in percent mode
                  public MyValueFormatter(PieChart pieChart) {
                      this();
                      this.pieChart = pieChart;
                  }
          
                  @Override
                  public String getFormattedValue(float value) {
          
          
                      return mFormat.format(((total_values * value)/100)) + " %";
                  }
          
                  @Override
                  public String getPieLabel(float value, PieEntry pieEntry) {
                      if (pieChart != null && pieChart.isUsePercentValuesEnabled()) {
                          // Converted to percent
                          return getFormattedValue(value);
                      } else {
                          // raw value, skip percent sign
                          return mFormat.format(value);
                      }
                  }
              }

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-01
        • 1970-01-01
        相关资源
        最近更新 更多