android – 如何使用AChartEngine动态线图和X轴自动平移(滚动)?

android – 如何使用AChartEngine动态线图和X轴自动平移(滚动)?,第1张

概述我使用AChartEngine Api创建了动态折线图,显示了G-Force值的变化.一切正常,但当图形在X轴向前移动时,我必须在X轴上手动滚动才能进一步查看,如果您没有正确使用我,请查看下面的图像. 如何让它在x轴上自动滚动以避免手动滚动? 以下是我的代码 public class GraphActivity extends Activity implements SensorEventList 我使用AChartEngine API创建了动态折线图,显示了G-Force值的变化.一切正常,但当图形在X轴向前移动时,我必须在X轴上手动滚动才能进一步查看,如果您没有正确使用我,请查看下面的图像.

如何让它在x轴上自动滚动以避免手动滚动?
以下是我的代码

public class GraphActivity extends Activity implements SensorEventListener{    private linearLayout lyGforce;    //=== G-force =======    private SensorManager mSensorManager;    private Sensor mAccelerometer;    private float gOffset;    private boolean calibrate;    private static TimeSerIEs timeSerIEsGforce;    private static XYMultipleSerIEsDataset datasetGforce;    private static XYMultipleSerIEsRenderer rendererGforce;    private static XYSerIEsRenderer rendererSerIEsGforce;    private static GraphicalVIEw vIEwGforce;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        // Todo auto-generated method stub        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.mainactivity);        lyGforce = (linearLayout) findVIEwByID(R.ID.lygforce);        //=========== G-force =======        mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);        mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);        datasetGforce = new XYMultipleSerIEsDataset();        rendererGforce = new XYMultipleSerIEsRenderer();        rendererGforce.setApplyBackgroundcolor(true);        rendererGforce.setBackgroundcolor(color.argb(100,50,50));        rendererGforce.setAxisTitleTextSize(16);        rendererGforce.setChartTitleTextSize(20);        rendererGforce.setLabelsTextSize(15);        rendererGforce.setLegendTextSize(15);        rendererGforce.setmargins(new int[] { 20,30,15,0 });        rendererGforce.setZoombuttonsVisible(true);        rendererGforce.setPointSize(10);        rendererGforce.setShowGrID(true);        rendererGforce.setGrIDcolor(color.WHITE);        rendererSerIEsGforce = new XYSerIEsRenderer();        rendererSerIEsGforce.setcolor(color.GREEN);        rendererSerIEsGforce.setlinewidth(2);        rendererGforce.addSerIEsRenderer(rendererSerIEsGforce);        timeSerIEsGforce = new TimeSerIEs("G-Force");        datasetGforce.addSerIEs(timeSerIEsGforce);        vIEwGforce = ChartFactory.getTimeChartVIEw(this,datasetGforce,rendererGforce,"");        vIEwGforce.refreshDrawableState();        vIEwGforce.repaint();        lyGforce.addVIEw(vIEwGforce);    }    @OverrIDe    protected voID onResume() {        // Todo auto-generated method stub        super.onResume();        // ============= G-force ==================//        calibrate = true;        mSensorManager.registerListener(this,mAccelerometer,SensorManager.SENSOR_DELAY_UI);    }    @OverrIDe    protected voID onPause() {        // Todo auto-generated method stub        super.onPause();        //========== G-force=============//        mSensorManager.unregisterListener(this);    }    @OverrIDe    public voID onAccuracyChanged(Sensor sensor,int accuracy) {        // Todo auto-generated method stub    }    //========== G-force=============//    @OverrIDe    public voID onSensorChanged(SensorEvent event) {        // Todo auto-generated method stub        switch (event.sensor.getType()) {            case Sensor.TYPE_ACCELEROMETER:                float x = event.values[0];                float y = event.values[1]; // Use to calculate G-Force value                float z = event.values[2];                if(calibrate)                    gOffset = y - SensorManager.GraviTY_EARTH;                double gForce = ((y - gOffset) / SensorManager.GraviTY_EARTH);                timeSerIEsGforce.add(new Date(),gForce);                  rendererGforce.setXAxisMax(rendererGforce.getXAxisMax() + 30);           rendererGforce.setXAxisMin(rendererGforce.getXAxisMin() + 30);                vIEwGforce.repaint();                Log.e("NIRAV","G-Force: "+String.valueOf(gForce));                calibrate = false;            break;            default:                break;        }    }}
解决方法 您可以通过更改X轴上的可见区域来执行此 *** 作:

renderer.setXAxisMin(min);renderer.setXAxisMax(max);
总结

以上是内存溢出为你收集整理的android – 如何使用AChartEngine动态线图和X轴自动平移(滚动)?全部内容,希望文章能够帮你解决android – 如何使用AChartEngine动态线图和X轴自动平移(滚动)?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1129894.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存