首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >安卓: GraphView如何在X轴上实现时间?

安卓: GraphView如何在X轴上实现时间?
EN

Stack Overflow用户
提问于 2014-01-19 13:54:26
回答 3查看 9.4K关注 0票数 3

我发现在Android中如何在图形的X轴上实现时间有点困难吗?

这是我的密码:

代码语言:javascript
运行
复制
for (int i = 0; i < listSize; i++) 
            {
                String[] onlyReading = mData.get(i).getReading().split(" ");
                readingList[i] = Double.parseDouble(onlyReading[0]);
                String date = mData.get(i).getUnFormatedDate();
                String[] temp = date.split(" ");
                String[] dateTemp = null;
                String[] timeTemp = null;

                if(temp.length > 0) 
                {
                    dateTemp = temp[0].trim().split("-");
                    timeTemp = temp[1].trim().split(":");

                    Date dateObj = new Date();
                    String year = "0";
                    if(dateTemp != null)
                    {
                        dateObj.setDate(Integer.parseInt(dateTemp[0]));
                        dateObj.setMonth(Integer.parseInt(dateTemp[1]) - 1);
                        year = dateTemp[2].trim();
                        if(dateTemp[2].trim().length() == 4)
                        {
                            year = dateTemp[2].substring(2, 4);
                        }
                        dateObj.setYear(Integer.parseInt(year)+100);
                    }
                    if(timeTemp != null)
                    { 
                        calendar = new GregorianCalendar(Integer.parseInt(year) + 2000, Integer.parseInt(dateTemp[1]) - 1, Integer.parseInt(dateTemp[0]), Integer.parseInt(timeTemp[0]), Integer.parseInt(timeTemp[1]));
                    }

                    dateObj = new Date(calendar.getTimeInMillis());
                    dateList[i] = dateObj;
                }
            }

            if(dateList.length > 0)
            { 
                //dates.clear();
                //values.clear();
                //readingData.clear();
                //readingDate.clear();

                GraphViewData[] data = new GraphViewData[dateList.length];





                LineGraphView graphView = new LineGraphView(
                          getActivity() // context
                          , "" // heading
                    );


                for (int i = 0; i < listSize; i++)
                {
                    data[i] = new GraphViewData(Double.valueOf(i), readingList[i]);
                } 

                GraphViewSeries exampleSeries = new GraphViewSeries(data);
                graphView.addSeries(exampleSeries);
                graphView.setDrawBackground(false);
                ((LineGraphView) graphView).setDrawDataPoints(true);
                graphView.getGraphViewStyle().setGridColor(0);
                graphView.getGraphViewStyle().setHorizontalLabelsColor(Color.WHITE);
                graphView.getGraphViewStyle().setVerticalLabelsColor(Color.WHITE);
                graphView.getGraphViewStyle().setNumHorizontalLabels(5);
                graphView.getGraphViewStyle().setNumVerticalLabels(5);
                graphView.setManualYAxisBounds(400, 0);
                mGraphParent.addView(graphView);
            }  
        }

即使我添加Y轴值,我也无法知道如何将时间值添加到X轴?

EN

Stack Overflow用户

回答已采纳

发布于 2014-01-25 17:57:29

诀窍是将时间转换为秒或毫秒(unix时间),并将其转换为X值。

在GraphView项目上有一个例子。看一看:

https://github.com/jjoe64/GraphView-Demos/blob/master/src/com/jjoe64/graphviewdemos/CustomLabelFormatterActivity.java#L68

票数 2
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21217635

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档