Java Code Examples for lecho.lib.hellocharts.view.LineChartView#setLineChartData()
The following examples show how to use
lecho.lib.hellocharts.view.LineChartView#setLineChartData() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BGHistory.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
private void setupCharts() { dateButton1.setText(dateFormatter.format(date1.getTime())); Calendar endDate = (GregorianCalendar) date1.clone(); endDate.add(Calendar.DATE, noDays); int numValues = noDays * (60 / 2) * 24; // LimiTTer sample rate 1 per 2 minutes BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(this, date1.getTimeInMillis(), endDate.getTimeInMillis(), numValues, false); chart = (LineChartView) findViewById(R.id.chart); chart.setZoomType(ZoomType.HORIZONTAL); previewChart = (PreviewLineChartView) findViewById(R.id.chart_preview); previewChart.setZoomType(ZoomType.HORIZONTAL); chart.setLineChartData(bgGraphBuilder.lineData()); chart.setOnValueTouchListener(bgGraphBuilder.getOnValueSelectTooltipListener(this)); previewChart.setLineChartData(bgGraphBuilder.previewLineData(chart.getLineChartData())); previewChart.setViewportCalculationEnabled(true); chart.setViewportCalculationEnabled(true); previewChart.setViewportChangeListener(new ViewportListener()); chart.setViewportChangeListener(new ChartViewPortListener()); setupStatistics(date1.getTimeInMillis(), endDate.getTimeInMillis()); }
Example 2
Source File: PreviewLineChartActivity.java From hellocharts-android with Apache License 2.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { setHasOptionsMenu(true); View rootView = inflater.inflate(R.layout.fragment_preview_line_chart, container, false); chart = (LineChartView) rootView.findViewById(R.id.chart); previewChart = (PreviewLineChartView) rootView.findViewById(R.id.chart_preview); // Generate data for previewed chart and copy of that data for preview chart. generateDefaultData(); chart.setLineChartData(data); // Disable zoom/scroll for previewed chart, visible chart ranges depends on preview chart viewport so // zoom/scroll is unnecessary. chart.setZoomEnabled(false); chart.setScrollEnabled(false); previewChart.setLineChartData(previewData); previewChart.setViewportChangeListener(new ViewportListener()); previewX(false); return rootView; }
Example 3
Source File: GoodBadChartActivity.java From hellocharts-android with Apache License 2.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_good_bad, container, false); chart = (LineChartView) rootView.findViewById(R.id.chart); generateDefaultData(); chart.setLineChartData(data); // Increase viewport height for better look Viewport v = chart.getMaximumViewport(); float dy = v.height() * 0.2f; v.inset(0, -dy); chart.setMaximumViewport(v); chart.setCurrentViewport(v); return rootView; }
Example 4
Source File: Home.java From xDrip with GNU General Public License v3.0 | 6 votes |
public void setupCharts() { bgGraphBuilder = new BgGraphBuilder(this); updateStuff = false; chart = (LineChartView) findViewById(R.id.chart); chart.setZoomType(ZoomType.HORIZONTAL); previewChart = (PreviewLineChartView) findViewById(R.id.chart_preview); previewChart.setZoomType(ZoomType.HORIZONTAL); chart.setLineChartData(bgGraphBuilder.lineData()); previewChart.setLineChartData(bgGraphBuilder.previewLineData()); updateStuff = true; previewChart.setViewportCalculationEnabled(true); chart.setViewportCalculationEnabled(true); previewChart.setViewportChangeListener(new ViewportListener()); chart.setViewportChangeListener(new ChartViewPortListener()); setViewport(); }
Example 5
Source File: Home.java From NightWatch with GNU General Public License v3.0 | 6 votes |
public void setupCharts() { bgGraphBuilder = new BgGraphBuilder(this); updateStuff = false; chart = (LineChartView) findViewById(R.id.chart); chart.setZoomType(ZoomType.HORIZONTAL); previewChart = (PreviewLineChartView) findViewById(R.id.chart_preview); previewChart.setZoomType(ZoomType.HORIZONTAL); chart.setLineChartData(bgGraphBuilder.lineData()); previewChart.setLineChartData(bgGraphBuilder.previewLineData()); updateStuff = true; previewChart.setViewportCalculationEnabled(true); chart.setViewportCalculationEnabled(true); previewChart.setViewportChangeListener(new ViewportListener()); chart.setViewportChangeListener(new ChartViewPortListener()); setViewport(); }
Example 6
Source File: Home.java From NightWatch with GNU General Public License v3.0 | 6 votes |
public void setupCharts() { bgGraphBuilder = new BgGraphBuilder(this); updateStuff = false; chart = (LineChartView) findViewById(R.id.chart); chart.setZoomType(ZoomType.HORIZONTAL); previewChart = (PreviewLineChartView) findViewById(R.id.chart_preview); previewChart.setZoomType(ZoomType.HORIZONTAL); chart.setLineChartData(bgGraphBuilder.lineData()); previewChart.setLineChartData(bgGraphBuilder.previewLineData()); updateStuff = true; previewChart.setViewportCalculationEnabled(true); chart.setViewportCalculationEnabled(true); previewChart.setViewportChangeListener(new ViewportListener()); chart.setViewportChangeListener(new ChartViewPortListener()); setViewport(); }
Example 7
Source File: BGHistory.java From xDrip-Experimental with GNU General Public License v3.0 | 6 votes |
private void setupCharts() { dateButton1.setText(dateFormatter.format(date1.getTime())); Calendar endDate = (GregorianCalendar) date1.clone(); endDate.add(Calendar.DATE, noDays); int numValues = noDays * (60 / 5) * 24; BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(this, date1.getTimeInMillis(), endDate.getTimeInMillis(), numValues); chart = (LineChartView) findViewById(R.id.chart); chart.setZoomType(ZoomType.HORIZONTAL); previewChart = (PreviewLineChartView) findViewById(R.id.chart_preview); previewChart.setZoomType(ZoomType.HORIZONTAL); chart.setLineChartData(bgGraphBuilder.lineData()); chart.setOnValueTouchListener(bgGraphBuilder.getOnValueSelectTooltipListener()); previewChart.setLineChartData(bgGraphBuilder.previewLineData()); previewChart.setViewportCalculationEnabled(true); chart.setViewportCalculationEnabled(true); previewChart.setViewportChangeListener(new ViewportListener()); chart.setViewportChangeListener(new ChartViewPortListener()); }
Example 8
Source File: BGHistory.java From xDrip with GNU General Public License v3.0 | 6 votes |
private void setupCharts() { dateButton1.setText(dateFormatter.format(date1.getTime())); Calendar endDate = (GregorianCalendar) date1.clone(); endDate.add(Calendar.DATE, noDays); int numValues = noDays * (60 / 2) * 24; // LimiTTer sample rate 1 per 2 minutes BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(this, date1.getTimeInMillis(), endDate.getTimeInMillis(), numValues, false); chart = (LineChartView) findViewById(R.id.chart); chart.setZoomType(ZoomType.HORIZONTAL); previewChart = (PreviewLineChartView) findViewById(R.id.chart_preview); previewChart.setZoomType(ZoomType.HORIZONTAL); chart.setLineChartData(bgGraphBuilder.lineData()); chart.setOnValueTouchListener(bgGraphBuilder.getOnValueSelectTooltipListener(this)); previewChart.setLineChartData(bgGraphBuilder.previewLineData(chart.getLineChartData())); previewChart.setViewportCalculationEnabled(true); chart.setViewportCalculationEnabled(true); previewChart.setViewportChangeListener(new ViewportListener()); chart.setViewportChangeListener(new ChartViewPortListener()); setupStatistics(date1.getTimeInMillis(), endDate.getTimeInMillis()); }
Example 9
Source File: LineCharts.java From MetalDetector with GNU General Public License v3.0 | 6 votes |
/** * 初始化视图 * */ protected void initView(LineChartView lineChartView) { pointValueList = new ArrayList<>(); linesList = new ArrayList<>(); //初始化坐标轴 axisY = new Axis(); axisX = new Axis(); lineChartData = initData(null); lineChartView.setLineChartData(lineChartData); Viewport port = initViewPort(0, 50,150); lineChartView.setCurrentViewportWithAnimation(port); lineChartView.setInteractive(false); lineChartView.setScrollEnabled(true); lineChartView.setValueTouchEnabled(true); lineChartView.setFocusableInTouchMode(true); lineChartView.setViewportCalculationEnabled(false); lineChartView.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL); lineChartView.startDataAnimation(); points = new ArrayList<>(); }
Example 10
Source File: ExampleChartPreferenceView.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
protected void refreshView(View view) { LineChartView chart = (LineChartView) view.findViewById(R.id.example_linechart); BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(getContext()); chart.setLineChartData(bgGraphBuilder.lineData()); Viewport viewport = chart.getMaximumViewport(); chart.setViewportCalculationEnabled(false); chart.setInteractive(false); chart.setCurrentViewport(viewport); chart.setPadding(0, 0, 0, 0); chart.setLeft(0); chart.setTop(0); Log.d(TAG, "onBindExampleChart: refreshview " + chart.getHeight()); }
Example 11
Source File: LineCharts.java From MetalDetector with GNU General Public License v3.0 | 5 votes |
protected void makeCharts(final LineChartView lineChartView,float uT){ //实时添加新的点 PointValue value1 = new PointValue(position * 5, uT); value1.setLabel("00:00"); pointValueList.add(value1); float x = value1.getX(); float y = uT; //根据新的点的集合画出新的线 Line line = new Line(pointValueList); line.setColor(Color.RED); line.setShape(ValueShape.CIRCLE); line.setCubic(true);//曲线是否平滑 line.setHasPoints(false);//设置折线是否含点 linesList.clear(); linesList.add(line); lineChartData = initData(linesList); lineChartView.setLineChartData(lineChartData); //根据点的横坐实时变换坐标的视图范围 Viewport port; if (x > 500) { port = initViewPort(x - 500, x, y); } else { port = initViewPort(0, 500 ,y); } lineChartView.setCurrentViewport(port);//当前窗口 Viewport maxPort = initMaxViewPort(x,y);//更新最大窗口设置 lineChartView.setMaximumViewport(maxPort);//最大窗口 position++; }
Example 12
Source File: ExampleChartPreferenceView.java From xDrip with GNU General Public License v3.0 | 5 votes |
protected void refreshView(View view) { LineChartView chart = (LineChartView) view.findViewById(R.id.example_linechart); BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(getContext()); chart.setLineChartData(bgGraphBuilder.lineData()); Viewport viewport = chart.getMaximumViewport(); chart.setViewportCalculationEnabled(false); chart.setInteractive(false); chart.setCurrentViewport(viewport); chart.setPadding(0, 0, 0, 0); chart.setLeft(0); chart.setTop(0); Log.d(TAG, "onBindExampleChart: refreshview " + chart.getHeight()); }
Example 13
Source File: LibreTrendGraph.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
public void setupCharts() { final TextView trendView = (TextView) findViewById(R.id.textLibreHeader); chart = (LineChartView) findViewById(R.id.libre_chart); List<Line> lines = new ArrayList<Line>(); List<PointValue> lineValues = new ArrayList<PointValue>(); final float conversion_factor_mmol = (float) (doMgdl ? 1 : Constants.MGDL_TO_MMOLL); LibreBlock libreBlock= LibreBlock.getLatestForTrend(); if(libreBlock == null) { trendView.setText("No libre data to display"); setupEmptyCharts(); return; } String time = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new Date((long) libreBlock.timestamp)); ArrayList<Float> bg_data = getLatestBgForXMinutes(MINUTES_TO_DISPLAY); if(bg_data == null) { trendView.setText("Error displaying data for " + time); setupEmptyCharts(); return; } trendView.setText("Scan from " + time); float min = 1000; float max = 0; int i = 0; for(float bg : bg_data ) { if(bg <= 0) { i++; continue; } if(min > bg) { min = bg; } if(max < bg) { max = bg; } lineValues.add(new PointValue(-i, bg * conversion_factor_mmol)); i++; } Line trendLine = new Line(lineValues); trendLine.setColor(ChartUtils.COLOR_RED); trendLine.setHasLines(false); trendLine.setHasPoints(true); trendLine.setPointRadius(3); lines.add(trendLine); final int MIN_GRAPH = 20; if(max - min < MIN_GRAPH) { // On relative flat trend the graph can look very noise althouth with the right resolution it is not that way. // I will add two dummy invisible points that will cause the graph to look with bigger Y range. float average = (max + min) /2; List<PointValue> dummyPointValues = new ArrayList<PointValue>(); Line dummyPointLine = new Line(dummyPointValues); dummyPointValues.add(new PointValue(0, (average - MIN_GRAPH / 2) * conversion_factor_mmol)); dummyPointValues.add(new PointValue(0, (average + MIN_GRAPH / 2) * conversion_factor_mmol)); dummyPointLine.setColor(ChartUtils.COLOR_RED); dummyPointLine.setHasLines(false); dummyPointLine.setHasPoints(false); lines.add(dummyPointLine); } Axis axisX = new Axis(); Axis axisY = new Axis().setHasLines(true); axisX.setTextSize(16); axisY.setTextSize(16); axisX.setName("Time from last scan"); axisY.setName("Glucose " + (doMgdl ? "mg/dl" : "mmol/l")); data = new LineChartData(lines); data.setAxisXBottom(axisX); data.setAxisYLeft(axisY); chart.setLineChartData(data); }
Example 14
Source File: LibreTrendGraph.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
void setupEmptyCharts() { chart = (LineChartView) findViewById(R.id.libre_chart); List<Line> lines = new ArrayList<Line>(); data = new LineChartData(lines); chart.setLineChartData(data); }
Example 15
Source File: CalibrationGraph.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
public void setupCharts() { chart = (LineChartView) findViewById(R.id.chart); List<Line> lines = new ArrayList<Line>(); //calibration values List<Calibration> calibrations = Calibration.allForSensor(); List<Line> greyLines = getCalibrationsLine(calibrations, Color.parseColor("#66FFFFFF")); calibrations = Calibration.allForSensorInLastFourDays(); List<Line> blueLines = getCalibrationsLine(calibrations, ChartUtils.COLOR_BLUE); Calibration calibration = Calibration.lastValid(); if (calibration != null) { //set header DecimalFormat df = new DecimalFormat("#"); df.setMaximumFractionDigits(2); df.setMinimumFractionDigits(2); String Header = "slope = " + df.format(calibration.slope) + " intercept = " + df.format(calibration.intercept); GraphHeader.setText(Header); //red line List<PointValue> lineValues = new ArrayList<PointValue>(); final float conversion_factor = (float) (doMgdl ? 1 : Constants.MGDL_TO_MMOLL); lineValues.add(new PointValue((float) start_x, (conversion_factor * (float) (start_x * calibration.slope + calibration.intercept)))); lineValues.add(new PointValue((float) end_x, (conversion_factor * (float) (end_x * calibration.slope + calibration.intercept)))); Line calibrationLine = new Line(lineValues); calibrationLine.setColor(ChartUtils.COLOR_RED); calibrationLine.setHasLines(true); calibrationLine.setHasPoints(false); lines.add(calibrationLine); // calibration plugin final CalibrationAbstract plugin = getCalibrationPluginFromPreferences(); if (plugin != null) { final CalibrationAbstract.CalibrationData pcalibration = plugin.getCalibrationData(); final List<PointValue> plineValues = new ArrayList<PointValue>(); plineValues.add(new PointValue((float) start_x, (conversion_factor * (float) (plugin.getGlucoseFromSensorValue(start_x, pcalibration))))); plineValues.add(new PointValue((float) end_x, (conversion_factor * (float) (plugin.getGlucoseFromSensorValue(end_x, pcalibration))))); final Line pcalibrationLine = new Line(plineValues); pcalibrationLine.setColor(Color.parseColor(plugin_color)); pcalibrationLine.setHasLines(true); pcalibrationLine.setHasPoints(false); lines.add(pcalibrationLine); PluginHeader.setText("(" + plugin.getAlgorithmName() + ") " + "s = " + df.format(pcalibration.slope) + " i = " + df.format(pcalibration.intercept)); PluginHeader.setTextColor(Color.parseColor(plugin_color)); } //add lines in order for (Line greyLine : greyLines) { lines.add(greyLine); } for (Line blueLine : blueLines) { lines.add(blueLine); } } Axis axisX = new Axis(); Axis axisY = new Axis().setHasLines(true); axisX.setName("Raw Value"); axisY.setName("Glucose " + (doMgdl ? "mg/dl" : "mmol/l")); data = new LineChartData(lines); data.setAxisXBottom(axisX); data.setAxisYLeft(axisY); chart.setLineChartData(data); }
Example 16
Source File: Home.java From xDrip-Experimental with GNU General Public License v3.0 | 4 votes |
private void setupCharts() { bgGraphBuilder = new BgGraphBuilder(this); updateStuff = false; chart = (LineChartView) findViewById(R.id.chart); chart.setZoomType(ZoomType.HORIZONTAL); //Transmitter Battery Level final Sensor sensor = Sensor.currentSensor(); if (sensor != null && sensor.latest_battery_level != 0 && sensor.latest_battery_level <= Constants.TRANSMITTER_BATTERY_LOW && ! mPreferences.getBoolean("disable_battery_warning", false)) { Drawable background = new Drawable() { @Override public void draw(Canvas canvas) { DisplayMetrics metrics = getApplicationContext().getResources().getDisplayMetrics(); int px = (int) (30 * (metrics.densityDpi / 160f)); Paint paint = new Paint(); paint.setTextSize(px); paint.setAntiAlias(true); paint.setColor(Color.parseColor("#FFFFAA")); paint.setStyle(Paint.Style.STROKE); paint.setAlpha(100); canvas.drawText("transmitter battery", 10, chart.getHeight() / 3 - (int) (1.2 * px), paint); if(sensor.latest_battery_level <= Constants.TRANSMITTER_BATTERY_EMPTY){ paint.setTextSize((int)(px*1.5)); canvas.drawText("VERY LOW", 10, chart.getHeight() / 3, paint); } else { canvas.drawText("low", 10, chart.getHeight() / 3, paint); } } @Override public void setAlpha(int alpha) {} @Override public void setColorFilter(ColorFilter cf) {} @Override public int getOpacity() {return 0;} }; chart.setBackground(background); } previewChart = (PreviewLineChartView) findViewById(R.id.chart_preview); previewChart.setZoomType(ZoomType.HORIZONTAL); chart.setLineChartData(bgGraphBuilder.lineData()); chart.setOnValueTouchListener(bgGraphBuilder.getOnValueSelectTooltipListener()); previewChart.setLineChartData(bgGraphBuilder.previewLineData()); updateStuff = true; previewChart.setViewportCalculationEnabled(true); chart.setViewportCalculationEnabled(true); previewChart.setViewportChangeListener(new ViewportListener()); chart.setViewportChangeListener(new ChartViewPortListener()); setViewport(); }
Example 17
Source File: CalibrationGraph.java From xDrip with GNU General Public License v3.0 | 4 votes |
public void setupCharts() { chart = (LineChartView) findViewById(R.id.chart); List<Line> lines = new ArrayList<Line>(); //calibration values List<Calibration> calibrations = Calibration.allForSensor(); List<Line> greyLines = getCalibrationsLine(calibrations, Color.parseColor("#66FFFFFF")); calibrations = Calibration.allForSensorInLastFourDays(); List<Line> blueLines = getCalibrationsLine(calibrations, ChartUtils.COLOR_BLUE); Calibration calibration = Calibration.lastValid(); if (calibration != null) { //set header DecimalFormat df = new DecimalFormat("#"); df.setMaximumFractionDigits(2); df.setMinimumFractionDigits(2); String Header = "slope = " + df.format(calibration.slope) + " intercept = " + df.format(calibration.intercept); GraphHeader.setText(Header); //red line List<PointValue> lineValues = new ArrayList<PointValue>(); final float conversion_factor = (float) (doMgdl ? 1 : Constants.MGDL_TO_MMOLL); lineValues.add(new PointValue((float) start_x, (conversion_factor * (float) (start_x * calibration.slope + calibration.intercept)))); lineValues.add(new PointValue((float) end_x, (conversion_factor * (float) (end_x * calibration.slope + calibration.intercept)))); Line calibrationLine = new Line(lineValues); calibrationLine.setColor(ChartUtils.COLOR_RED); calibrationLine.setHasLines(true); calibrationLine.setHasPoints(false); lines.add(calibrationLine); // calibration plugin final CalibrationAbstract plugin = getCalibrationPluginFromPreferences(); if (plugin != null) { final CalibrationAbstract.CalibrationData pcalibration = plugin.getCalibrationData(); final List<PointValue> plineValues = new ArrayList<PointValue>(); plineValues.add(new PointValue((float) start_x, (conversion_factor * (float) (plugin.getGlucoseFromSensorValue(start_x, pcalibration))))); plineValues.add(new PointValue((float) end_x, (conversion_factor * (float) (plugin.getGlucoseFromSensorValue(end_x, pcalibration))))); final Line pcalibrationLine = new Line(plineValues); pcalibrationLine.setColor(Color.parseColor(plugin_color)); pcalibrationLine.setHasLines(true); pcalibrationLine.setHasPoints(false); lines.add(pcalibrationLine); PluginHeader.setText("(" + plugin.getAlgorithmName() + ") " + "s = " + df.format(pcalibration.slope) + " i = " + df.format(pcalibration.intercept)); PluginHeader.setTextColor(Color.parseColor(plugin_color)); } //add lines in order for (Line greyLine : greyLines) { lines.add(greyLine); } for (Line blueLine : blueLines) { lines.add(blueLine); } } Axis axisX = new Axis(); Axis axisY = new Axis().setHasLines(true); axisX.setName("Raw Value"); axisY.setName("Glucose " + (doMgdl ? "mg/dl" : "mmol/l")); data = new LineChartData(lines); data.setAxisXBottom(axisX); data.setAxisYLeft(axisY); chart.setLineChartData(data); }
Example 18
Source File: CalibrationGraph.java From xDrip-Experimental with GNU General Public License v3.0 | 4 votes |
public void setupCharts() { chart = (LineChartView) findViewById(R.id.chart); List<Line> lines = new ArrayList<Line>(); Calibration calibration = Calibration.last(); if(calibration != null) { //set header DecimalFormat df = new DecimalFormat("#"); df.setMaximumFractionDigits(2); df.setMinimumFractionDigits(2); String Header = "slope = " + df.format(calibration.slope) + " intercept = " + df.format(calibration.intercept); GraphHeader.setText(Header); //red line List<PointValue> lineValues = new ArrayList<PointValue>(); lineValues.add(new PointValue((float) start_x, (float) (start_x * calibration.slope + calibration.intercept))); lineValues.add(new PointValue((float) end_x, (float) (end_x * calibration.slope + calibration.intercept))); Line calibrationLine = new Line(lineValues); calibrationLine.setColor(ChartUtils.COLOR_RED); calibrationLine.setHasLines(true); calibrationLine.setHasPoints(false); //calibration values List<Calibration> calibrations = Calibration.allForSensor(); Line greyLine = getCalibrationsLine(calibrations, Color.parseColor("#66FFFFFF")); calibrations = Calibration.allForSensorInLastFourDays(); Line blueLine = getCalibrationsLine(calibrations, ChartUtils.COLOR_BLUE); //add lines in order lines.add(greyLine); lines.add(blueLine); lines.add(calibrationLine); } Axis axisX = new Axis(); Axis axisY = new Axis().setHasLines(true); axisX.setName("Raw Value"); axisY.setName("BG"); data = new LineChartData(lines); data.setAxisXBottom(axisX); data.setAxisYLeft(axisY); chart.setLineChartData(data); }
Example 19
Source File: LibreTrendGraph.java From xDrip with GNU General Public License v3.0 | 4 votes |
void setupEmptyCharts() { chart = (LineChartView) findViewById(R.id.libre_chart); List<Line> lines = new ArrayList<Line>(); data = new LineChartData(lines); chart.setLineChartData(data); }
Example 20
Source File: LibreTrendGraph.java From xDrip with GNU General Public License v3.0 | 4 votes |
public void setupCharts() { final TextView trendView = (TextView) findViewById(R.id.textLibreHeader); chart = (LineChartView) findViewById(R.id.libre_chart); List<Line> lines = new ArrayList<Line>(); List<PointValue> lineValues = new ArrayList<PointValue>(); final float conversion_factor_mmol = (float) (doMgdl ? 1 : Constants.MGDL_TO_MMOLL); LibreBlock libreBlock= LibreBlock.getLatestForTrend(); if(libreBlock == null) { trendView.setText("No libre data to display"); setupEmptyCharts(); return; } String time = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new Date((long) libreBlock.timestamp)); ArrayList<Float> bg_data = getLatestBgForXMinutes(MINUTES_TO_DISPLAY); if(bg_data == null) { trendView.setText("Error displaying data for " + time); setupEmptyCharts(); return; } trendView.setText("Scan from " + time); float min = 1000; float max = 0; int i = 0; for(float bg : bg_data ) { if(bg <= 0) { i++; continue; } if(min > bg) { min = bg; } if(max < bg) { max = bg; } lineValues.add(new PointValue(-i, bg * conversion_factor_mmol)); i++; } Line trendLine = new Line(lineValues); trendLine.setColor(ChartUtils.COLOR_RED); trendLine.setHasLines(false); trendLine.setHasPoints(true); trendLine.setPointRadius(3); lines.add(trendLine); final int MIN_GRAPH = 20; if(max - min < MIN_GRAPH) { // On relative flat trend the graph can look very noise althouth with the right resolution it is not that way. // I will add two dummy invisible points that will cause the graph to look with bigger Y range. float average = (max + min) /2; List<PointValue> dummyPointValues = new ArrayList<PointValue>(); Line dummyPointLine = new Line(dummyPointValues); dummyPointValues.add(new PointValue(0, (average - MIN_GRAPH / 2) * conversion_factor_mmol)); dummyPointValues.add(new PointValue(0, (average + MIN_GRAPH / 2) * conversion_factor_mmol)); dummyPointLine.setColor(ChartUtils.COLOR_RED); dummyPointLine.setHasLines(false); dummyPointLine.setHasPoints(false); lines.add(dummyPointLine); } Axis axisX = new Axis(); Axis axisY = new Axis().setHasLines(true); axisX.setTextSize(16); axisY.setTextSize(16); axisX.setName("Time from last scan"); axisY.setName("Glucose " + (doMgdl ? "mg/dl" : "mmol/l")); data = new LineChartData(lines); data.setAxisXBottom(axisX); data.setAxisYLeft(axisY); chart.setLineChartData(data); }