Question

I have an issue with an achartengine graph - as in this screenshot:

the broken layout

It looks like the X axis is given too much bottom padding, and the values are duplicated (one representation of each value is in the graph proper, and reacts properly to panning, while the other is located at the bottom of the graph view, but can't be manipulated in any way).

Here's the code used to create the graph:

protected void onCreate(Bundle savedInstanceState) {
        ...
        gDataset = new XYMultipleSeriesDataset();

        gRenderer = new XYMultipleSeriesRenderer();
        gRenderer.setApplyBackgroundColor(true);
        gRenderer.setPointSize(10);

        chart = new TimeBarChart(gDataset, gRenderer);
        graphView = new GraphicalView(this, chart);
        graphHolder.addView(graphView);
        //Mode is just an internal enum
        chart.setDateFormat(curMode == Mode.DAY ? "HH:mm dd.MM.yyyy" : "dd.MM.yyyy");
        ....
}

And to populate it:

...
//some DB stuff goes here, result is the cursor

curSeries = new XYSeries("");
gDataset.addSeries(curSeries);

XYSeriesRenderer renderer = new XYSeriesRenderer();
renderer.setColor(Color.RED);
renderer.setPointStyle(PointStyle.POINT);
gRenderer.addSeriesRenderer(renderer);
while (!result.isAfterLast()) {
    .....
    curSeries.add(timestamp,value);
      ....
}
.....
graphView.invalidate();
graphView.repaint();

And here's the graph holder's view definition in the layout XML (main container is RelativeLayout of course) :

<LinearLayout
    android:id="@+id/graphHolder"
    android:layout_width="fill_parent"
    android:layout_height="200dp"
    android:layout_alignParentTop="true"
    android:minHeight="200dp">
</LinearLayout>

A couple of things:

  • I'm using the 0.7 version.
  • The TimeBarChart class is nothing else than a TimeChart with the simple change to extend BarChart instead. The code is copied from the 0.7 revision. Regardless, I was using ChartFactory#getTimeChartView() previously and the result was the same - so this isn't the cause of the problem.
  • I've tried checking whether the height layout parameter causes the problem, but that wasn't it as well.
  • graphHolder is injected by RoboGuice.
  • the problem was encountered in the 2.3 emulator.

Obviously, I'm doing something wrong, but I'm at a loss what. Any help is greatly appreciated.

PS. I've tried to post it on the achartengine group, but it looks like the mods are hibernating for the winter ;).

Was it helpful?

Solution

I finally had time to reinvestigate this, and figured it out.

The gist:

The bars on the bottom are the legend. I had a bug in my code that caused it to create a series for each datapoint, hence the multiple "bars", in reality legend graphics. The series had no names, which added to the confusion.

Fixing the bug and adding setShowLegend(false) dealed with the issue.

I've discovered this while evaluating AndroidPlot (BTW, I recommend it as an alternative to achartengine, as graphs can be defined in XML, and can be way more liberally customized graphically than the screenshots suggest).

I somehow failed to notice the legend in the achartengine screenshots, but I recognized them in AndroidPlot. And yes, I do feel quite stupid now :).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top