1
我試圖得到相同的圖相似的畫面:的Android:WiFi分析儀條形圖
嗯,我有負數{-50,-70,-40的列表。 ..},我想有相同的圖,但如果我normaly工作,我得到這個圖是顛倒:
我tryed把標籤,而不是y軸的數字,但我doesen我沒有給出我想要的圖表。 請有人告訴我如何做這個圖表,我通過4天試圖在第一張圖片中得到結果。或者給我提供了一個主意,我已經失去了4天serching和trynig :( 這是我使用的代碼:
public class TruitonAChartEngineActivity extends ActionBarActivity {
private static int SERIES_NR ; //the number of columns to display,
@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();
final int nr = 15;
int [] classObject =new int[] {70,-56,-40,-80};
Random r = new Random();
ArrayList<String> legendTitles = new ArrayList<String>();
legendTitles.add("Sales");
legendTitles.add("Expenses");
SERIES_NR = 2 ;
for (int i = 0; i < SERIES_NR; i++) {
CategorySeries series = new CategorySeries(legendTitles.get(i));
for (int k = 0; k < nr; k++) {
if (k==2)
series.add(classObject[k]);
if (k==1)
series.add(classObject[k]);
if (k==0)
series.add(classObject[k]);
if (k==3)
series.add(classObject[k]);
}
dataset.addSeries(series.toXYSeries());
}
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);
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(Color.rgb((int)(Math.random() * 255), (int)(Math.random() * 255), (int)Math.random() * 255));
renderer.addSeriesRenderer(r);
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(0.5);
renderer.setXAxisMax(14.5);
renderer.setYAxisMin(-90);
renderer.setYAxisMax(-30);
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(10, "-90");
renderer.addYTextLabel(20, "-80");
renderer.addYTextLabel(30, "-70");
renderer.addYTextLabel(40, "-60");
renderer.addYTextLabel(50, "-50");
renderer.addYTextLabel(60, "-40");
renderer.addYTextLabel(70, "-30");
renderer.addYTextLabel(80, "");*/
renderer.setPanEnabled(true, true);
renderer.setZoomEnabled(false, false);
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);
}`enter code here`
謝謝
PS:我使用achartengine。