Using dates with the Graphview library

后端 未结 4 1463
时光取名叫无心
时光取名叫无心 2020-12-31 11:50

I\'m using GraphView library (see: https://github.com/jjoe64/GraphView or http://www.jjoe64.com/p/graphview-library.html)

But I would like to use Date/Time for the X

4条回答
  •  难免孤独
    2020-12-31 12:39

    I created the horizontal labels at the same time I was setting the values:

    public void initializeLineGraphView() {
    
        // Get last weeks entries from the DB
        ArrayList entries = DbManager.getInstance().getLastWeeksEntries(new Date());
        String[] hLabels = new String[entries.size()];
        GraphView.GraphViewData[] graphViewData = new GraphView.GraphViewData[entries.size()];
    
        for(int i = 0; i < entries.size(); i++) {
    
            Entry entry = entries.get(i);
            int pain = entry.getPain();
            graphViewData[i] = new GraphView.GraphViewData(i, pain);
    
            // Generate the horizontal labels
            SimpleDateFormat sdf = new SimpleDateFormat("EEE");
            String dayOfWeek = sdf.format(entry.getDate());
            hLabels[i] = dayOfWeek;
    
        }
    
        mSeries = new GraphViewSeries("", null, graphViewData);
        GraphView graphView = new LineGraphView(getActivity(), "");
        graphView.addSeries(mSeries);
        graphView.setHorizontalLabels(hLabels);
        graphView.setVerticalLabels(new String[] {"10", "5", "0"});
        mLineGraphView = graphView;
    
    }
    

提交回复
热议问题