我正在使用Android应用程序,并且有一个传感器读数图:在Y轴上绘制了温度/湿度/风,然后在X轴上绘制了时间/日期。我正在使用SimpleGraph library。在大多数情况下,一切都很好。但是,我遇到了2-3个问题。
graph.getViewport().scrollToEnd();
,则没有任何变化。 所以我知道我得到了正确的数据点,因为我的日志显示了它们。我很确定它们不会被视线绘制出来。我真正想要的是弄清楚如何根据时间选择正确获取数据和标签。例如日/周/月。我已经包括了两个主要的类,以及一个针对3标签调用的示例调用。
我可能缺少一些简单的东西。感谢任何建议,评论。
谢谢!
从主屏幕调用并指定标签计数:
graphTemp = (GraphView) findViewById(R.id.graphTemp);
try {
GraphUtility gu = new GraphUtility(1,1,3,true,false, this,celsius);
gu.grapher( this,graphTemp, gu.seriesBuilder(
gu.getTempData(gu.getSixHours())));
这是我要设置简单图形的地方:
public class GraphUtility {
public int focus;
public Activity activity;
public MainActivity mainActivity;
public Context context;
Constants constants;
private final static int graphColor
Color.parseColor("#6a0c05");
private double maxYBound = 0;
private double minYBound = 999;
private int time = 0;
private int labelCount = 0;
private boolean maxy = true;
private boolean miny = true;
private boolean celsius;
public GraphUtility(int focus, int time, int labelCount,boolean maxy, boolean miny, MainActivity mainActivity, boolean celsius) {
this.focus = focus;
this.time = time;
this.labelCount = labelCount;
context = mainActivity;
this.mainActivity = mainActivity;
this.miny = miny;
this.maxy = maxy;
this.celsius = celsius;
}
public void grapher(Context context, GraphView graph, LineGraphSeries[] seriesArray){
try{
graph.removeAllSeries();
LineGraphSeries series = new LineGraphSeries();
series.clearReference(graph);
if(focus==0){
for(int i = 0; i<seriesArray.length; i++){
// series = new LineGraphSeries();
series = seriesArray[i];
series.setDrawBackground(true);
if(i == 0) {
series.setColor(Color.parseColor("#8d1007"));
series.setBackgroundColor(Color.parseColor("#8d1007"));
}
if(i == 1) {
series.setColor(Color.parseColor("#551a8b"));
series.setBackgroundColor(Color.parseColor("#551a8b"));
}
if(i == 2) {
series.setColor(Color.parseColor("#FF0008F0"));
series.setBackgroundColor(Color.parseColor("#FF0008F0"));
}
series.setDataPointsRadius(2);
series.setThickness(2);
graph.addSeries(series);
}
}
if(focus == 1){
series = seriesArray[0];
series.setDrawBackground(true);
series.setColor(Color.parseColor("#8d1007"));
series.setBackgroundColor(Color.parseColor("#8d1007"));
}
if(focus == 2){
series = seriesArray[1];
series.setDrawBackground(true);
series.setColor(Color.parseColor("#8d1007"));
series.setBackgroundColor(Color.parseColor("#8d1007"));
}
if(focus == 3){
series = seriesArray[2];
series.setDrawBackground(true);
series.setColor(Color.parseColor("#8d1007"));
series.setBackgroundColor(Color.parseColor("#8d1007"));
}
series.setDataPointsRadius(2);
series.setThickness(2);
graph.addSeries(series);
//graph.addSeries(series);
graph.getGridLabelRenderer().setGridColor(graphColor);
graph.getGridLabelRenderer().setHorizontalLabelsColor(graphColor);
graph.getGridLabelRenderer().setVerticalLabelsColor(graphColor);
graph.getGridLabelRenderer().setGridStyle(GridLabelRenderer.GridStyle.BOTH);
graph.getViewport().scrollToEnd();
//Add 5 percent for easier readability
if(maxy) {
graph.getViewport().setYAxisBoundsManual(true);
maxYBound = maxYBound + (maxYBound* .05);
maxYBound= 5*(Math.ceil(Math.abs(maxYBound/5)));
if(maxYBound ==0){
maxYBound=1;
}
graph.getViewport().setMaxY(maxYBound);
}
//Minus 5 percent
if(minYBound !=0) {
if(miny) {
graph.getViewport().setYAxisBoundsManual(true);
minYBound = minYBound - (minYBound * .05);
minYBound= 5*(Math.floor(Math.abs(minYBound/5)));
Log.d("BTWeather-minYval", String.valueOf(minYBound));
//TODO Empty sensors causes crash.
graph.getViewport().setMinY(minYBound);
}
}
if(labelCount > 0){
graph.getGridLabelRenderer().setNumHorizontalLabels(labelCount);
}
graph.getGridLabelRenderer().setHumanRounding(true);
// graph.getGridLabelRenderer().setTextSize(35);
graph.getGridLabelRenderer().reloadStyles();
java.text.DateFormat dateTimeFormatter = DateFormat.getTimeFormat(context);
if(time==1) {
graph.getGridLabelRenderer().setLabelFormatter(
new DateAsXAxisLabelFormatter(graph.getContext(),
dateTimeFormatter));
}else{
graph.getGridLabelRenderer().setLabelFormatter(
new DateAsXAxisLabelFormatter(graph.getContext()));
}
//
}catch(Exception e){
Log.d("BTWeather-error21", e.toString());
}
}
// TODO Graphs not advancing again showing hours behind instead of latest sensor
public LineGraphSeries[] seriesBuilder(List<Sensors> sensorsList){
LineGraphSeries[] seriesArray = new LineGraphSeries[3];
try{
DataPoint d = null;
DataPoint[] dataPoints = new DataPoint[sensorsList.size()];
DataPoint[] dataPointsH = new DataPoint[sensorsList.size()];
DataPoint[] dataPointsW = new DataPoint[sensorsList.size()];
Date date1 = new Date();
int i = 0;
Log.d("BTWeather-seriesbuilder",
" Length of sensorlist: " + String.valueOf(sensorsList.size()));
if(sensorsList.size()==0){
minYBound = 0;
}
try{
for(Sensors sensor: sensorsList){
findMaxY(sensor);
findMinY(sensor);
try {
date1 = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss").parse(sensor.getmDate());
//Log.d("BTWeather-sensorlistFG",
// String.valueOf(date1)+" - " + String.valueOf(sensor.getmTemp()) );
} catch (ParseException e) {
e.printStackTrace();
}
if( isCelsius()){
d = new DataPoint(date1, Double.valueOf(sensor.getmTemp()));
}else{
double tmp = mainActivity.cToF(Double.valueOf(sensor.getmTemp()));
// Log.d("BTWeather-seriesdump",String.valueOf(tmp));
d = new DataPoint(date1, tmp);
}
dataPoints[i]= d;
d = new DataPoint(date1, Double.valueOf(sensor.getmHumidity()));
dataPointsH[i]=d;
d = new DataPoint(date1, Double.valueOf(sensor.getmWind()));
dataPointsW[i]=d;
i++;
}
seriesArray[0] = new LineGraphSeries<>(dataPoints);
seriesArray[1] = new LineGraphSeries<>(dataPointsH);
seriesArray[2] = new LineGraphSeries<>(dataPointsW);
}catch(Exception e){
Log.d("BTWeather-error20", e.toString());
}
}catch (Exception e){
Log.d("BTWeather-error22", e.toString());
}
return seriesArray;
}
//TODO min / max not resetting propperly for days/weeks etc
public void findMaxY (Sensors sensor){
try{
//Focus passed from main activity on graph click
if(focus ==1){
if( isCelsius()) {
if (Double.valueOf(sensor.getmTemp()) > maxYBound) {
maxYBound = Double.valueOf(sensor.getmTemp());
}
}else if(mainActivity.cToF(Double.valueOf(sensor.getmTemp()))>maxYBound){
maxYBound=mainActivity.cToF(Double.valueOf(sensor.getmTemp()));
}
}
else if(focus == 2){
if( Double.valueOf(sensor.getmHumidity())> maxYBound){
maxYBound = Double.valueOf(sensor.getmHumidity());
}
}
else if(focus == 3){
if(Double.valueOf(sensor.getmWind())> maxYBound){
maxYBound = Double.valueOf(sensor.getmWind());
}
}}
catch (Exception e){
Log.d("BTWeather-error19", e.toString());
}
}
public void findMinY (Sensors sensor){
if(sensor != null) {
try {
//Focus passed from main activity on graph click
if (focus == 1) {
if (isCelsius()) {
if (Double.valueOf(sensor.getmTemp()) < minYBound) {
minYBound = Double.valueOf(sensor.getmTemp());
}
} else if (mainActivity.cToF(Double.valueOf(sensor.getmTemp())) < minYBound) {
minYBound = mainActivity.cToF(Double.valueOf(sensor.getmTemp()));
}
} else if (focus == 2) {
if (Double.valueOf(sensor.getmHumidity()) < minYBound) {
minYBound = Double.valueOf(sensor.getmHumidity());
}
} else if (focus == 3) {
if (Double.valueOf(sensor.getmWind()) < minYBound) {
minYBound = Double.valueOf(sensor.getmWind());
}
}
} catch (Exception e) {
Log.d("BTWeather-error18", e.toString());
}
}else{
minYBound=0;
}
}
//Database
public static String getYesterday(){
//return new Date(System.currentTimeMillis()-24*60*60*1000);
long day = TimeUnit.DAYS.toMillis(1);
String start= DateFormat.format("MM-dd-yyyy HH:mm:ss",
new Date(System.currentTimeMillis() - day)).toString();
return start;
}
public static String getSixHours(){
//return new Date(System.currentTimeMillis()-24*60*60*1000);
long day = TimeUnit.HOURS.toMillis(6);
String start= DateFormat.format("MM-dd-yyyy HH:mm:ss",
new Date(System.currentTimeMillis() - day)).toString();
return start;
}
public static String getWeek(){
//return new Date(System.currentTimeMillis()-24*60*60*1000);
long week = TimeUnit.DAYS.toMillis(7);
String start= DateFormat.format("MM-dd-yyyy HH:mm:ss",
new Date(System.currentTimeMillis() - week)).toString();
return start;
}
public static String getMonth(){
//return new Date(System.currentTimeMillis()-24*60*60*1000);
long month = TimeUnit.DAYS.toMillis(30);
String start= DateFormat.format("MM-dd-yyyy HH:mm:ss",
new Date(System.currentTimeMillis() - month)).toString();
return start;
}
public static Date getMeTomorrow(){
return new Date(System.currentTimeMillis());
}
public List<Sensors> getTempData(String start){
SensorsDatabase sDb = SensorsDatabase.getSensorsDatabase(context);
List<Sensors> dataPoints = null;
Date date1 = new Date();
try {
dataPoints = sDb.sensorsDao().findTempByDate(
start,
DateFormat.format("MM-dd-yyyy HH:mm:ss", getMeTomorrow()).toString());
} catch (Exception e) {
Log.d("BTWeather-error8", String.valueOf(e));
}
return dataPoints;
}
public boolean isCelsius() {
return celsius;
}
}
此活动是图形的完整视图。在这里主要是工作。但是,如上所述,有时最后几个小时的数据会被切断。说2:30,我会看到直到12:30的数据和标签
public class FullGraphActivity extends AppCompatActivity {
GraphView graph;
private TextView mTextMessage;
private final static int graphColor = Color.parseColor("#6a0c05");
private MainActivity mainActivity;
private int focus =0;
private int time = 0;
GraphUtility gu;
private boolean celsius;
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.graph_hour:
time=1;
if(focus ==1 )
mTextMessage.setText(R.string.graph_hour_temp);
if(focus ==2 )
mTextMessage.setText(R.string.graph_hour_humid);
if(focus ==3 )
mTextMessage.setText(R.string.graph_hour_wind);
try{
gu = new GraphUtility(focus,time,0,true,true,mainActivity,celsius);
gu.grapher(getApplicationContext(),graph,gu.seriesBuilder(gu.getTempData(gu.getYesterday())));
}catch(Exception e){
Log.d("BTWeather-error15", e.toString());
}
return true;
case R.id.graph_day:
time=2;
if(focus ==1 )
mTextMessage.setText(R.string.graph_day_temp);
if(focus ==2 )
mTextMessage.setText(R.string.graph_day_humid);
if(focus ==3 )
mTextMessage.setText(R.string.graph_day_wind);
try{
gu = new GraphUtility(focus,time,0,true,true,mainActivity,celsius );
gu.grapher(getApplicationContext(),graph,gu.seriesBuilder(gu.getTempData(gu.getWeek())));
}catch(Exception e){
Log.d("BTWeather-error15", e.toString());
}
return true;
case R.id.graph_week:
time=3;
if(focus ==1 )
mTextMessage.setText(R.string.graph_week_temp);
if(focus ==2 )
mTextMessage.setText(R.string.graph_week_humid);
if(focus ==3 )
mTextMessage.setText(R.string.graph_week_wind);
try{
gu = new GraphUtility(focus,time,0,true,true,mainActivity,celsius );
gu.grapher(getApplicationContext(),graph,gu.seriesBuilder(gu.getTempData(gu.getMonth())));
}catch(Exception e){
Log.d("BTWeather-error15", e.toString());
}
return true;
}
return false;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_full_graph);
Intent mIntent = getIntent();
focus = mIntent.getIntExtra("focus", 0);
celsius = mIntent.getBooleanExtra("celsius", false);
mTextMessage = (TextView) findViewById(R.id.message);
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.graphMenu);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
mainActivity = new MainActivity() ;
graph = (GraphView) findViewById(R.id.fullGraph);
// Setting the very 1st item as home screen.
navigation.setSelectedItemId(R.id.graph_hour);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home){
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
}
希望这不是太多信息。再次感谢任何评论。 Full code repo if it helps.
答案 0 :(得分:0)
好吧,像往常一样,在决定发布之后,我能够借助simplegraphs doc上的示例来制定解决方案。我以为我从文档中镜像了日期示例,但是我省略了一个关键部分:
// set manual x bounds to have nice steps
graph.getViewport().setMinX(start);
graph.getViewport().setMaxX(System.currentTimeMillis());
graph.getViewport().setXAxisBoundsManual(true);
由于某种原因,尽管使用了API中提供的清除/重置功能,但我仍无法正确清除每个图形的样式/数据。为了避免浪费太多的时间,我决定在布局中创建三个graphview,然后隐藏不使用的graphview。这不是最佳方法,但似乎不会影响性能。有关代码更改,请参见下文。请注意,出于风格原因进行了一些更改。
我将我的绘图器方法更改为包括双开始,这是从此处开始的时间:
Class GraphUtility
public void grapher(Context context, GraphView graph, LineGraphSeries[] seriesArray, Double start){
try{
graph.removeAllSeries();
graph.getGridLabelRenderer().resetStyles();
LineGraphSeries series = new LineGraphSeries();
series.clearReference(graph);
if(focus==0) {
for (int i = 0; i < seriesArray.length; i++) {
// series = new LineGraphSeries();
series = seriesArray[i];
series.setDrawBackground(true);
if (i == 0) {
series.setColor(Color.parseColor("#8d1007"));
series.setBackgroundColor(Color.parseColor("#4D6a0c05"));
}
if (i == 1) {
series.setColor(Color.parseColor("#00004C"));
series.setBackgroundColor(Color.parseColor("#4D00004C"));
}
if (i == 2) {
series.setColor(Color.parseColor("#006600"));
series.setBackgroundColor(Color.parseColor("#4D006600"));
}
series.setDataPointsRadius(4);
series.setThickness(4);
graph.getGridLabelRenderer().setGridColor(graphColor);
graph.getGridLabelRenderer().setHorizontalLabelsColor(graphColor);
graph.getGridLabelRenderer().setVerticalLabelsColor(graphColor);
graph.addSeries(series);
}
}
if(focus == 1){
series = seriesArray[0];
series.setDrawBackground(true);
series.setColor(Color.parseColor("#8d1007"));
series.setBackgroundColor(Color.parseColor("#4D6a0c05"));
graph.getGridLabelRenderer().setGridColor(Color.parseColor("#8d1007"));
graph.getGridLabelRenderer().setHorizontalLabelsColor(Color.parseColor("#8d1007"));
graph.getGridLabelRenderer().setVerticalLabelsColor(Color.parseColor("#8d1007"));
series.setDataPointsRadius(2);
series.setThickness(2);
graph.addSeries(series);
}
if(focus == 2){
series = seriesArray[1];
series.setDrawBackground(true);
series.setColor(Color.parseColor("#00004C"));
series.setBackgroundColor(Color.parseColor("#4D00004C"));
graph.getGridLabelRenderer().setGridColor(Color.parseColor("#00004C"));
graph.getGridLabelRenderer().setHorizontalLabelsColor(Color.parseColor("#00004C"));
graph.getGridLabelRenderer().setVerticalLabelsColor(Color.parseColor("#00004C"));
series.setDataPointsRadius(2);
series.setThickness(2);
graph.addSeries(series);
}
if(focus == 3){
series = seriesArray[2];
series.setDrawBackground(true);
series.setColor(Color.parseColor("#006600"));
series.setBackgroundColor(Color.parseColor("#4D006600"));
graph.getGridLabelRenderer().setGridColor(Color.parseColor("#006600"));
graph.getGridLabelRenderer().setHorizontalLabelsColor(Color.parseColor("#006600"));
graph.getGridLabelRenderer().setVerticalLabelsColor(Color.parseColor("#006600"));
series.setDataPointsRadius(2);
series.setThickness(2);
graph.addSeries(series);
}
graph.getGridLabelRenderer().setGridStyle(GridLabelRenderer.GridStyle.BOTH);
//Add 5 percent for easier readability
Log.d(Constants.LOG_TAG,"MaxY" + String.valueOf(maxYBound));
if(maxy) {
graph.getViewport().setYAxisBoundsManual(true);
maxYBound = maxYBound + (maxYBound* .05);
maxYBound= 5*(Math.ceil(Math.abs(maxYBound/5)));
if(maxYBound ==0){
maxYBound=1;
}
graph.getViewport().setMaxY(maxYBound);
}
//Minus 5 percent
Log.d(Constants.LOG_TAG,"MinY" + String.valueOf(minYBound));
if(minYBound !=0) {
if(miny) {
graph.getViewport().setYAxisBoundsManual(true);
minYBound = minYBound - (minYBound * .05);
minYBound= 5*(Math.floor(Math.abs(minYBound/5)));
Log.d("BTWeather-minYval", String.valueOf(minYBound));
graph.getViewport().setMinY(minYBound);
}
}else{
graph.getViewport().setMinY(minYBound);
}
if(labelCount > 0){
graph.getGridLabelRenderer().setNumHorizontalLabels(labelCount);
}
if(time==1) {
java.text.DateFormat dateTimeFormatter = DateFormat.getTimeFormat(context);
graph.getGridLabelRenderer().setLabelFormatter(
new DateAsXAxisLabelFormatter(graph.getContext(),
dateTimeFormatter));
}else{
graph.getGridLabelRenderer().setLabelFormatter(new DateAsXAxisLabelFormatter(context));
}
//graph.getGridLabelRenderer().setNumHorizontalLabels(labelCount); // only 4 because of the space
// set manual x bounds to have nice steps
graph.getViewport().setMinX(start);
graph.getViewport().setMaxX(System.currentTimeMillis());
graph.getViewport().setXAxisBoundsManual(true);
// as we use dates as labels, the human rounding to nice readable numbers
// is not necessary
graph.getGridLabelRenderer().setHumanRounding(false);
//graph.getGridLabelRenderer().reloadStyles();
}catch(Exception e){
Log.d("BTWeather-error21", e.toString());
}
}
FullGraphActivity类:仅需要更改才能用于绘图器调用以及根据时间调用隐藏/显示正确的视图。
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.graph_hour:
time=1;
if(focus==0) {
getSupportActionBar().setTitle(R.string.AllHourly);
try {
GraphView graph2;
graph2 = (GraphView) findViewById(R.id.fullGraph2);
graph2.setVisibility(View.INVISIBLE);
graph2 = (GraphView) findViewById(R.id.fullGraph3);
graph2.setVisibility(View.INVISIBLE);
GraphView graph;
graph = (GraphView) findViewById(R.id.fullGraph);
graph.setVisibility(View.VISIBLE);
gu = new GraphUtility(focus, time, 6, true, true, mainActivity, celsius);
gu.grapher(getApplicationContext(), graph, gu.seriesBuilder(gu.getTempData(gu.getYesterday())),gu.getYesterdayDouble());
} catch (Exception e) {
Log.d("BTWeather-error15", e.toString());
}
}else {
if (focus == 1)
getSupportActionBar().setTitle(R.string.graph_hour_temp);
if (focus == 2)
getSupportActionBar().setTitle(R.string.graph_hour_humid);
if (focus == 3)
getSupportActionBar().setTitle(R.string.graph_hour_wind);
try {
GraphView graph2;
graph2 = (GraphView) findViewById(R.id.fullGraph2);
graph2.setVisibility(View.INVISIBLE);
graph2 = (GraphView) findViewById(R.id.fullGraph3);
graph2.setVisibility(View.INVISIBLE);
GraphView graph;
graph = (GraphView) findViewById(R.id.fullGraph);
graph.setVisibility(View.VISIBLE);
graph.getGridLabelRenderer().resetStyles();
graph.removeAllSeries();
gu = new GraphUtility(focus, time, 6, true, true, mainActivity, celsius);
gu.grapher(getApplicationContext(), graph, gu.seriesBuilder(gu.getTempData(gu.getYesterday())),gu.getYesterdayDouble());
} catch (Exception e) {
Log.d("BTWeather-error15", e.toString());
}
}
return true;
case R.id.graph_day:
time=2;
if(focus==0){
getSupportActionBar().setTitle(R.string.AllDaily);
try {
GraphView graph2;
graph2 = (GraphView) findViewById(R.id.fullGraph);
graph2.setVisibility(View.INVISIBLE);
graph2 = (GraphView) findViewById(R.id.fullGraph3);
graph2.setVisibility(View.INVISIBLE);
GraphView graph;
graph = (GraphView) findViewById(R.id.fullGraph2);
graph.setVisibility(View.VISIBLE);
graph.getGridLabelRenderer().resetStyles();
graph.removeAllSeries();
gu = new GraphUtility(focus, time, 7, true, true, mainActivity, celsius);
gu.grapher(getApplicationContext(), graph, gu.seriesBuilder(gu.getTempData(gu.getWeek())),gu.getWeekDouble());
} catch (Exception e) {
Log.d("BTWeather-error15", e.toString());
}
}else {
if (focus == 1)
getSupportActionBar().setTitle(R.string.graph_day_temp);
if (focus == 2)
getSupportActionBar().setTitle(R.string.graph_day_humid);
if (focus == 3)
getSupportActionBar().setTitle(R.string.graph_day_wind);
try {
GraphView graph2;
graph2 = (GraphView) findViewById(R.id.fullGraph);
graph2.setVisibility(View.INVISIBLE);
graph2 = (GraphView) findViewById(R.id.fullGraph3);
graph2.setVisibility(View.INVISIBLE);
GraphView graph;
graph = (GraphView) findViewById(R.id.fullGraph2);
graph.setVisibility(View.VISIBLE);
graph.getGridLabelRenderer().resetStyles();
graph.removeAllSeries();
gu = new GraphUtility(focus, time, 7, true, true, mainActivity, celsius);
gu.grapher(getApplicationContext(), graph, gu.seriesBuilder(gu.getTempData(gu.getWeek())),gu.getWeekDouble());
} catch (Exception e) {
Log.d("BTWeather-error15", e.toString());
}
}
return true;
case R.id.graph_week:
time=3;
if(focus==0){
getSupportActionBar().setTitle(R.string.AllWeekly);
try {
GraphView graph2;
graph2 = (GraphView) findViewById(R.id.fullGraph);
graph2.setVisibility(View.INVISIBLE);
graph2 = (GraphView) findViewById(R.id.fullGraph2);
graph2.setVisibility(View.INVISIBLE);
GraphView graph;
graph = (GraphView) findViewById(R.id.fullGraph3);
graph.setVisibility(View.VISIBLE);
graph.getGridLabelRenderer().resetStyles();
graph.removeAllSeries();
gu = new GraphUtility(focus, time, 8, false, false, mainActivity, celsius);
gu.grapher(getApplicationContext(), graph, gu.seriesBuilder(gu.getTempData(gu.getMonth())),gu.getMonthDouble());
} catch (Exception e) {
Log.d("BTWeather-error15", e.toString());
}
}else {
if (focus == 1)
getSupportActionBar().setTitle(R.string.graph_week_temp);
if (focus == 2)
getSupportActionBar().setTitle(R.string.graph_week_humid);
if (focus == 3)
getSupportActionBar().setTitle(R.string.graph_week_wind);
try {
GraphView graph2;
graph2 = (GraphView) findViewById(R.id.fullGraph);
graph2.setVisibility(View.INVISIBLE);
graph2 = (GraphView) findViewById(R.id.fullGraph2);
graph2.setVisibility(View.INVISIBLE);
GraphView graph;
graph = (GraphView) findViewById(R.id.fullGraph3);
graph.getGridLabelRenderer().resetStyles();
graph.removeAllSeries();
graph.setVisibility(View.VISIBLE);
gu = new GraphUtility(focus, time, 8, true, true, mainActivity, celsius);
gu.grapher(getApplicationContext(), graph, gu.seriesBuilder(gu.getTempData(gu.getMonth())),gu.getMonthDouble());
} catch (Exception e) {
Log.d("BTWeather-error15", e.toString());
}
}
return true;
}
return false;
}
};
如果我找到了针对多种视图的解决方案,那么我会对此文章进行编辑,以防将来对某人有用。
最好, 詹姆斯