2015-12-16 35 views
1

我的堆積條形圖MPAndroidChart工作得很好,但我試圖刪除或編輯欄內的值。但我找不到任何有意義修改的代碼。如何刪除或編輯MPAndroidChart - StackedBarChart - 條目?

enter image description here

我不認爲我的代碼是非常有用的,但在這裏它是...

private void initStackedBarChartStuff() { 
    mMonths = dfs.getShortMonths(); 
    mChart = (BarChart) mContext.findViewById(R.id.chart1); 
    mChart.setOnChartValueSelectedListener(this); 

    mChart.setDescription(""); 

// if more than 60 entries are displayed in the chart, no values will be 
// drawn 
    mChart.setMaxVisibleValueCount(30); 

// scaling can now only be done on x- and y-axis separately 
    mChart.setPinchZoom(false); 

    mChart.setDrawGridBackground(false); 
    mChart.setDrawBarShadow(false); 

    mChart.setDrawValueAboveBar(false); 

// change the position of the y-labels 
    YAxis yLabels = mChart.getAxisLeft(); 
    yLabels.setValueFormatter(new MyYAxisValueFormatter()); 
    mChart.getAxisRight().setEnabled(false); 
    mChart.getAxisLeft().setEnabled(false); 

    XAxis xLabels = mChart.getXAxis(); 
    xLabels.setPosition(XAxis.XAxisPosition.TOP); 

    Legend l = mChart.getLegend(); 
    l.setPosition(Legend.LegendPosition.BELOW_CHART_RIGHT); 
    l.setFormSize(8f); 
    l.setFormToTextSpace(4f); 
    l.setXEntrySpace(6f); 

// mChart.setDrawLegend(false); 
} 

填補stackedBarChart

private void fillStackedBarChart(Vector drawingData, Vector drawingIntervall) { 
    if (drawingData == null || drawingData == null) 
     return; 

    int anzBdata = dataSizes[1]; 
    int intervall = globalIntervall; 
    ArrayList<String> xVals = new ArrayList<String>(); 


// Strings über die Blöcke schreiben ########################################### 
    { 
     long zeit = 0; 
     String[] months = new String[12]; 
     String[] days = new String[7]; 
     boolean einmal = true; 

     for (int i = 0; i < drawingIntervall.size(); i++) 
     zeit += ((Long) drawingIntervall.get(i)).longValue(); 

     if (bigData) // > 2 Jahre 
     months = null; 
     else if (zeit > 31623000) // > 1 Jahre 
     months = dfs.getShortMonths(); 
     else 
     months = dfs.getMonths(); 
     days = dfs.getWeekdays(); 


     for (int i = 0; i < drawingData.size(); i++) { 
     long[] pack = (long[]) drawingData.get(i); 
     String s = ""; 

     //  Sonderfall !! In Monatsansicht den Monat dazu schreiben 
     if ((einmal) && (intervall == 2)) { 
      if (etStart.getText().toString().trim().startsWith("01.")) { 
      Calendar calE = convStringToDate(etEnd.getText().toString().trim(), true, true); 
      int jahr = calE.get(Calendar.YEAR); 
      int monat = calE.get(Calendar.MONTH); 

      Calendar calX = myGetInstance(); 
      calX.set(Calendar.YEAR, jahr); 
      calX.set(Calendar.MONTH, monat); 
      calX = getLastDayOfMonth(calX); 

      if (calE.getTimeInMillis() == calX.getTimeInMillis()) { 
       einmal = false; 
       s = months[calE.get(Calendar.MONTH)]; 
      } 
      } 
     } 

     switch (intervall) { 
      case 0: 
      s += df.format(convMilliToDate(pack[0] * 1000, false, false).getTime()); 
      break; 

      case 1: 
      s += convMilliToString(pack[0] * 1000); 
      break; 

      case 2: 
      s += "KW " + convMilliToDate(pack[0] * 1000, false,  false).get(Calendar.WEEK_OF_YEAR); 
      break; 

      case 3: 
      if (bigData) 
       s += convMilliToDate(pack[0] * 1000, false,  false).get(Calendar.YEAR) + ""; 
      else 
       s += months[convMilliToDate(pack[0] * 1000, false, false).get(Calendar.MONTH)]; 
      break; 
     } 

     xVals.add(s); 
     } 
    } 


    // nun alle Balken/Blöcke zeichnen  ########################################## 
    { 
//  1 Y-Wert entspricht z.B. 1 Tag, o. 1 Woche,... jeder Y-Wert hat so viele floats wie B-Daten vorhanden sind ########################################### 
     ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>(); 

     for (int i = 0; i < drawingData.size(); i++) { 
     long[] pack = (long[]) drawingData.get(i); 
     long intervallSek = ((Long) drawingIntervall.get(i)).longValue()  + 1; 
     long pastSek = 0; 
     float[] f = new float[anzBdata + 1]; 
     int b = 0; 

     for (int j = 0; j < pack.length; j++) { 
      if ((j >= dataSizes[0]) && (j <= (anzBdata - 1 + dataSizes[0]))) { 
     f[b++] = pack[j]; 
     pastSek += pack[j]; 
     } 
    } 
     f[b++] = intervallSek - pastSek; // zeichnet einen Block indem "keine Daten" aufgezeichnet wurden. (wenn Maschine ohne Strom o.ä.) 
     yVals1.add(new BarEntry(f, i)); 
     } 

//  BarDataSet set1 = new BarDataSet(yVals1, "Statistics Business Data"); 
     BarDataSet set1 = new BarDataSet(yVals1, ""); 
     set1.setColors(getColors()); 
     set1.setStackLabels(barChartLegend); 

     ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>(); 
     dataSets.add(set1); 

     BarData data = new BarData(xVals, dataSets); 
     data.setValueFormatter(new MyValueFormatter()); 

     mChart.setData(data); 
     mChart.invalidate(); 
    } 
    } 

回答

0

該解決方案是不是真的漂亮,可能會找到一個更好的...

該c Lass BarChart從BarLineChartBase擴展而來。 BarLineChartBase中有一行可以被註釋或刪除以獲得所需的解決方案。

mRenderer.drawValues(canvas); 
0

基本上有兩種方式:

  • 使用ValueFormatter自定義格式的值(編輯或刪除)
  • 使用dataSet.setDrawValues(false)完全刪除所有值
相關問題