How to remove autoscalling in dynamically updated chart using Achartengine?


Ask by : pawegio November 04, 2012 16:18

I would like to cancel autoscalling during updating the chart and get the effect of "moving" the chart (when I add new data) without scaling it. I hope you know what I want to achieve.

Here is piece of my code where I declare my chart:

    mDataset = new XYMultipleSeriesDataset();

    mRenderer = new XYMultipleSeriesRenderer();
    mRenderer.setAxesColor(Color.BLUE);
    mRenderer.setAxisTitleTextSize(16);
    mRenderer.setChartTitle("Accelerometer monitor");
    mRenderer.setChartTitleTextSize(15);
    mRenderer.setFitLegend(true);
    mRenderer.setGridColor(Color.LTGRAY);
    mRenderer.setPanEnabled(true, false);
    mRenderer.setZoomEnabled(false, true);
    mRenderer.setPointSize(1);
    mRenderer.setXTitle("Time");
    mRenderer.setYTitle("Value");
    mRenderer.setMargins(new int []{20, 30, 15, 0});
    mRenderer.setZoomButtonsVisible(true);
    mRenderer.setBarSpacing(10);
    mRenderer.setShowGrid(true);

    mSeriesRendererX = new XYSeriesRenderer();
    mSeriesRendererX.setColor(Color.RED);

    mSeriesRendererY = new XYSeriesRenderer();
    mSeriesRendererY.setColor(Color.GREEN);

    mSeriesRendererZ = new XYSeriesRenderer();
    mSeriesRendererZ.setColor(Color.BLUE);

    mRenderer.addSeriesRenderer(mSeriesRendererX);
    mRenderer.addSeriesRenderer(mSeriesRendererY);
    mRenderer.addSeriesRenderer(mSeriesRendererZ);

    mSeriesRendererX.setFillPoints(true);
    mSeriesRendererX.setPointStyle(PointStyle.CIRCLE);
    mSeriesRendererY.setFillPoints(true);
    mSeriesRendererY.setPointStyle(PointStyle.CIRCLE);
    mSeriesRendererZ.setFillPoints(true);
    mSeriesRendererZ.setPointStyle(PointStyle.CIRCLE);

    mTimeSeriesX = new TimeSeries("x");
    mTimeSeriesY = new TimeSeries("y");
    mTimeSeriesZ = new TimeSeries("z");
View original question

Answer by : DanNovember 04, 2012 16:18

You can control the scaling by manually setting the visible range on the axis:

mRenderer.setXAxisMin(xMinValue);
mRenderer.setXAxisMax(xMaxValue);
mRenderer.setYAxisMin(yMinValue);
mRenderer.setYAxisMax(yMaxValue);
View original answer