问题描述
我想显示的信息得到了来自无线扫描与广播接收器,为条形图使用achartengine。嗯,我想有一个真正的时间表,我每次接收数据的onReceive()方法,我更新图表。要achaeive,我创造了的onReceive()方法。但我只是得到一个图表的第一个结果的图表对象,没有及时更新,但我可以看到在无线扫描的变化。我想知道是什么问题。这是我使用的code:
公共类WifiChartsRealTime延伸活动{
的LinearLayout布局;
名单< INT [] GT;值=新的ArrayList&其中; INT []≥();
//名单,其中,ScanResult> classObject =新的ArrayList< ScanResult>();
INT [] [] Center_Frequency_2 = {{1,2,3,4,5,6,7,8,9,10,11,12,13,14},
{2412,2417,2422,2427,2432,2437,2442,2447,2452,2457,2462,2467,2472,2484},
};
WifiManager无线网络;
按钮ENAB;
字符串resultsString;
的String [] myStringArray;
INT AA = 10;
公共类接收器扩展的BroadcastReceiver {
@覆盖
公共无效的onReceive(上下文的背景下,意图意图){
INT长;
如果(intent.getAction()。等于(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)){
名单< ScanResult>结果= wifi.getScanResults();
长度= results.size();
Toast.makeText(getApplicationContext(),
resultsString *****************:+结果,Toast.LENGTH_LONG)
。显示();
Toast.makeText(getApplicationContext(),
长度1:+长度,Toast.LENGTH_LONG)
。显示();
Log.i(长度1,长度+);
XYMultipleSeriesRenderer渲染= getTruitonBarRenderer(results.size());
myChartSettings(渲染);
/ *意图intent1 = ChartFactory.getBarChartIntent(WifiChartsRealTime.this,getTruitonBarDataset(),renderer,Type.DEFAULT);
startActivity(intent1); * /
GraphicalView mChartView = ChartFactory.getBarChartView(WifiChartsRealTime.this,getTruitonBarDataset(结果),渲染器,Type.STACKED);
layout.addView(mChartView);
// mChartView.refreshDrawableState();
mChartView.repaint();
}
}
}
@覆盖
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_wifi_charts_real_time);
布局=(的LinearLayout)findViewById(R.id.chart);
ConnectivityManager cxMgr =(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
无线=(WifiManager)getSystemService(Context.WIFI_SERVICE);
接收器接收器=新的接收器();
registerReceiver(接收器,新的IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
registerReceiver(接收器,新的IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
}
私人XYMultipleSeriesDataset getTruitonBarDataset(名单< ScanResult> classObject){
INT SERIES_NR; //列数来显示,
ArrayList的<字符串> legendTitles =新的ArrayList<字符串>();
XYMultipleSeriesDataset数据集=新XYMultipleSeriesDataset();
Toast.makeText(getApplicationContext(),
位置XYMultipleSeriesDataset:+ classObject,Toast.LENGTH_LONG)
。显示();
Toast.makeText(getApplicationContext(),
大小XYMultipleSeriesDataset:+ classObject.size(),Toast.LENGTH_LONG)
。显示();
//长度= classObject.size();
对于(INT J = 0; J< classObject.size(); J ++){
values.add(新INT [] {classObject.get(J).LEVEL}); //每一个意甲将关注的一个接入点,并包含一个RSSI
}
对于(INT K = 0; K< classObject.size(); k ++){
legendTitles.add(classObject.get(K).SSID); //每意甲将有一个传说中的SSID
}
//确定DES canaux
INT [] channelsTab =新INT [classObject.size()];
的for(int i = 0; I< classObject.size();我++){
如果(classObject.get(ⅰ)。频率/ 1000 == 2){
对于(INT J = 0; J< 14,J ++)
{如果(Center_Frequency_2 [1] [j]的== classObject.get(ⅰ)。频率)
channelsTab [i] = Center_Frequency_2 [0] [J]。
}
}
}
// FIN确定DES canaux
SERIES_NR = classObject.size(); //接入点的数目
的for(int i = 0; I< SERIES_NR;我++){//循环,每系列
CategorySeries系列=新CategorySeries(legendTitles.get(一));
INT []ν= values.get(ⅰ);
INT seriesLength = v.length;
dataset.addSeries(series.toXYSeries());
对于(INT K = 0; K< seriesLength; k ++){
Log.i(屈尊SERIES_NR,SERIES_NR +);
Log.i(屈尊II,我+);
Log.i(自甘堕落,K +);
Log.i(自甘堕落,V [K] +);
Log.i(自甘堕落,V [K] / 10 +);
/ * XYSeries tempSerie = dataset.getSeriesAt(ⅰ);
tempSerie.add(ⅰ,40 - v [k]的%10); * /
开关(ⅴ[k]的/ 10){
案例-9:
//series.add(classObject[k]);
如果(ⅴ[k]的%10 == 0)
//series.add(40);
{XYSeries tempSerie = dataset.getSeriesAt(ⅰ);
tempSerie.add(channelsTab [I],30);
tempSerie.addAnnotation(legendTitles.get(ⅰ)+:+ V [k]的,channelsTab [I],30);
}
其他
//series.add(40 - v [k]的%10);
{XYSeries tempSerie = dataset.getSeriesAt(ⅰ);
tempSerie.add(channelsTab [I]中,30 - v [k]的%10);
tempSerie.addAnnotation(legendTitles.get(ⅰ)+:+ V [k]的,channelsTab [I]中,30 - v [k]的%10);
}
打破;
案例-8:
//series.add(classObject[k]);
如果(ⅴ[k]的%10 == 0)
//series.add(40);
{XYSeries tempSerie = dataset.getSeriesAt(ⅰ);
tempSerie.add(channelsTab [I],40);
tempSerie.addAnnotation(legendTitles.get(ⅰ)+:+ V [k]的,channelsTab [I],40);
}
其他
//series.add(40 - v [k]的%10);
{XYSeries tempSerie = dataset.getSeriesAt(ⅰ);
tempSerie.add(channelsTab [I]中,40 - v [k]的%10);
tempSerie.addAnnotation(legendTitles.get(ⅰ)+:+ V [k]的,channelsTab [I]中,40 - v [k]的%10);
}
打破;
案例-7:
//series.add(classObject[k]);
如果(ⅴ[k]的%10 == 0)
{
XYSeries tempSerie = dataset.getSeriesAt(ⅰ);
tempSerie.add(channelsTab [I],50);
tempSerie.addAnnotation(legendTitles.get(ⅰ)+:+ V [k]的,channelsTab [I],50);
}
其他
//series.add(50 - v [k]的%10);
{XYSeries tempSerie = dataset.getSeriesAt(ⅰ);
tempSerie.add(channelsTab [I]中,50 - v [k]的%10);
tempSerie.addAnnotation(legendTitles.get(ⅰ)+:+ V [k]的,channelsTab [I]中,50 - v [k]的%10);
// series.toXYSeries()加(7.5,50 - v [k]的10%)。
}
打破;
案例-6:
//series.add(classObject[k]);
如果(ⅴ[k]的%10 == 0)
//series.add(60);
{XYSeries tempSerie = dataset.getSeriesAt(ⅰ);
tempSerie.add(channelsTab [I],60);
tempSerie.addAnnotation(legendTitles.get(ⅰ)+:+ V [k]的,channelsTab [I],60);
}
其他
//series.add(60 - v [k]的%10);
{XYSeries tempSerie = dataset.getSeriesAt(ⅰ);
tempSerie.add(channelsTab [I]中,60 - v [k]的%10);
tempSerie.addAnnotation(legendTitles.get(ⅰ)+:+ V [k]的,channelsTab [I]中,60 - v [k]的%10);
}
打破;
案例-5:
//series.add(classObject[k]);
如果(ⅴ[k]的%10 == 0)
//series.add(70);
{XYSeries tempSerie = dataset.getSeriesAt(ⅰ);
tempSerie.add(channelsTab [I],70);
tempSerie.addAnnotation(legendTitles.get(ⅰ)+:+ V [k]的,channelsTab [I],70);
}
其他
//series.add(70 - v [k]的%10);
{XYSeries tempSerie = dataset.getSeriesAt(ⅰ);
tempSerie.add(channelsTab [I]中,70 - v [k]的%10);
tempSerie.addAnnotation(legendTitles.get(ⅰ)+:+ V [k]的,channelsTab [I]中,70 - v [k]的%10);
}
打破;
案例-4:
//series.add(classObject[k]);
如果(ⅴ[k]的%10 == 0)
//series.add(80);
{XYSeries tempSerie = dataset.getSeriesAt(ⅰ);
tempSerie.add(channelsTab [I],80);
tempSerie.addAnnotation(legendTitles.get(ⅰ)+:+ V [k]的,channelsTab [I],80);
}
其他
{XYSeries tempSerie = dataset.getSeriesAt(ⅰ);
tempSerie.add(channelsTab [I]中,80 - v [k]的%10);
tempSerie.addAnnotation(legendTitles.get(ⅰ)+:+ V [k]的,channelsTab [I]中,80 - v [k]的%10);
}
打破;
案例-3:
//series.add(classObject[k]);
如果(ⅴ[k]的%10 == 0)
{XYSeries tempSerie = dataset.getSeriesAt(ⅰ);
tempSerie.add(channelsTab [I],90);
tempSerie.addAnnotation(legendTitles.get(ⅰ)+:+ V [k]的,channelsTab [I],90);
}
其他
//series.add(90 - v [k]的%10);
{XYSeries tempSerie = dataset.getSeriesAt(ⅰ);
tempSerie.add(channelsTab [I]中,90 - v [k]的%10);
tempSerie.addAnnotation(legendTitles.get(ⅰ)+:+ V [k]的,channelsTab [I]中,90 - v [k]的%10);
}
打破;
}
}
}
返回的数据集;
}
公共XYMultipleSeriesRenderer getTruitonBarRenderer(INT长度){
XYMultipleSeriesRenderer渲染器=新XYMultipleSeriesRenderer();
renderer.setAxisTitleTextSize(10);
renderer.setChartTitleTextSize(20);
renderer.setLabelsTextSize(10);
renderer.setLegendTextSize(10);
renderer.setMargins(新INT [] {30,40,15,0});
对于(INT K = 0; K<长度; k ++)
{Log.i(SimpleSeriesRendererK +);
SimpleSeriesRenderer R =新SimpleSeriesRenderer();
r.setColor(Color.rgb((int)的(的Math.random()* 255),(int)的(的Math.random()* 255),(INT)的Math.random()* 255));
renderer.addSeriesRenderer(r)的;
}
返回渲染器;
}
@燮pressWarnings(德precation)
私人无效myChartSettings(XYMultipleSeriesRenderer渲染器){
renderer.setChartTitle(无线频道);
renderer.setXAxisMin(-1);
renderer.setXAxisMax(16);
renderer.setYAxisMin(20);
renderer.setYAxisMax(100);
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(20,-100);
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(真实的,真正的);
renderer.setZoomEnabled(真实的,真正的);
renderer.setApplyBackgroundColor(真正的);
renderer.setBackgroundColor(Color.BLACK);
renderer.setYLabelsAlign(Align.RIGHT);
renderer.setBarSpacing(0.5);
renderer.setXTitle(运河上的WiFi);
renderer.setYTitle(Puissance杜信号[DBM]);
renderer.setShowGrid(真正的);
renderer.setGridColor(Color.GRAY);
renderer.setXLabels(0); //设置要显示的整数标签的数量
renderer.setXLabels((int)的0.5); // 25
renderer.setYLabels(10);
renderer.setBarWidth(10); //条宽
renderer.setXLabelsAlign(Align.LEFT);
}
}
嗯,我解决了这个问题,有一个EAL时间图(柱状图),我不得不改变我的寿法的onReceive像bellow.I希望这将有助于一个人。
公共无效的onReceive(上下文的背景下,意图意图){
WifiManager wifiMan =(WifiManager)WifiChartsRealTime.this.getSystemService(Context.WIFI_SERVICE);
wifiMan.startScan();
如果(intent.getAction()。等于(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)){
结果= wifi.getScanResults();
长度= results.size();
Log.i(长度1,长度+);
XYMultipleSeriesRenderer渲染= getTruitonBarRenderer(results.size());
myChartSettings(渲染);
布局=(的LinearLayout)findViewById(R.id.chart);
如果(mChartView!= NULL){
layout.removeView(mChartView);
}
mChartView = ChartFactory.getBarChartView(WifiChartsRealTime.this,getTruitonBarDataset(结果),渲染器,Type.STACKED);
layout.addView(mChartView,0,新的LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
}
}`
I'm trying to display information got from wifi scan with broadcast receiver ,into a bar chart using achartengine. Well i want to have a real time chart ,every time i receive data from onReceive() method ,i update the chart. To achaeive that ,i create the chart objects in the onReceive() method .But i just get a chart with the first result ,there is no update ,although i can see the changes on the wifi scan.I would like to know what is the problem.This is the code that i'm using:
public class WifiChartsRealTime extends Activity {
LinearLayout layout;
List<int[]> values = new ArrayList<int[]>();
//List<ScanResult> classObject = new ArrayList<ScanResult>();
int [ ] [ ] Center_Frequency_2 = { { 1,2,3,4,5,6,7,8,9,10,11,12,13,14 },
{ 2412, 2417, 2422, 2427, 2432,2437,2442,2447,2452 ,2457,2462,2467,2472,2484},
};
WifiManager wifi;
Button enab;
String resultsString ;
String[] myStringArray;
int aa = 10;
public class Receiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
int length ;
if(intent.getAction().equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)){
List<ScanResult> results = wifi.getScanResults();
length=results.size();
Toast.makeText(getApplicationContext(),
"resultsString***************** :"+results , Toast.LENGTH_LONG)
.show();
Toast.makeText(getApplicationContext(),
"length1 :"+length , Toast.LENGTH_LONG)
.show();
Log.i("length1",length +"");
XYMultipleSeriesRenderer renderer = getTruitonBarRenderer(results.size());
myChartSettings(renderer);
/* Intent intent1 = ChartFactory.getBarChartIntent(WifiChartsRealTime.this,getTruitonBarDataset(),renderer,Type.DEFAULT);
startActivity(intent1);*/
GraphicalView mChartView = ChartFactory.getBarChartView(WifiChartsRealTime.this, getTruitonBarDataset( results), renderer, Type.STACKED);
layout.addView(mChartView);
// mChartView.refreshDrawableState();
mChartView.repaint();
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wifi_charts_real_time);
layout = (LinearLayout) findViewById(R.id.chart);
ConnectivityManager cxMgr = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
wifi = (WifiManager)getSystemService(Context.WIFI_SERVICE);
Receiver receiver = new Receiver();
registerReceiver(receiver,new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
registerReceiver(receiver,new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
}
private XYMultipleSeriesDataset getTruitonBarDataset( List<ScanResult> classObject) {
int SERIES_NR ; //the number of columns to display,
ArrayList<String> legendTitles = new ArrayList<String>();
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
Toast.makeText(getApplicationContext(),
"Position XYMultipleSeriesDataset:"+classObject , Toast.LENGTH_LONG)
.show();
Toast.makeText(getApplicationContext(),
"SIZE XYMultipleSeriesDataset:"+classObject.size() , Toast.LENGTH_LONG)
.show();
// length = classObject.size();
for (int j=0;j<classObject.size();j++){
values.add(new int[] { classObject.get(j).level}); //every serie will concern an access point and contain one RSSI
}
for (int k = 0; k < classObject.size(); k++) {
legendTitles.add(classObject.get(k).SSID);//every serie will have a legend the SSID
}
//determination des canaux
int[] channelsTab = new int[classObject.size()];
for(int i=0;i<classObject.size();i++){
if (classObject.get(i).frequency /1000 == 2) {
for (int j =0;j<14;j++)
{ if (Center_Frequency_2[1][j] == classObject.get(i).frequency)
channelsTab[i]= Center_Frequency_2[0][j] ;
}
}
}
//FIN determination des canaux
SERIES_NR = classObject.size() ;//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+"");
/* XYSeries tempSerie = dataset.getSeriesAt(i);
tempSerie.add(i, 40 - v[k] %10);*/
switch (v[k] / 10){
case -9 :
//series.add(classObject[k]);
if (v[k] %10 == 0)
//series.add(40);
{XYSeries tempSerie = dataset.getSeriesAt(i);
tempSerie.add(channelsTab[i], 30);
tempSerie.addAnnotation(legendTitles.get(i)+":"+v[k], channelsTab[i], 30);
}
else
//series.add(40 - v[k] %10);
{XYSeries tempSerie = dataset.getSeriesAt(i);
tempSerie.add(channelsTab[i], 30 - v[k] %10);
tempSerie.addAnnotation(legendTitles.get(i)+":"+v[k] , channelsTab[i], 30 - v[k] %10);
}
break;
case -8 :
//series.add(classObject[k]);
if (v[k] %10 == 0)
//series.add(40);
{XYSeries tempSerie = dataset.getSeriesAt(i);
tempSerie.add(channelsTab[i], 40);
tempSerie.addAnnotation(legendTitles.get(i)+":"+v[k], channelsTab[i], 40);
}
else
//series.add(40 - v[k] %10);
{XYSeries tempSerie = dataset.getSeriesAt(i);
tempSerie.add(channelsTab[i], 40 - v[k] %10);
tempSerie.addAnnotation(legendTitles.get(i)+":"+v[k], channelsTab[i], 40 - v[k] %10);
}
break;
case -7 :
//series.add(classObject[k]);
if (v[k] %10 == 0)
{
XYSeries tempSerie = dataset.getSeriesAt(i);
tempSerie.add(channelsTab[i], 50);
tempSerie.addAnnotation(legendTitles.get(i)+":"+v[k], channelsTab[i], 50);
}
else
//series.add(50 - v[k] %10);
{XYSeries tempSerie = dataset.getSeriesAt(i);
tempSerie.add(channelsTab[i],50 - v[k] %10);
tempSerie.addAnnotation(legendTitles.get(i)+":"+v[k], channelsTab[i], 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(channelsTab[i], 60);
tempSerie.addAnnotation(legendTitles.get(i)+":"+v[k], channelsTab[i], 60);
}
else
//series.add(60 - v[k] %10);
{XYSeries tempSerie = dataset.getSeriesAt(i);
tempSerie.add(channelsTab[i], 60 - v[k] %10);
tempSerie.addAnnotation(legendTitles.get(i)+":"+v[k], channelsTab[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(channelsTab[i], 70);
tempSerie.addAnnotation(legendTitles.get(i)+":"+v[k], channelsTab[i], 70);
}
else
//series.add(70 - v[k] %10);
{XYSeries tempSerie = dataset.getSeriesAt(i);
tempSerie.add(channelsTab[i], 70 - v[k] %10);
tempSerie.addAnnotation(legendTitles.get(i)+":"+v[k], channelsTab[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(channelsTab[i], 80);
tempSerie.addAnnotation(legendTitles.get(i)+":"+v[k], channelsTab[i], 80);
}
else
{XYSeries tempSerie = dataset.getSeriesAt(i);
tempSerie.add(channelsTab[i], 80 - v[k] %10);
tempSerie.addAnnotation(legendTitles.get(i)+":"+v[k], channelsTab[i], 80 - v[k] %10);
}
break;
case -3 :
//series.add(classObject[k]);
if (v[k] %10 == 0)
{XYSeries tempSerie = dataset.getSeriesAt(i);
tempSerie.add(channelsTab[i], 90);
tempSerie.addAnnotation(legendTitles.get(i)+":"+v[k], channelsTab[i], 90);
}
else
//series.add(90 - v[k] %10);
{XYSeries tempSerie = dataset.getSeriesAt(i);
tempSerie.add(channelsTab[i], 90 - v[k] %10);
tempSerie.addAnnotation(legendTitles.get(i)+":"+v[k], channelsTab[i], 90 - v[k] %10);
}
break;
}
}
}
return dataset;
}
public XYMultipleSeriesRenderer getTruitonBarRenderer(int length) {
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
renderer.setAxisTitleTextSize(10);
renderer.setChartTitleTextSize(20);
renderer.setLabelsTextSize(10);
renderer.setLegendTextSize(10);
renderer.setMargins(new int[] { 30, 40, 15, 0 });
for (int k = 0; k < length; k++)
{ Log.i("SimpleSeriesRenderer" ,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(16);
renderer.setYAxisMin(20);
renderer.setYAxisMax(100);
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(20, "-100");
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
renderer.setXLabelsAlign(Align.LEFT);
}
}
Well i resolved this problem ,to have a eal time chart (bar chart ) ,i have to change tho my onReceive method like bellow.I hope it will help someone.
public void onReceive(Context context, Intent intent) {
WifiManager wifiMan=(WifiManager)WifiChartsRealTime.this.getSystemService(Context.WIFI_SERVICE);
wifiMan.startScan();
if(intent.getAction().equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)){
results = wifi.getScanResults();
length=results.size();
Log.i("length1",length +"");
XYMultipleSeriesRenderer renderer = getTruitonBarRenderer(results.size());
myChartSettings(renderer);
layout = (LinearLayout) findViewById(R.id.chart);
if (mChartView != null) {
layout.removeView(mChartView);
}
mChartView = ChartFactory.getBarChartView(WifiChartsRealTime.this, getTruitonBarDataset( results), renderer, Type.STACKED);
layout.addView(mChartView, 0, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
}
}`
这篇关于安卓:BroadcastReceiver的使用Achartengine,不显示更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!