gpt4 book ai didi

安卓 :Wifi analyzer bar chart

转载 作者:行者123 更新时间:2023-11-30 02:57:55 24 4
gpt4 key购买 nike

我正在尝试获得与图片中相同的图表:

enter image description here

好吧,我有一个负数列表 {-50,-70,-40...},我想要相同的图表,但如果我正常工作,我会得到这张向上的图表:

enter image description here

我试着用标签代替 y 轴数字,但我没有给我想要的图表。请有人告诉我如何制作这张图表,我花了 4 天时间试图在第一张图片中得到结果。或者给我一个想法,我已经失去了 4 天的搜索和尝试:(。这是我正在使用的代码:

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。

最佳答案

好吧,我找到了一个解决方案,我确定它不是最好的,但总比什么都没有好:

Y 轴将从 30 到 90(实数)开始,我将设置标签而不是像这样的实数:

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

PS:我确定我的 Y 坐标会在 -90 到 -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);
}
}

关于安卓 :Wifi analyzer bar chart,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22981828/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com