2014-04-10 59 views
1

我試圖得到相同的圖相似的畫面:的Android:WiFi分析儀條形圖

enter image description here

嗯,我有負數{-50,-70,-40的列表。 ..},我想有相同的圖,但如果我normaly工作,我得到這個圖是顛倒:

enter image description here

我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。

回答

1

嗯,我找到了一個解決方案,我敢肯定,這不是最好的,但仍優於什麼:

Y軸將從​​(實數)開始,我將設置標籤,而不是像這樣的實數:

-90 correspond to 30 
-80 correspond to 40 ... 

PS:我敢肯定,我的Y座標將-90 to -30變化:

這是代碼:

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 , 70, 20, 75, 
       95, 35,45,10};//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++) { 
      CategorySeries series = new CategorySeries(legendTitles.get(i)); 
      int[] v = values.get(i); 
      int seriesLength = v.length; 
      for (int k = 0; k < seriesLength; k++) { 
       switch (v[k]/10){ 
       case -8 : 
         //series.add(classObject[k]); 
         if (v[k] %10 == 0) 
          series.add(40); 
         else 
          series.add(40 - v[k] %10); 

         break; 
       case -7 : 
         //series.add(classObject[k]); 
         if (v[k] %10 == 0) 
          series.add(50); 
         else 
          series.add(50 - v[k] %10); 
         break; 
       case -6 : 
         //series.add(classObject[k]); 
         if (v[k] %10 == 0) 
          series.add(60); 
         else 
          series.add(60 - v[k] %10); 
         break; 
       case -5 : 
         //series.add(classObject[k]); 
         if (v[k] %10 == 0) 
          series.add(70); 
         else 
          series.add(70 - v[k] %10); 
         break; 
       case -4 : 
         //series.add(classObject[k]); 
         if (v[k] %10 == 0) 
          series.add(80); 
         else 
          series.add(80 - v[k] %10); 
         break; 
       case -3 : 
         //series.add(classObject[k]); 
         if (v[k] %10 == 0) 
          series.add(90); 
         else 
          series.add(90 - v[k] %10); 
         break; 
        } 


       } 
       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); 
     for (int k = 0; k < 14; k++) 
     { 
      SimpleSeriesRenderer r = new SimpleSeriesRenderer(); 
      r.setColor(Color.rgb((int)(Math.random() * 255), (int)(Math.random() * 255), (int)Math.random() * 255)); 
      renderer.addSeriesRenderer(r); 
     } 
     /* 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(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(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); 

    } 

    @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); 
    } 
}