【问题标题】:MPAndroid line chart expanding if values on x-axis is in large size如果 x 轴上的值较大,则 MPAndroid 折线图会扩展
【发布时间】:2016-04-12 12:18:11
【问题描述】:

我正在使用 MPAndroid 库来表示折线图和饼图。当我在 x 轴上使用像 1,2,3,4.. 这样的小值时,图表适合屏幕并且不需要滚动。但是当 x 轴的数据像日期范围(2016 年 4 月 13 日)一样大时,它只会在屏幕上给我 5 个值而不是 10 个,当我缩放图表时,它会显示水平滚动中的所有值。使用下面的代码

 private void initializeChart(LineChart chart) {
    // Chart view
    chart.setDrawGridBackground(false);
    chart.setDescription("");
    chart.getLegend().setEnabled(true);
    chart.setTouchEnabled(false);
    int color = getResources().getColor(R.color.white);
    chart.getAxisLeft().setTextColor(color); // left y-axis
    chart.getXAxis().setTextColor(color);
    //X axis
    XAxis xAxis = chart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawLabels(true);

    //Y axis
    YAxis leftAxis = chart.getAxisLeft();
    YAxis rightAxis = chart.getAxisRight();
    rightAxis.setDrawLabels(false);
    rightAxis.setDrawGridLines(false);
    leftAxis.setDrawLabels(true);
    leftAxis.setDrawGridLines(false);
    ChartItem item = CannonJsonParser.parseCanonJson(act, act.res);

    setLineData(10, 20, item);
    // set data
    chart.setData(lineData);
    chart.getLegend().setEnabled(false);
    //animate
    // chart.animateX(2000, Easing.EasingOption.EaseInOutQuart);
    chart.setDragEnabled(true);
    chart.setTouchEnabled(true);
    chart.setScaleXEnabled(true);
    chart.setScaleYEnabled(false);
    chart.setHighlightPerDragEnabled(false);
    chart.setHighlightPerTapEnabled(false);
}

我希望所有数据都应该固定在一个屏幕上而不滚动,或者如果它滚动那么它应该是可滚动的而不需要缩放图形。现在,当我放大图表时,只有它会滚动并显示所有数据。

【问题讨论】:

    标签: android mpandroidchart


    【解决方案1】:

    设置 AxisMaxValue()。它将显示正确的图表。

    chart.getAxisLeft().setAxisMaxValue(float);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-20
      • 1970-01-01
      • 2014-07-06
      • 1970-01-01
      • 2019-12-07
      相关资源
      最近更新 更多