2017-11-01 1 views
-3

auflösen Ich arbeite mit dem PieChart der MPAndroidChart-Bibliothek.Kann den Konstruktor 'PieData (java.util.ArrayList <java.lang.String>, com.hithub.mikephil.charting.data.PieDataSet) nicht'

Ich versuche ein Kreisdiagramm mit Legenden zu generieren. Aber ein Fehler hält Aufspringen Kann nicht Konstruktor 'PieData (java.util.ArrayList, com.hithub.mikephil.charting.data.PieDataSet)' lösen

public class Graph_all extends Fragment { 

    private PieData data; 
    private Map<String, Float> dataGraph = null; 

    public Graph_all(){ 

    } 

    PieChart mChart; 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     // Inflate the layout for this fragment 
     View view = inflater.inflate(R.layout.fragment_piegraph, container, false); 

     mChart = (PieChart) view.findViewById(R.id.pieChartGraph); 
     mChart.getDescription().setEnabled(false); 

     addData(dataGraph); 

     Legend l = mChart.getLegend(); 
     l.setPosition(Legend.LegendPosition.BELOW_CHART_CENTER); 
     l.setXEntrySpace(7); 
     l.setYEntrySpace(8); 
     l.setTextColor(Color.BLACK); 
     l.setTextSize(12f); 


     return view; 
    } 

    public ArrayList<String> queryXData(){ 
     ExpenseDbHelper db = new ExpenseDbHelper(getActivity()); 
     SQLiteDatabase sqlite = db.getReadableDatabase(); 
     ArrayList<String> xNewData = new ArrayList<String>(); 
     String query = "SELECT name, SUM(value) AS total FROM expenses, categories WHERE expenses.category_id=categories._id GROUP BY category_id"; 
     Cursor cursor = sqlite.rawQuery(query, null); 
     for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { 
      xNewData.add(cursor.getString(cursor.getColumnIndex("name"))); 
     } 
     cursor.close(); 
     return xNewData; 
    } 

    public ArrayList<Float> queryYData(){ 
     ExpenseDbHelper db = new ExpenseDbHelper(getActivity()); 
     SQLiteDatabase sqliteY = db.getReadableDatabase(); 
     ArrayList<Float> yNewData = new ArrayList<Float>(); 
     String query = "SELECT category_id, SUM(value) AS total FROM expenses GROUP BY category_id"; 
     Cursor cursor = sqliteY.rawQuery(query, null); 
     for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { 
      yNewData.add(cursor.getFloat(cursor.getColumnIndexOrThrow("total"))); 
     } 
     cursor.close(); 
     return yNewData; 
    } 

    private void addData(Map<String, Float> dataGraph) { 
     int i = 0; 
     ArrayList<PieEntry> yVals = new ArrayList<PieEntry>(); 
     ArrayList<String> xVals = new ArrayList<String>(); 

     for (Map.Entry<String, Float> entry : dataGraph.entrySet()) { 
      yVals.add(new PieEntry(entry.getValue(), i++)); 
      xVals.add(entry.getKey()); 
     } 

     PieDataSet dataSet = new PieDataSet(yVals, null); 
     dataSet.setSliceSpace(3f); // space between each arc slice 
     dataSet.setSelectionShift(5f); 

     ArrayList<Integer> colors=new ArrayList<Integer>(); 

     for(int c: ColorTemplate.VORDIPLOM_COLORS) 
      colors.add(c); 
     for(int c: ColorTemplate.JOYFUL_COLORS) 
      colors.add(c); 
     for(int c: ColorTemplate.COLORFUL_COLORS) 
      colors.add(c); 
     for(int c: ColorTemplate.LIBERTY_COLORS) 
      colors.add(c); 
     for(int c: ColorTemplate.PASTEL_COLORS) 
      colors.add(c); 
     colors.add(ColorTemplate.getHoloBlue()); 
     dataSet.setColors(colors); 

     PieData data = new PieData(xVals, dataSet); 
     data.setValueTextSize(11f); 
     data.setValueTextColor(Color.WHITE); 

     mChart.setData(data); 
     mChart.highlightValues(null); 
     mChart.invalidate(); 
     mChart.setDrawHoleEnabled(false); 
    } 
} 

Der Fehler ist in addData()

PieData data = new PieData(xVals, dataSet); 

ich weiß nicht wirklich, was mit diesem

+0

falsch Konstruktor, das heißt Datenformate ur Weitergabe sind falsch –

+1

Warum denken Sie 'PieData' einen Konstruktor hat, der diese Argumente übernimmt? [Es sieht nicht so aus] (https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartLib/src/main/java/com/github/mikephil/charting/data/PieData.java). –

+0

Könnten Sie bitte meine Antwort überprüfen? @Agca Cruz – KeLiuyue

Antwort

0

falsch Stellen Sie sicher, Sie haben diese public PieData(ArrayList<String> xVals,PieDataSet dataSet) Konstruktor in Ihrer PieData Klasse.

public class PieData{ 

ArrayList<String> xVals; 
PieDataSet dataSet; 

public PieData(ArrayList<String> xVals,PieDataSet dataSet){ 
    this.xVals = xVals; 
    this.dataSet = dataSet; 
} 
... 
} 
+0

Können Sie aufwendiger sein? –

+0

Könnten Sie 'PieData' Code zeigen? – KeLiuyue

+0

Ich verweise meine Arbeit damit. Ich weiß nicht, dass ich eine PieData.class https://stackoverflow.com/questions/35897894/mpandroidchart-pie-chart-is-not-generated-with-only-one-value erstellen sollte –

Verwandte Themen