Display hours per hour in GraphView?

826 Views Asked by At

Using the GraphView library i found this part of code:

/*
         * 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

That displays the date like "Sept 16, Sept 20" Ect etc... Is there possible change this code and display hour per hour? Like "06.00, 07.00, 08.00" etc etc?

1

There are 1 best solutions below

9
On

You shoud use SimpleDateFormat for date formatting:

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
    }