在GraphView中显示每小时的小时数?

时间:2013-08-28 08:20:46

标签: android datetime android-graphview

使用GraphView库我发现了这部分代码:

/*
         * use Date as x axis label
         */
        long now = new Date().getTime();
        data = new GraphViewData[size];
        for (int i=0; i<size; i++) {
            data[i] = new GraphViewData(now+(i*60*60*24*1000), rand.nextInt(20)); // next day
        }
        exampleSeries = new GraphViewSeries(data);

        if (getIntent().getStringExtra("type").equals("bar")) {
            graphView = new BarGraphView(
                    this
                    , "GraphViewDemo"
            );
        } else {
            graphView = new LineGraphView(
                    this
                    , "GraphViewDemo"
            );
            ((LineGraphView) graphView).setDrawBackground(true);
        }
        graphView.addSeries(exampleSeries); // data

显示日期,如“9月16日,9月20日”等等......是否有可能更改此代码并显示每小时的小时数?像“06.00,07.00,08.00”等?

1 个答案:

答案 0 :(得分:0)

您应该使用SimpleDateFormat进行日期格式设置:

SimpleDateFormat hoursDateFormat = new SimpleDateFormat("h.mm");

for (int i=0; i<size; i++) {
    data[i] = new GraphViewData(hoursDateFormat.format(now+(i*60*60*24*1000)), rand.nextInt(20)); // next day
    }
相关问题