【问题标题】:GraphView with Date Lables and scrollable带有日期标签和可滚动的 GraphView
【发布时间】:2017-06-05 11:45:54
【问题描述】:

我正在尝试使用 GraphView 库使 X 轴具有数据标签,Y 轴具有数字。问题是当使用日期作为标签时,我无法使 X 轴可滚动。 这是代码:

    Calendar calendar = Calendar.getInstance();
    DataPoint[] points = new DataPoint[31];
    Random rand = new Random();
    calendar.add(Calendar.DATE, 0);
    Date startDate = calendar.getTime();
    points[0] = new DataPoint(startDate, rand.nextInt(9) + 1);
    List<String> dataPointsString = new ArrayList<>();
    dataPointsString.add(calendar.getTime().toString());
    calendar.add(Calendar.DATE, -20);
    Date endDate = calendar.getTime();
    calendar.add(Calendar.DATE, +20);
    for (int i = 1; i <= 30; i++) {
        calendar.add(Calendar.DATE, -1);
        points[i] = new DataPoint(calendar.getTime(), rand.nextInt(9) + 1);
        dataPointsString.add(calendar.getTime().toString());
    }

    GraphView graph = (GraphView) view.findViewById(R.id.graph);

    // you can directly pass Date objects to DataPoint-Constructor
    // this will convert the Date to double via Date#getTime()
    LineGraphSeries<DataPoint> series = new LineGraphSeries<>(points);

    // set date label formatter
    graph.getGridLabelRenderer().setLabelFormatter(new DateAsXAxisLabelFormatter(getActivity()));
    graph.getGridLabelRenderer().setNumHorizontalLabels(6);

    graph.getViewport().setYAxisBoundsManual(true);
    graph.getViewport().setMinY(0);
    graph.getViewport().setMaxY(10);

    graph.getViewport().setXAxisBoundsManual(true);

    // as we use dates as labels, the human rounding to nice readable numbers
    // is not necessary
    graph.getGridLabelRenderer().setHumanRounding(false);

    graph.getViewport().setScalable(true);

    graph.addSeries(series);

知道有什么问题吗?

【问题讨论】:

    标签: android graph android-graphview


    【解决方案1】:
         graph.getGridLabelRenderer().setNumHorizontalLabels(11);
    you setted 6 change it to 10 or 11 accordingly and try below...
    
        // activate horizontal zooming and scrolling
    graphview.getViewport().setScalable(true);
    
    // activate horizontal scrolling
    graphview.getViewport().setScrollable(true);
    
    // activate horizontal and vertical zooming and scrolling
    graphview.getViewport().setScalableY(true);
    
    // activate vertical scrolling
    graphview.getViewport().setScrollableY(true);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-01
      • 2014-03-01
      • 2021-08-05
      相关资源
      最近更新 更多