Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/svn/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android SimpleGraph的标签和自动x轴滚动问题_Android_Android Graphview - Fatal编程技术网

Android SimpleGraph的标签和自动x轴滚动问题

Android SimpleGraph的标签和自动x轴滚动问题,android,android-graphview,Android,Android Graphview,我正在开发一个Android应用程序,我有一个传感器读数图:温度/湿度/风绘制在Y轴上,然后时间/日期绘制在X轴上。我在用电脑。在大多数情况下,一切都很好。然而,有2-3个问题我被卡住了 如果我为标签指定一个数字,比如我的主屏幕为3,它不会滚动到最后,或者最好是哪一个,它不会只显示3个标签和指定时间内的所有数据。相反,它显示前三个标签并剪切数据。如果我尝试graph.getViewport().scrollToEnd()没有任何变化 在我的“FullGraphActivity”中,我仍然缺少最后

我正在开发一个Android应用程序,我有一个传感器读数图:温度/湿度/风绘制在Y轴上,然后时间/日期绘制在X轴上。我在用电脑。在大多数情况下,一切都很好。然而,有2-3个问题我被卡住了

  • 如果我为标签指定一个数字,比如我的主屏幕为3,它不会滚动到最后,或者最好是哪一个,它不会只显示3个标签和指定时间内的所有数据。相反,它显示前三个标签并剪切数据。如果我尝试
    graph.getViewport().scrollToEnd()没有任何变化
    
  • 在我的“FullGraphActivity”中,我仍然缺少最后几个小时的数据……有时。其他时候,它会表现出来
  • 所以我知道我得到了正确的数据点,因为我的日志显示了它们。我敢肯定,他们被策划在视线之外。我真正想知道的是如何根据我的时间选择正确绘制数据和标签。例如天/周/月。我已经包括了两个主要类,以及一个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;
    }
    }
    

    希望这不是太多的信息。再次感谢您的评论

    好的,所以像往常一样,在决定发布后,我能够借助simplegraphs文档上的示例制定出一个解决方案。我以为我从文档中镜像了日期示例,但我遗漏了一个关键部分:

    // set manual x bounds to have nice steps
    graph.getViewport().setMinX(start);
    graph.getViewport().setMaxX(System.currentTimeMillis());
    graph.getViewport().setXAxisBoundsManual(true);
    
    由于某些原因,尽管使用了API中提供的清除/重置,但我无法正确清除每个图形样式/数据。与其在上面浪费太多时间,我决定在布局中创建三个GraphView,然后隐藏未使用的GraphView。这不是最好的方法,但似乎不会影响性能。请参阅下面的代码更改。注意:由于样式原因,进行了一些更改

    我更改了grapher方法,以包括双开始,即开始时间:

    类的可图性

    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());
    
        }
    }
    
    如果我找到了一个解决多视图问题的方法,我会编辑这篇文章,以防将来对别人有用

    最好的, 詹姆斯

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