telkins
telkins

Reputation: 10540

Achartengine graph not displaying initially

Right now I'm using aChartEngine library in my Android project. It's working nicely so far. One thing I can't figure out is how to get it initially displayed. The only way to show my data is to click and pan somewhere on the graph or press the zoom buttons. So the zoom buttons are initially displayed, but not the graph itself. I searched through the methods for the renderer, but nothing worked. I call mSeriesRenderer.setShowGrid(true); after my renderer is created and it doesn't display. I've also tried to repaint() and not even that is working. Am I calling it at the wrong time?

public void onResume()
{
    if(mMeterObs.getGraph() == null)
    {
        LinearLayout layout = (LinearLayout)findViewById(R.id.chart);
        mMeterObs.setGraph(ChartFactory.getLineChartView(this, mMeterObs.getMultipleSeries(), mMeterObs.getSeriesRenderer()));
        layout.addView(mMeterObs.getGraph(), LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        mMeterObs.repaint();
    }
    else
        mMeterObs.repaint();
}

mMeterObs.getMultipleSeries() and mMeterObs.getSeriesRenderer() are both empty to begin with, but it should still be able to display the grid and axes, right?

In the constructor for mMeterObs I call this:

mSeriesRenderer.setXLabels(12);
    mSeriesRenderer.setYLabels(10);
    mSeriesRenderer.setShowGrid(true);
    mSeriesRenderer.setXLabelsAlign(Align.RIGHT);
    mSeriesRenderer.setYLabelsAlign(Align.RIGHT);
    mSeriesRenderer.setZoomButtonsVisible(true);
    mSeriesRenderer.setRange(new double[] { 0.0, 10.0, -1.0, 1.0 });
    //mSeriesRenderer.setPanEnabled(true);
    mSeriesRenderer.setZoomLimits(new double[] { -10, 20, -10, 40 });
    mSeriesRenderer.setGridColor(Color.LTGRAY);
    mSeriesRenderer.setShowGrid(true);
    mSeriesRenderer.setShowAxes(true);
    mSeriesRenderer.setPointSize(.5f);

Upvotes: 2

Views: 1004

Answers (1)

Dan D.
Dan D.

Reputation: 32391

I suggest you add some series with data. Grids are only displayed along the labels, but you have no labels.

Upvotes: 1

Related Questions