我正在努力处理这个雷达图。我想把每个客户都放在雷达图中。仅出现一个客户,其他客户的所有价值都会为该客户添加。有人可以帮我吗?
private void setupChartView() {
RadarChart radarChart = findViewById(R.id.radarChart);
ArrayList<RadarEntry> dataEntries = new ArrayList<>();
Calendar calendar = Calendar.getInstance();
int currentYear = calendar.get(Calendar.YEAR);
SQLiteDatabase db = new DatabaseHelper(this).getWritableDatabase();
Cursor getCustomer = db.rawQuery("select DISTINCT " + C_SALES_CUSTOMER + " FROM " + TABLESALES, null);
for(int i=0; i<getCustomer.getCount(); i++) {
getCustomer.moveToNext();
@SuppressLint("Range")
String customer = getCustomer.getString(getCustomer.getColumnIndex(C_SALES_CUSTOMER));
Cursor getSales = db.rawQuery("select * from " + TABLESALES + " where " + C_SALES_CUSTOMER + " like '%" + customer + "%'", null);
for(int j=0; j<getSales.getCount(); j++) {
getSales.moveToNext();
@SuppressLint("Range")
String sales = getSales.getString(getSales.getColumnIndex(C_SALES_TOTAL));
RadarEntry radarEntry = new RadarEntry(Integer.valueOf(sales));
dataEntries.add(radarEntry);
RadarDataSet radarDataSet = new RadarDataSet(dataEntries, customer);
RadarData radarData = new RadarData();
radarData.addDataSet(radarDataSet);
radarChart.setData(radarData);
}
}
radarChart.getDescription().setEnabled(false);
Legend legend = radarChart.getLegend();
legend.setXEntrySpace(7f);
legend.setYEntrySpace(5f);
legend.setYOffset(75f);
legend.setTextSize(16f);
legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
}
我自己找到了解决方案
private void setupChartView() {
RadarChart radarChart = findViewById(R.id.radarChart);
RadarData radarData = new RadarData();
Calendar calendar = Calendar.getInstance();
int currentYear = calendar.get(Calendar.YEAR);
SQLiteDatabase db = new DatabaseHelper(this).getWritableDatabase();
Cursor getCustomer = db.rawQuery("select DISTINCT " + C_SALES_CUSTOMER + " FROM " + TABLESALES, null);
for(int i=0; i<getCustomer.getCount(); i++) {
ArrayList<RadarEntry> dataEntries = new ArrayList<>();
getCustomer.moveToNext();
@SuppressLint("Range")
String customer = getCustomer.getString(getCustomer.getColumnIndex(C_SALES_CUSTOMER));
Cursor getSales = db.rawQuery("select " + C_SALES_TOTAL + " from " + TABLESALES + " where " + C_SALES_CUSTOMER + " = '" + customer + "'", null);
Toast.makeText(this, String.valueOf(getSales.getCount()), Toast.LENGTH_SHORT).show();
for(int j=0; j<getSales.getCount(); j++) {
getSales.moveToNext();
@SuppressLint("Range")
String sales = getSales.getString(getSales.getColumnIndex(C_SALES_TOTAL));
Toast.makeText(this, sales, Toast.LENGTH_SHORT).show();
RadarEntry radarEntry = new RadarEntry(Integer.valueOf(sales));
dataEntries.add(radarEntry);
}
RadarDataSet radarDataSet = new RadarDataSet(dataEntries, customer);
int color= ((int)(Math.random()*16777215)) | (0xFF << 24);
radarDataSet.setColor(color);
radarData.addDataSet(radarDataSet);
}
radarChart.setData(radarData);
radarChart.getDescription().setEnabled(false);
Legend legend = radarChart.getLegend();
legend.setXEntrySpace(7f);
legend.setYEntrySpace(5f);
legend.setYOffset(75f);
legend.setTextSize(16f);
legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
}