android – Achartengine线图

android – Achartengine线图,第1张

概述我正在使用Achartengine来创建折线图.我现在的月份显示,但上个月的第二行没有显示出来.这是lass和logcat:所以从logcat可以看出我的日期是正确的,上个月的计数也是正确的.那么为什么它没有显示超出我. Log Cat: 08-07 16:13:43.969: I/PROJECTCARUSO(11734): DEBUG startdate: 2013-07-01 enddate: 我正在使用Achartengine来创建折线图.我现在的月份显示,但上个月的第二行没有显示出来.这是lass和logcat:所以从logcat可以看出我的日期是正确的,上个月的计数也是正确的.那么为什么它没有显示超出我.

Log Cat:

08-07 16:13:43.969: I/PROJECTCARUSO(11734): DEBUG startdate: 2013-07-01 enddate: 2013-07-3108-07 16:13:43.969: I/PROJECTCARUSO(11734): count: 908-07 16:13:43.979: I/PROJECTCARUSO(11734): DEBUG startdate: 2013-08-01 enddate: 2013-08-31

类:

public class TempHistoryFragment extends Fragment{    private GraphicalVIEw mChartVIEw;    SimpleDateFormat  format = new SimpleDateFormat("yyyy-MM-dd");      @OverrIDe    public voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);     }    @OverrIDe    public VIEw onCreateVIEw(LayoutInflater inflater,VIEwGroup container,Bundle savedInstanceState) {        if (container == null) {            return null;        }        Calendar cal = Calendar.getInstance();        Calendar cal2 = Calendar.getInstance();        SimpleDateFormat month_date = new SimpleDateFormat("MMMMMMMMM");        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd",Locale.US);        String month_name = month_date.format(cal.getTime());        ArrayList<Integer> xArray = new ArrayList<Integer>();        ArrayList<Integer> yArray = new ArrayList<Integer>();        ArrayList<Integer> xArray2 = new ArrayList<Integer>();        ArrayList<Integer> yArray2 = new ArrayList<Integer>();        cal.add(Calendar.MONTH,-1);        String prev_month_name = month_date.format(cal.getTime());        int daysInMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH);        //***********************************************//        // Our first data Last MONTH        //***********************************************//        //start date for cursor        //cal.add(Calendar.MONTH,-1);        cal.set(Calendar.DATE,1);        String startdate = df.format(cal.getTime());        //end date        cal.set(Calendar.DATE,daysInMonth);        String enddate = df.format(cal.getTime());        Log.i("PROJECTCARUSO","DEBUG startdate: " + startdate + " enddate: " + enddate);        Cursor c = getActivity().getContentResolver().query(StatusProvIDer.CONTENT_URI_CHARTING,null,"? < " + StatusData.KEY_CHARTING_DATE + " AND ? > " + StatusData.KEY_CHARTING_DATE,new String[] {startdate,enddate},null); //        c.movetoFirst();        Log.i("PROJECTCARUSO","count: " + c.getCount());        if (c.getCount()>0 && c!=null) {            while (c.isAfterLast() == false) {                if ((isNumeric(c.getString(c.getColumnIndex(StatusData.KEY_CHARTING_TEMPERATURE))))) {                java.util.Date date = null;                int day = 0;                //get date from database                String datetest = c.getString(c.getColumnIndex(StatusData.KEY_CHARTING_DATE));                //try to reformat to date.                try {                    date = format.parse(datetest);                    day = date.getDate();                } catch (java.text.ParseException e) {                    // Todo auto-generated catch block                    e.printstacktrace();                }                  xArray.add(day);                }            c.movetoNext();            }         }        int[] x = new int[xArray.size()];        for (int i = 0; i < xArray.size(); i++) {            x[i] = xArray.get(i);        }        int[] y = new int[yArray.size()];        for (int i = 0; i < yArray.size(); i++) {            y[i] = yArray.get(i);        }        TimeSerIEs serIEs = new TimeSerIEs(prev_month_name);         for( int i = 0; i < y.length; i++)        {            serIEs.add(x[i],y[i]);        }        //***********************************************//        // Our second data THIS MONTH        //***********************************************//        //start date for cursor        cal2.set(Calendar.DATE,1);        String startdate2 = df.format(cal2.getTime());        //end date        cal2.set(Calendar.DATE,daysInMonth);        String enddate2 = df.format(cal2.getTime());        Log.i("PROJECTCARUSO","DEBUG startdate: " + startdate2 + " enddate: " + enddate2);        Cursor c2 = getActivity().getContentResolver().query(StatusProvIDer.CONTENT_URI_CHARTING,new String[] {startdate2,enddate2},null); //        c2.movetoFirst();        if (c2.getCount()>0 && c2!=null) {            while (c2.isAfterLast() == false)  {                if (isNumeric(c2.getString(c2.getColumnIndex(StatusData.KEY_CHARTING_TEMPERATURE)))){                    yArray2.add(c2.getInt(c2.getColumnIndex(StatusData.KEY_CHARTING_TEMPERATURE)));                    java.util.Date date = null;                    int day = 0;                    //get date from database                    String datetest = c2.getString(c2.getColumnIndex(StatusData.KEY_CHARTING_DATE));                    //try to reformat to date.                    try {                        date = format.parse(datetest);                        day = date.getDate();                    } catch (java.text.ParseException e) {                        // Todo auto-generated catch block                        e.printstacktrace();                    }                      xArray2.add(day);                }            c2.movetoNext();            }         }        int[] x2 = new int[xArray2.size()];        for (int i = 0; i < xArray2.size(); i++) {            x2[i] = xArray2.get(i);        }        int[] y2 = new int[yArray2.size()];        for (int i = 0; i < yArray2.size(); i++) {            y2[i] = yArray2.get(i);        }        TimeSerIEs serIEs2 = new TimeSerIEs(month_name);         for( int i = 0; i < x2.length; i++)        {            serIEs2.add(x2[i],y2[i]);        }        XYMultipleSerIEsDataset dataset = new XYMultipleSerIEsDataset();        dataset.addSerIEs(serIEs);        dataset.addSerIEs(serIEs2);        XYMultipleSerIEsRenderer mRenderer = new XYMultipleSerIEsRenderer(); // Holds a collection of XYSerIEsRenderer and customizes the graph        XYSerIEsRenderer renderer = new XYSerIEsRenderer(); // This will be used to customize line 1        XYSerIEsRenderer renderer2 = new XYSerIEsRenderer(); // This will be used to customize line 2        mRenderer.addSerIEsRenderer(renderer);        mRenderer.addSerIEsRenderer(renderer2);        // Customization time for line 1!        renderer.setcolor(getResources().getcolor(R.color.complementary));        renderer.setPointStyle(PointStyle.SQUARE);        renderer.setFillPoints(true);        // Customization time for line 2!        renderer2.setcolor(getResources().getcolor(R.color.base));        renderer2.setPointStyle(PointStyle.DIAMOND);        renderer2.setFillPoints(true);        mChartVIEw = ChartFactory.getlineChartVIEw(getActivity(),dataset,mRenderer);        //Set Chart Title and labels        mRenderer.setChartTitle("Temperature Tracking");        mRenderer.setChartTitleTextSize(getResources().getDimension(R.dimen.largeText));        mRenderer.setLabelscolor(getResources().getcolor(R.color.primaryTextDark));        //YAxis of Temp        mRenderer.setYTitle("Temperature",0);        mRenderer.setYAxisMin(80,0);        mRenderer.setYAxisMax(110,0);        mRenderer.setYLabelsAlign(Align.CENTER);        mRenderer.setYLabelscolor(0,getResources().getcolor(R.color.primaryTextDark));         //XAxis of month        mRenderer.setXLabels(20);        mRenderer.setXTitle(month_name);                mRenderer.setXAxisMin(1);        mRenderer.setXAxisMax(daysInMonth);        mRenderer.setXLabelscolor(getResources().getcolor(R.color.primaryTextDark));         //Set the display        mRenderer.setmarginscolor(getResources().getcolor(R.color.transparent));        mRenderer.setShowCustomTextGrID(true);        mRenderer.setAxisTitleTextSize(getResources().getDimension(R.dimen.mediumText));        mRenderer.setLabelsTextSize(getResources().getDimension(R.dimen.smallMediumText));        mRenderer.setPanEnabled(false,false);        mRenderer.setClickEnabled(false);        mRenderer.setZoomEnabled(false,false);        return mChartVIEw;    }    @SuppressWarnings("unused")    public static boolean isNumeric(String str)      {        try        {          double d = Double.parseDouble(str);        }        catch(NumberFormatException nfe)        {          return false;        }        return true;      }}

哦,这是那些颜色:

<color name ="base">#51bbc2</color>    <color name ="complementary">#C25951</color>
解决方法 谢谢@Dan你带我到解决方案.我去了并记录了所有的点,以确保所有正确的值都放在正确的数组中,然后找出yArray.add(c.getInt(c.getColumnIndex(StatusData.KEY_CHARTING_TEMPERATURE)));不知何故被删除了.所以现在它有效!好极了! 总结

以上是内存溢出为你收集整理的android – Achartengine线图全部内容,希望文章能够帮你解决android – Achartengine线图所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1138630.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存