1
votes

Looking for a basic "AndroidPlot" bar graph example.

A few people have contacted the developer via the site forum but he mentions he is still working on that tutorial.

However, he does link to a more in depth example to look at for now.

The problem is I can't figure out which parts render the bar graph vs. the other functionality, as I am obviously not familiar with the more complex parts of the library.

Can any one please help me with a basic structure of code for a bar graph, using AndroidPlot please?

Thank you.

1
why -1? isn't this the place we help each other with specific questions after looking every where? - Greg McNulty
The main reason for the -1 is: what did you try? Show some code. - Bart Friederichs

1 Answers

0
votes

I got it working like this with AChartEngine (setup, I use one renderer, with one dataset, it is an active changeing graph):

LinearLayout layout = (LinearLayout)findViewById(R.id.chart);

// setup dataset and renderer
dataset = new XYMultipleSeriesDataset();
renderer = new XYMultipleSeriesRenderer();

// configure renderer
renderer.setZoomEnabled(false, false);
renderer.setPanEnabled(false, false);
renderer.setYAxisMax(90);
renderer.setYAxisMin(0);
renderer.setXAxisMin(-1);
renderer.setBarSpacing(0.5);
renderer.setShowLegend(false);
renderer.setXLabels(0);             // hides the default labels
renderer.setLabelsTextSize(15);

// create chart
mChartView = ChartFactory.getBarChartView(this, dataset, renderer, BarChart.Type.DEFAULT);
layout.addView(mChartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

// add some data, so the chart shows
XYSeriesRenderer r = new XYSeriesRenderer();
r.setColor(Color.rgb(192, 192, 192));
renderer.addSeriesRenderer(r);
XYSeries c = new XYSeries("");
c.add(0,0);
dataset.addSeries(c);

Then later, render it again to liven it up (note I ripped some parts from my own code, it might not be complete):

// remove any bars that already exist
if (theAct.dataset.getSeriesCount() > 0) {
    theAct.dataset.removeSeries(0);
}

XYSeries c = new XYSeries("");

// for some reason, the bar is very narrow, when only one bar is shown,
// when we use a negative spacing, the bar will be bigger
// i is the number of bars
if (i == 1) {
    theAct.renderer.setBarSpacing(-0.8);
} else {
    theAct.renderer.setBarSpacing(0.5);
}

// finish up and render!
theAct.renderer.setXAxisMax(i);
theAct.dataset.addSeries(c);
theAct.mChartView.zoomReset();
theAct.mChartView.repaint();