私は、SQLiteテーブルにグラフがあり、そのデータを X 軸と Y 軸にグラフで表示したい Android に非常に慣れていません。私のデータベースの値またははfallowsです:
productId Qty
2100021 20
2100022 50
X軸とY軸でAndroidのこれらの値のグラフをプロットしたい。
私は次のコードを書きます
public class SalesTrackingByCustomer extends Activity {
private DBAdapter db;
private Spinner spinner1, spinner2;
private String[] prodctnames;
private String[] prodctnames1;
private double[] product_1;
private double[] product_2;
public int count;
public String custid;
public Sample customerdetails;
public ChartCollection<String> collection;
ChartArea area;
ChartArea area1;
private SimpleAdapter mSchedule;
Vector<String> vec_custid=new Vector<String>();
Vector<String> vec_oldno=new Vector<String>();
Vector<String> vec_productid=new Vector<String>();
Vector<String> vec_qty=new Vector<String>();
private ListView mListView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bycustomers);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
mListView=(ListView)findViewById(R.id.listView1);
prodctnames=new String[10];
product_1=new double[10];
prodctnames1=new String[10];
product_2=new double[10];
db=new DBAdapter(this);
final ChartView chartView = (ChartView) findViewById(R.id.chartView);
ChartPalette palette = new ChartPalette(0xffffd7e8);
chartView.setPalette(palette);
final ChartSeries product1 = new ChartSeries("P1", ChartTypes.Column);
spinner1 = (Spinner) findViewById(R.id.spinner1);
spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
int position=spinner1.getSelectedItemPosition();
System.out.println("=====ITEM POSITION======"+position);
final String selected=arg0.getItemAtPosition(arg2).toString();
System.out.println("=====IN SELECTED======"+selected);
db.open();
Cursor customer=db.fetchorderCustomername(selected);
custid=customer.getString(0);
System.out.println("=====CUSTOMER NAME ID======"+custid);
Cursor cursor=db.fetchorderDetails(custid);
count=cursor.getCount();
System.out.println("=====COUNT======"+count);
int i=0;
while (i<count)
{
String productid=cursor.getString(1);
prodctnames[i]=productid;
String qty=cursor.getString(2);
product_1[i]=Double.parseDouble(qty);
System.out.println("=====PROID======"+prodctnames[i]+"=====QUANTITY======"+product_1[i]);
cursor.moveToNext();
i++;
}
for (int j = 0; j < count; j++)
{
ChartPoint point = product1.getPoints().addXY(j, product_1[j]);
point.setAxisLabel(prodctnames[j]);
}
if(position==0)
{
chartView.refreshDrawableState();
chartView.getSeries().add(product1);
area = chartView.getAreas().get(0);
area.getDefaultXAxis().setLabelsMode(ChartAxis.LabelsMode.SeriesLabels);
}
if(position==1)
{
chartView.refreshDrawableState();
chartView.getSeries().add(product1);
area1 = chartView.getAreas().get(0);
area1.getDefaultXAxis().setLabelsMode(ChartAxis.LabelsMode.SeriesLabels);
}
//area.refresh();
db.close();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
前もって感謝します。