使用AChartEngine给出错误的迷你图

时间:2014-10-02 18:08:10

标签: android graph achartengine

我有一个值列表,我想使用AChartEngine库绘制SparkLine图。

我编写了这段代码,但是一旦我运行代码,应用程序崩溃了。

这是Activity.java代码

    @SuppressLint("ClickableViewAccessibility")
public class CompanyActivity extends BaseActivity implements OnRefreshListener, OnLoadMoreListener {

    TextView tvCompanyName;
    TextView tvCompanyPrice;
    TextView tvCompanyChange;
    ImageView ivCompanyLogo;
    TextView tvCompanyAbout;
    LinearLayout rlForScreenShot;
    Button bShare;
    PullAndLoadListView lvCompanyWall;
    WallAdapter adapter;
    SimpleFacebook mSimpleFacebook;
    Company company;
    Bitmap screenShot;
    Bitmap screenShot1;
    ChartFactory chartview;
    XYMultipleSeriesRenderer renderer;
    XYMultipleSeriesDataset datasett;
    XYSeriesRenderer seriesrenderer;
    GraphicalView mChartView;

    int start;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.company);

        getFragmentManager().beginTransaction().add(R.id.rlHeader, header).commit();

        Bundle b = this.getIntent().getExtras();
        company = (Company)b.getSerializable("company");

        super.setTitle(company.companyCode);

        flProgress = (FrameLayout)findViewById(R.id.flProgress);

        start = 0;

        View header = getLayoutInflater().inflate(R.layout.company_header, null, false);
        rlForScreenShot = (LinearLayout)findViewById(R.id.rlForScreenShot);
        rlForScreenShot.addView(mChartView); 
        lvCompanyWall = (PullAndLoadListView)findViewById(R.id.lvCompanyWall);
        lvCompanyWall.addHeaderView(header);

        if (lvCompanyWall != null) {
            lvCompanyWall.setOnRefreshListener(this);
            lvCompanyWall.setOnLoadMoreListener(this);
        }

        new LoadCompanyAsyncTask().execute();
    }

class LoadCompanyAsyncTask extends AsyncTask<Void, Void, Void> {
        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);

            TimeSeries series = new TimeSeries("Line1");
            for (History history: company.history) {
                series.add(null, Float.parseFloat(history.value));

            }
            renderer.addSeriesRenderer(seriesrenderer);
            renderer.setShowAxes(false);
            renderer.setShowLabels(false);
            renderer.setShowLegend(false);
            renderer.setShowGrid(false);

                datasett.addSeries(series);

                mChartView = ChartFactory.getTimeChartView(context, datasett, renderer, "Sparkline");
                rlForScreenShot.addView(mChartView); 
             tvCompanyName.setText(company.companyCode);
            tvCompanyPrice.setText(company.price.last);
            String priceChange = company.price.stockChange.equals("0.00") ? "(0.00%)" : 
        Common.percentageChange(Double.parseDouble(company.price.ref), Double.parseDouble(company.price.last));
            tvCompanyChange.setText((company.price.stockChange.equals("0.00") ? "0.000" : company.price.stockChange) + " " + priceChange);
            adapter = new WallAdapter(context, company.wallpost);
            lvCompanyWall.setAdapter(adapter);
            flProgress.setVisibility(View.GONE);

        }

        @Override
        protected Void doInBackground(Void... params) {
            CompanyApi api = new CompanyApi(context);
            try {
                company = api.getCompany(sm.getCurrentSession().ID, company.id, start, 15);
                company.history = api.getPriceChart(sm.getCurrentSession().ID, company.id);
            } catch (Exception e) {
                e.printStackTrace();
                company.history = new ArrayList<History>();
            }

            return null;
        }
    }

这是xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/rlForScreenShot"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_alignBottom="@+id/cvChart2">
         </LinearLayout>

 </LinearLayout>

为什么会崩溃,我做错了什么?

由于 金斯利

0 个答案:

没有答案