如何将AChartEngine与SQLite DB中的数据集成?

时间:2012-11-10 14:05:58

标签: android sqlite achartengine

你好AChartEngine对我来说很新,所以欢迎任何帮助。我想要做的是显示我的数据库中的2个数据,即BMI结果和用户保存他/她的BMI结果时的日期。我现在不知道该怎么做。我所拥有的就是这个:

我的代码:     公共类ViewBMIData扩展了Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.viewbmidata);

    //TextView tv1 = (TextView) findViewById (R.id.tvBMIData);
    //TextView tv2 = (TextView) findViewById ( R.id.tvBMIDate );

    BMICalculatorDB info = new BMICalculatorDB(this);
    info.open();

    String data1 = info.getBMIDataData();
    String data2 = info.getBMIDateData();
    for (int i = 1; data1 == null; i++) {

        double x = Double.parseDouble( data1 );
        double y = Double.parseDouble( data2 );

        }
        info.close();

    //tv1.setText( data1 );
    //tv2.setText( data2 );

} 

这段代码是我从教程中找到的,但不知道如何做到这一点:

    public Intent getIntent( Context context ){

            // Bar 1
            int[] y = { 124, 135, 443, 456, 234, 123, 342, 134, 123, 643, 234, 274 };
            CategorySeries series = new CategorySeries("BMI");
            for (int i = 0; i < y.length; i++) {
                series.add("Bar " + (i+1), y[i]);
            }

            // Bar 2
            int[] y2 = { 224, 235, 243, 256, 234, 223, 242, 234, 223, 243, 234, 274 };
            CategorySeries series2 = new CategorySeries( "BMR" );
            for ( int i = 0; i < y.length; i++ ) {
                series2.add( "Bar " + (i+1), y2[i] );
            }

            XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
            dataset.addSeries( series.toXYSeries() );
            dataset.addSeries( series2.toXYSeries() );

            // This is how the "Graph" itself will look like
            XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
            mRenderer.setChartTitle( "BMI and BMR Statistics" );
            mRenderer.setXTitle( "DATE" );
            mRenderer.setYTitle( "BMI" );
            mRenderer.setAxesColor( Color.GREEN );
            mRenderer.setLabelsColor( Color.RED );

            // Customize bar 1
            XYSeriesRenderer renderer = new XYSeriesRenderer();
            renderer.setDisplayChartValues( true );
            renderer.setChartValuesSpacing( ( float ) 0.5 );
            mRenderer.addSeriesRenderer( renderer );

            // Customize bar 2
            XYSeriesRenderer renderer2 = new XYSeriesRenderer();
            renderer.setColor( Color.CYAN );
            renderer.setDisplayChartValues( true );
            renderer.setChartValuesSpacing( ( float ) 0.5 );
            mRenderer.addSeriesRenderer( renderer2 );

            Intent intent = ChartFactory.getBarChartIntent( context, dataset,mRenderer, Type.DEFAULT );
            return intent;

}  */

请指导我这样做。感谢

1 个答案:

答案 0 :(得分:2)

没有比AChartEngine下载的教程和演示程序更好的帮助。