1

使用 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”等?

4

1 回答 1

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
    }
于 2013-08-28T08:52:44.410 回答