Java Code Examples for lecho.lib.hellocharts.model.Line#getValues()
The following examples show how to use
lecho.lib.hellocharts.model.Line#getValues() .
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: LineChartRenderer.java From hellocharts-android with Apache License 2.0 | 6 votes |
@Override public boolean checkTouch(float touchX, float touchY) { selectedValue.clear(); final LineChartData data = dataProvider.getLineChartData(); int lineIndex = 0; for (Line line : data.getLines()) { if (checkIfShouldDrawPoints(line)) { int pointRadius = ChartUtils.dp2px(density, line.getPointRadius()); int valueIndex = 0; for (PointValue pointValue : line.getValues()) { final float rawValueX = computator.computeRawX(pointValue.getX()); final float rawValueY = computator.computeRawY(pointValue.getY()); if (isInArea(rawValueX, rawValueY, touchX, touchY, pointRadius + touchToleranceMargin)) { selectedValue.set(lineIndex, valueIndex, SelectedValueType.LINE); } ++valueIndex; } } ++lineIndex; } return isTouched(); }
Example 2
Source File: LineChartRenderer.java From hellocharts-android with Apache License 2.0 | 6 votes |
private void calculateMaxViewport() { tempMaximumViewport.set(Float.MAX_VALUE, Float.MIN_VALUE, Float.MIN_VALUE, Float.MAX_VALUE); LineChartData data = dataProvider.getLineChartData(); for (Line line : data.getLines()) { // Calculate max and min for viewport. for (PointValue pointValue : line.getValues()) { if (pointValue.getX() < tempMaximumViewport.left) { tempMaximumViewport.left = pointValue.getX(); } if (pointValue.getX() > tempMaximumViewport.right) { tempMaximumViewport.right = pointValue.getX(); } if (pointValue.getY() < tempMaximumViewport.bottom) { tempMaximumViewport.bottom = pointValue.getY(); } if (pointValue.getY() > tempMaximumViewport.top) { tempMaximumViewport.top = pointValue.getY(); } } } }
Example 3
Source File: LineChartRenderer.java From hellocharts-android with Apache License 2.0 | 6 votes |
private void drawPoints(Canvas canvas, Line line, int lineIndex, int mode) { pointPaint.setColor(line.getPointColor()); int valueIndex = 0; for (PointValue pointValue : line.getValues()) { int pointRadius = ChartUtils.dp2px(density, line.getPointRadius()); final float rawX = computator.computeRawX(pointValue.getX()); final float rawY = computator.computeRawY(pointValue.getY()); if (computator.isWithinContentRect(rawX, rawY, checkPrecision)) { // Draw points only if they are within contentRectMinusAllMargins, using contentRectMinusAllMargins // instead of viewport to avoid some // float rounding problems. if (MODE_DRAW == mode) { drawPoint(canvas, line, pointValue, rawX, rawY, pointRadius); if (line.hasLabels()) { drawLabel(canvas, line, pointValue, rawX, rawY, pointRadius + labelOffset); } } else if (MODE_HIGHLIGHT == mode) { highlightPoint(canvas, line, pointValue, rawX, rawY, lineIndex, valueIndex); } else { throw new IllegalStateException("Cannot process points in mode: " + mode); } } ++valueIndex; } }
Example 4
Source File: BgGraphBuilder.java From xDrip with GNU General Public License v3.0 | 5 votes |
private ArrayList<Line> autoSplitLine(Line macroline, final float jumpthresh) { ArrayList<Line> linearray = new ArrayList<>(); float lastx = -999999; List<PointValue> macropoints = macroline.getValues(); List<PointValue> thesepoints = new ArrayList<>(); if (macropoints.size() > 0) { final float endmarker = macropoints.get(macropoints.size() - 1).getX(); for (PointValue thispoint : macropoints) { // a jump too far for a line? make it a new one if (((lastx != -999999) && (Math.abs(thispoint.getX() - lastx) > jumpthresh)) || thispoint.getX() == endmarker) { if (thispoint.getX() == endmarker) { thesepoints.add(thispoint); } Line line = (Line) cloneObject(macroline); // aieeee try { line.setValues(thesepoints); linearray.add(line); } catch (NullPointerException e) { // } thesepoints = new ArrayList<PointValue>(); } lastx = thispoint.getX(); thesepoints.add(thispoint); // grow current line list } } return linearray; }
Example 5
Source File: BgGraphBuilder.java From xDrip with GNU General Public License v3.0 | 5 votes |
public ArrayList<Line> autoSplitLine(Line macroline, final float jumpthresh) { // if (d) Log.d(TAG, "Enter autoSplit Line"); ArrayList<Line> linearray = new ArrayList<Line>(); float lastx = -999999; List<PointValue> macropoints = macroline.getValues(); List<PointValue> thesepoints = new ArrayList<PointValue>(); if (macropoints.size() > 0) { final float endmarker = macropoints.get(macropoints.size() - 1).getX(); for (PointValue thispoint : macropoints) { // a jump too far for a line? make it a new one if (((lastx != -999999) && (Math.abs(thispoint.getX() - lastx) > jumpthresh)) || thispoint.getX() == endmarker) { if (thispoint.getX() == endmarker) { thesepoints.add(thispoint); } Line line = (Line) JoH.cloneObject(macroline); // aieeee line.setValues(thesepoints); linearray.add(line); thesepoints = new ArrayList<PointValue>(); } lastx = thispoint.getX(); thesepoints.add(thispoint); // grow current line list } } // if (d) Log.d(TAG, "Exit autoSplit Line"); return linearray; }
Example 6
Source File: BgGraphBuilder.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
private ArrayList<Line> autoSplitLine(Line macroline, final float jumpthresh) { ArrayList<Line> linearray = new ArrayList<>(); float lastx = -999999; List<PointValue> macropoints = macroline.getValues(); List<PointValue> thesepoints = new ArrayList<>(); if (macropoints.size() > 0) { final float endmarker = macropoints.get(macropoints.size() - 1).getX(); for (PointValue thispoint : macropoints) { // a jump too far for a line? make it a new one if (((lastx != -999999) && (Math.abs(thispoint.getX() - lastx) > jumpthresh)) || thispoint.getX() == endmarker) { if (thispoint.getX() == endmarker) { thesepoints.add(thispoint); } Line line = (Line) cloneObject(macroline); // aieeee try { line.setValues(thesepoints); linearray.add(line); } catch (NullPointerException e) { // } thesepoints = new ArrayList<PointValue>(); } lastx = thispoint.getX(); thesepoints.add(thispoint); // grow current line list } } return linearray; }
Example 7
Source File: BgGraphBuilder.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public ArrayList<Line> autoSplitLine(Line macroline, final float jumpthresh) { // if (d) Log.d(TAG, "Enter autoSplit Line"); ArrayList<Line> linearray = new ArrayList<Line>(); float lastx = -999999; List<PointValue> macropoints = macroline.getValues(); List<PointValue> thesepoints = new ArrayList<PointValue>(); if (macropoints.size() > 0) { final float endmarker = macropoints.get(macropoints.size() - 1).getX(); for (PointValue thispoint : macropoints) { // a jump too far for a line? make it a new one if (((lastx != -999999) && (Math.abs(thispoint.getX() - lastx) > jumpthresh)) || thispoint.getX() == endmarker) { if (thispoint.getX() == endmarker) { thesepoints.add(thispoint); } Line line = (Line) JoH.cloneObject(macroline); // aieeee line.setValues(thesepoints); linearray.add(line); thesepoints = new ArrayList<PointValue>(); } lastx = thispoint.getX(); thesepoints.add(thispoint); // grow current line list } } // if (d) Log.d(TAG, "Exit autoSplit Line"); return linearray; }
Example 8
Source File: LineChartRenderer.java From hellocharts-android with Apache License 2.0 | 5 votes |
/** * Draws lines, uses path for drawing filled area on software canvas. Line is drawn with canvas.drawLines() method. */ private void drawPath(Canvas canvas, final Line line) { prepareLinePaint(line); int valueIndex = 0; for (PointValue pointValue : line.getValues()) { final float rawX = computator.computeRawX(pointValue.getX()); final float rawY = computator.computeRawY(pointValue.getY()); if (valueIndex == 0) { path.moveTo(rawX, rawY); } else { path.lineTo(rawX, rawY); } ++valueIndex; } canvas.drawPath(path, linePaint); if (line.isFilled()) { drawArea(canvas, line); } path.reset(); }
Example 9
Source File: LineChartRenderer.java From hellocharts-android with Apache License 2.0 | 5 votes |
private void drawSquarePath(Canvas canvas, final Line line) { prepareLinePaint(line); int valueIndex = 0; float previousRawY = 0; for (PointValue pointValue : line.getValues()) { final float rawX = computator.computeRawX(pointValue.getX()); final float rawY = computator.computeRawY(pointValue.getY()); if (valueIndex == 0) { path.moveTo(rawX, rawY); } else { path.lineTo(rawX, previousRawY); path.lineTo(rawX, rawY); } previousRawY = rawY; ++valueIndex; } canvas.drawPath(path, linePaint); if (line.isFilled()) { drawArea(canvas, line); } path.reset(); }
Example 10
Source File: LineChartActivity.java From hellocharts-android with Apache License 2.0 | 5 votes |
/** * To animate values you have to change targets values and then call {@link Chart#startDataAnimation()} * method(don't confuse with View.animate()). If you operate on data that was set before you don't have to call * {@link LineChartView#setLineChartData(LineChartData)} again. */ private void prepareDataAnimation() { for (Line line : data.getLines()) { for (PointValue value : line.getValues()) { // Here I modify target only for Y values but it is OK to modify X targets as well. value.setTarget(value.getX(), (float) Math.random() * 100); } } }
Example 11
Source File: LineColumnDependencyActivity.java From hellocharts-android with Apache License 2.0 | 5 votes |
private void generateLineData(int color, float range) { // Cancel last animation if not finished. chartTop.cancelDataAnimation(); // Modify data targets Line line = lineData.getLines().get(0);// For this example there is always only one line. line.setColor(color); for (PointValue value : line.getValues()) { // Change target only for Y value. value.setTarget(value.getX(), (float) Math.random() * range); } // Start new data animation with 300ms duration; chartTop.startDataAnimation(300); }