I'm using achartEngine library ,and i'm drawing a bar graphe .I would like to have a superposable bars for example if they have the same X coordinates.
This is what i wont to obtaine :
This is what i'm actualy obtaining : If two bars hve the same x ,they are just neighbors.And this is not clear to undertand and specialy if i have more then two bars with the same x.
And this is the code i'm using :
public class TruitonAChartEngineActivity extends ActionBarActivity {
private static int SERIES_NR ; //the number of columns to display,
List<int[]> values = new ArrayList<int[]>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_truiton_achart_engine);
XYMultipleSeriesRenderer renderer = getTruitonBarRenderer();
myChartSettings(renderer);
Intent intent = ChartFactory.getBarChartIntent(this, getTruitonBarDataset(), renderer, Type.DEFAULT);
startActivity(intent);
}
private XYMultipleSeriesDataset getTruitonBarDataset() {
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
int [] classObject =new int[] {-70,-56,-45,-80,-47,-55,-80,-50};//,-75};//-85,-35,-45};//Signal strength receiver from each access point
for (int j=0;j<classObject.length;j++){
values.add(new int[] { classObject[j]}); //every serie will concern an access point and contain one RSSI
}
final int nr = classObject.length;
ArrayList<String> legendTitles = new ArrayList<String>();
for (int k = 0; k < classObject.length; k++) {
legendTitles.add("Sales"+k);//every serie will have a legend
}
SERIES_NR = classObject.length ;//number of access point
for (int i = 0; i < SERIES_NR; i++) {//Loop for every series
CategorySeries series = new CategorySeries(legendTitles.get(i));
int[] v = values.get(i);
int seriesLength = v.length;
dataset.addSeries(series.toXYSeries());
for (int k = 0; k < seriesLength; k++) {
Log.i("STOOP SERIES_NR",SERIES_NR+"");
Log.i("STOOP ii",i+"");
Log.i("STOOP",k+"");
Log.i("STOOP",v[k]+"");
Log.i("STOOP",v[k] / 10+"");
switch (v[k] / 10){
case -8 :
//series.add(classObject[k]);
if (v[k] %10 == 0)
//series.add(40);
{XYSeries tempSerie = dataset.getSeriesAt(i);
tempSerie.add(i, 40);
}
else
//series.add(40 - v[k] %10);
{XYSeries tempSerie = dataset.getSeriesAt(i);
tempSerie.add(i, 40 - v[k] %10);
}
break;
case -7 :
//series.add(classObject[k]);
if (v[k] %10 == 0)
{
XYSeries tempSerie = dataset.getSeriesAt(i);
tempSerie.add(i, 50);
tempSerie.addAnnotation("text *** "+i, 0, 50);
}
else
//series.add(50 - v[k] %10);
{XYSeries tempSerie = dataset.getSeriesAt(i);
tempSerie.add(i, 7.5,50 - v[k] %10);
// series.toXYSeries().add(7.5,50 - v[k] %10);
}
break;
case -6 :
//series.add(classObject[k]);
if (v[k] %10 == 0)
//series.add(60);
{XYSeries tempSerie = dataset.getSeriesAt(i);
tempSerie.add(i, 60);
}
else
//series.add(60 - v[k] %10);
{XYSeries tempSerie = dataset.getSeriesAt(i);
tempSerie.add(i, 60 - v[k] %10);
}
break;
case -5 :
//series.add(classObject[k]);
if (v[k] %10 == 0)
//series.add(70);
{XYSeries tempSerie = dataset.getSeriesAt(i);
tempSerie.add(i, 70);
}
else
//series.add(70 - v[k] %10);
{XYSeries tempSerie = dataset.getSeriesAt(i);
tempSerie.add(i, 70 - v[k] %10);
}
break;
case -4 :
//series.add(classObject[k]);
if (v[k] %10 == 0)
//series.add(80);
{XYSeries tempSerie = dataset.getSeriesAt(i);
tempSerie.add(i, 80);
}
else
{XYSeries tempSerie = dataset.getSeriesAt(i);
tempSerie.add(i, 80 - v[k] %10);
tempSerie.addAnnotation("text"+i, i, 80 - v[k] %10);
}
break;
case -3 :
//series.add(classObject[k]);
if (v[k] %10 == 0)
{XYSeries tempSerie = dataset.getSeriesAt(i);
tempSerie.add(i, 90);
}
else
//series.add(90 - v[k] %10);
{XYSeries tempSerie = dataset.getSeriesAt(i);
tempSerie.add(i, 90 - v[k] %10);
}
break;
}
}
}
return dataset;
}
public XYMultipleSeriesRenderer getTruitonBarRenderer() {
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
renderer.setAxisTitleTextSize(10);
renderer.setChartTitleTextSize(20);
renderer.setLabelsTextSize(10);
renderer.setLegendTextSize(10);
renderer.setMargins(new int[] { 30, 40, 15, 0 });
int randomColor = Color.rgb((int)(Math.random() * 255), (int)(Math.random() * 255), (int)Math.random() * 255);
for (int k = 0; k < 8; k++)
{
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(Color.rgb((int)(Math.random() * 255), (int)(Math.random() * 255), (int)Math.random() * 255));
renderer.addSeriesRenderer(r);
}
return renderer;
}
@SuppressWarnings("deprecation")
private void myChartSettings(XYMultipleSeriesRenderer renderer) {
renderer.setChartTitle("Wifi Channels");
renderer.setXAxisMin(1);
renderer.setXAxisMax(14);
renderer.setYAxisMin(30);
renderer.setYAxisMax(90);
renderer.addXTextLabel(1, "1");
renderer.addXTextLabel(2, "2");
renderer.addXTextLabel(3, "3");
renderer.addXTextLabel(4, "4");
renderer.addXTextLabel(5, "5");
renderer.addXTextLabel(6, "6");
renderer.addXTextLabel(7, "7");
renderer.addXTextLabel(8, "8");
renderer.addXTextLabel(9, "9");
renderer.addXTextLabel(10, "10");
renderer.addXTextLabel(11, "11");
renderer.addXTextLabel(12, "12");
renderer.addXTextLabel(13, "13");
renderer.addXTextLabel(14, "14");
renderer.addYTextLabel(0, "");
renderer.addYTextLabel(30, "-90");
renderer.addYTextLabel(40, "-80");
renderer.addYTextLabel(50, "-70");
renderer.addYTextLabel(60, "-60");
renderer.addYTextLabel(70, "-50");
renderer.addYTextLabel(80, "-40");
renderer.addYTextLabel(90, "-30");
renderer.addYTextLabel(100, "");
renderer.setPanEnabled(true, true);
renderer.setZoomEnabled(true, true);
renderer.setApplyBackgroundColor(true);
renderer.setBackgroundColor(Color.BLACK);
renderer.setYLabelsAlign(Align.RIGHT);
renderer.setBarSpacing(0.5);
renderer.setXTitle("Canal du WiFi");
renderer.setYTitle("Puissance du signal[dbm]");
renderer.setShowGrid(true);
renderer.setGridColor(Color.GRAY);
renderer.setXLabels(0); // sets the number of integer labels to appear
renderer.setXLabels((int) 0.5);//25
renderer.setYLabels(10);
renderer.setBarWidth(10);// bar width
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.truiton_achart_engine, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Thank you for helping.
来源:https://stackoverflow.com/questions/23006054/android-achartengine-superposable-bar-in-the-same-x-axis-coordinate