启用与图表的交互(缩放 in/out)Android 上的 MPAndroid图表

Enable interaction with a chart (zoom in/out) MPAndroidChart on Android

我正在 Android

上使用 MPAndroid图表

当有11条数据时,屏幕上只显示9条。

我想通过拖动来移动屏幕以查看其余部分,但这是不可能的。

需要补充什么吗?

chart.setData(data);

XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);

chart.getAxisRight().setEnabled(false);

chart.getLegend().setEnabled(false);

chart.getAxisLeft().setDrawGridLines(false);
chart.getXAxis().setDrawGridLines(false);
chart.getAxisRight().setDrawGridLines(false);

chart.getDescription().setEnabled(false);

chart.setScaleEnabled(false);


CustomMarkerView marker = new CustomMarkerView(getContext(),R.layout.chart_marker);
chart.setMarkerView(marker);

xAxis.setGranularityEnabled(true);

xAxis.setLabelRotationAngle(90f);

xAxis.setLabelCount(mWeekDataset.size(),false);
xAxis.setGranularity(1f);

我重现了你的问题。您必须设置 chart.setScaleEnabled(true);,而不是 false

来自文档:

/**
     * Set this to true to enable scaling (zooming in and out by gesture) for
     * the chart (this does not effect dragging) on both X- and Y-Axis.
     *
     * @param enabled
     */
    public void setScaleEnabled(boolean enabled) {
        this.mScaleXEnabled = enabled;
        this.mScaleYEnabled = enabled;
    }