com.github.mikephil.charting.data.Entry Java Examples

The following examples show how to use com.github.mikephil.charting.data.Entry. 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: SimpleFragment.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
protected ScatterData generateScatterData(int dataSets, float range, int count) {

        ArrayList<IScatterDataSet> sets = new ArrayList<>();

        ScatterChart.ScatterShape[] shapes = ScatterChart.ScatterShape.getAllDefaultShapes();

        for(int i = 0; i < dataSets; i++) {

            ArrayList<Entry> entries = new ArrayList<>();

            for(int j = 0; j < count; j++) {
                entries.add(new Entry(j, (float) (Math.random() * range) + range / 4));
            }

            ScatterDataSet ds = new ScatterDataSet(entries, getLabel(i));
            ds.setScatterShapeSize(12f);
            ds.setScatterShape(shapes[i % shapes.length]);
            ds.setColors(ColorTemplate.COLORFUL_COLORS);
            ds.setScatterShapeSize(9f);
            sets.add(ds);
        }

        ScatterData d = new ScatterData(sets);
        d.setValueTypeface(tf);
        return d;
    }
 
Example #2
Source File: KlineFragment.java    From shinny-futures-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * date: 2019/2/22
 * author: chenli
 * description: 产生持仓量数据集
 */
private LineDataSet generateLineDataSet(List<Entry> entries, int color, String label, boolean isHighlight, YAxis.AxisDependency axisDependency) {
    LineDataSet set = new LineDataSet(entries, label);
    set.setColor(color);
    set.setLineWidth(0.7f);
    set.setDrawCircles(false);
    set.setDrawCircleHole(false);
    set.setDrawValues(false);
    set.setAxisDependency(axisDependency);
    if (isHighlight) {
        set.setHighlightLineWidth(0.7f);
        set.setHighLightColor(color);
    } else {
        set.setHighlightEnabled(false);
    }
    return set;
}
 
Example #3
Source File: ModelDetailActivity.java    From Synapse with Apache License 2.0 6 votes vote down vote up
private void handleTrainingEvent(@NonNull TrainEvent event) {
    final Model model = (Model) event.obj;

    if (model == null) {
        return;
    }

    if (mChart.isEmpty()) {
        setUpNormalValues(model);
        setUpChart(model);
    } else {
        final int step = model.getStepEpoch();
        final double[] accuracies = model.getAccuracies();

        mAccuracyData.add(new Entry(step, (float) (double) accuracies[step - 1]));

        mChart.getData().notifyDataChanged();
        mChart.notifyDataSetChanged();
        mChart.invalidate();
    }
}
 
Example #4
Source File: KLineDataManage.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
public void setOneMaValue(LineData lineData, int i) {
    for (int k = 0; k < lineData.getDataSets().size(); k++) {
        ILineDataSet lineDataSet = lineData.getDataSetByIndex(k);
        lineDataSet.removeEntryByXValue(i);
        if (k == 0) {
            if (i >= N1) {
                sum = 0;
                float all5 = getSum(i - (N1 - 1), i) / N1;
                lineDataSet.addEntry(new Entry(i + offSet, all5));
            }
        } else if (k == 1) {
            if (i >= N2) {
                sum = 0;
                float all10 = getSum(i - (N2 - 1), i) / N2;
                lineDataSet.addEntry(new Entry(i + offSet, all10));
            }
        } else if (k == 2) {
            if (i >= N3) {
                sum = 0;
                float all20 = getSum(i - (N3 - 1), i) / N3;
                lineDataSet.addEntry(new Entry(i + offSet, all20));
            }
        }
    }
}
 
Example #5
Source File: KlineFragment.java    From shinny-futures-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * date: 6/1/18
 * author: chenli
 * description: K线图刷新时生成单个数据
 */
private void generateCandleAndLineDataEntry(int left_index, int index) {
    Map<String, KlineEntity.DataEntity> dataEntities = mKlineEntity.getData();
    KlineEntity.DataEntity dataEntity = dataEntities.get(String.valueOf(index));
    if (dataEntity == null) return;
    mCalendar.setTimeInMillis(Long.valueOf(dataEntity.getDatetime()) / 1000000);
    xVals.put(index - mBaseIndex, mSimpleDateFormat.format(mCalendar.getTime()));

    List<Entry> entries = generateMultiDataEntry(index, dataEntity, left_index);
    mTopChartViewBase.getCandleData().getDataSetByIndex(0).addEntryOrdered((CandleEntry) entries.get(0));
    mMiddleChartViewBase.getLineData().getDataSetByIndex(0).addEntryOrdered(entries.get(1));
    mMiddleChartViewBase.getBarData().getDataSetByIndex(0).addEntryOrdered((BarEntry) entries.get(2));
    mBottomChartViewBase.getLineData().getDataSetByIndex(0).addEntryOrdered(entries.get(3));
    mBottomChartViewBase.getLineData().getDataSetByIndex(1).addEntryOrdered(entries.get(4));
    mBottomChartViewBase.getBarData().getDataSetByIndex(0).addEntryOrdered((BarEntry) entries.get(5));

    for (int i = 0; i < mas.size(); i++) {
        int para = mas.get(i);
        if (index >= left_index + para - 1) {
            Entry entry = generateMALineDataEntry(index, para - 1);
            mLineData.getDataSetByIndex(i).addEntryOrdered(entry);
        }
    }
}
 
Example #6
Source File: Approximator.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
/**
 * uses the douglas peuker algorithm to reduce the given List of
 * entries
 * 
 * @param entries
 * @param epsilon
 * @return
 */
private List<Entry> reduceWithDouglasPeuker(List<Entry> entries, double epsilon) {
    // if a shape has 2 or less points it cannot be reduced
    if (epsilon <= 0 || entries.size() < 3) {
        return entries;
    }

    // first and last always stay
    keep[0] = true;
    keep[entries.size() - 1] = true;

    // first and last entry are entry point to recursion
    algorithmDouglasPeucker(entries, epsilon, 0, entries.size() - 1);

    // create a new array with series, only take the kept ones
    List<Entry> reducedEntries = new ArrayList<Entry>();
    for (int i = 0; i < entries.size(); i++) {
        if (keep[i]) {
            Entry curEntry = entries.get(i);
            reducedEntries.add(new Entry(curEntry.getVal(), curEntry.getXIndex()));
        }
    }
    return reducedEntries;
}
 
Example #7
Source File: Approximator.java    From NetKnight with Apache License 2.0 6 votes vote down vote up
/**
 * Filters according to type.
 * 
 * @param points the points to filter
 * @param tolerance the angle in degrees that will trigger the filtering
 * @return
 */
public List<Entry> filter(List<Entry> points, double tolerance) {

    if (tolerance <= 0)
        return points;

    keep = new boolean[points.size()];

    switch (mType) {
        case DOUGLAS_PEUCKER:
            return reduceWithDouglasPeuker(points, tolerance);
        case NONE:
            return points;
        default:
            return points;
    }
}
 
Example #8
Source File: StackedValueFormatter.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {

    if (!mDrawWholeStack && entry instanceof BarEntry) {

        BarEntry barEntry = (BarEntry) entry;
        float[] vals = barEntry.getYVals();

        if (vals != null) {

            // find out if we are on top of the stack
            if (vals[vals.length - 1] == value) {

                // return the "sum" across all stack values
                return mFormat.format(barEntry.getY()) + mAppendix;
            } else {
                return ""; // return empty
            }
        }
    }

    // return the "proposed" value
    return mFormat.format(value) + mAppendix;
}
 
Example #9
Source File: HorizontalBarChartActivity.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
@Override
public void onValueSelected(Entry e, Highlight h) {

    if (e == null)
        return;

    RectF bounds = mOnValueSelectedRectF;
    chart.getBarBounds((BarEntry) e, bounds);

    MPPointF position = chart.getPosition(e, chart.getData().getDataSetByIndex(h.getDataSetIndex())
            .getAxisDependency());

    Log.i("bounds", bounds.toString());
    Log.i("position", position.toString());

    MPPointF.recycleInstance(position);
}
 
Example #10
Source File: Approximator.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
/**
 * calculate the distance between a line between two entries and an entry
 * (point)
 * 
 * @param startEntry line startpoint
 * @param endEntry line endpoint
 * @param entryPoint the point to which the distance is measured from the
 *            line
 * @return
 */
public double calcPointToLineDistance(Entry startEntry, Entry endEntry, Entry entryPoint) {

    float xDiffEndStart = (float) endEntry.getXIndex() - (float) startEntry.getXIndex();
    float xDiffEntryStart = (float) entryPoint.getXIndex() - (float) startEntry.getXIndex();

    double normalLength = Math.sqrt((xDiffEndStart)
            * (xDiffEndStart)
            + (endEntry.getVal() - startEntry.getVal())
            * (endEntry.getVal() - startEntry.getVal()));
    return Math.abs((xDiffEntryStart)
            * (endEntry.getVal() - startEntry.getVal())
            - (entryPoint.getVal() - startEntry.getVal())
            * (xDiffEndStart))
            / normalLength;
}
 
Example #11
Source File: FragmentPrice.java    From Lunary-Ethereum-Wallet with GNU General Public License v3.0 6 votes vote down vote up
private LineData getData(ArrayList<Entry> yVals) {
    LineDataSet set1 = new LineDataSet(yVals, "");
    set1.setLineWidth(1.45f);
    set1.setColor(Color.argb(240, 255, 255, 255));
    set1.setCircleColor(Color.WHITE);
    set1.setHighLightColor(Color.WHITE);
    set1.setFillColor(getResources().getColor(R.color.chartFilled));
    set1.setDrawCircles(false);
    set1.setDrawValues(false);
    set1.setDrawFilled(true);
    set1.setFillFormatter(new IFillFormatter() {
        @Override
        public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
            return priceChart.getAxisLeft().getAxisMinimum();
        }
    });

    LineData data = new LineData(set1);
    return data;
}
 
Example #12
Source File: PlotterFragment.java    From Bluefruit_LE_Connect_Android_V2 with MIT License 6 votes vote down vote up
private void appendDataset(@NonNull String peripheralIdentifier, @NonNull Entry entry, int index) {
    LineDataSet dataSet = new LineDataSet(null, "Values[" + peripheralIdentifier + ":" + index + "]");
    dataSet.addEntry(entry);
    dataSet.addEntry(entry);

    dataSet.setDrawCircles(false);
    dataSet.setDrawValues(false);
    dataSet.setLineWidth(2);
    final int[] colors = UartStyle.defaultColors();
    final int color = colors[index % colors.length];
    dataSet.setColor(color);
    final DashPathEffect dashPatternEffect = mLineDashPathEffectForPeripheral.get(peripheralIdentifier);
    dataSet.setFormLineDashEffect(dashPatternEffect);

    List<LineDataSet> previousDataSets = mDataSetsForPeripheral.get(peripheralIdentifier);
    if (previousDataSets != null) {
        previousDataSets.add(dataSet);
    } else {
        List<LineDataSet> dataSets = new ArrayList<>();
        dataSets.add(dataSet);
        mDataSetsForPeripheral.put(peripheralIdentifier, dataSets);
    }
}
 
Example #13
Source File: KLineDataManage.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
/**
 * 初始化自己计算KDJ
 */
public void initKDJ() {
    KDJEntity kdjEntity = new KDJEntity(getKLineDatas(), KDJN, KDJM1, KDJM2);

    kData = new ArrayList<>();
    dData = new ArrayList<>();
    jData = new ArrayList<>();
    for (int i = 0; i < kdjEntity.getD().size(); i++) {
        kData.add(new Entry(i + offSet, kdjEntity.getK().get(i)));
        dData.add(new Entry(i + offSet, kdjEntity.getD().get(i)));
        jData.add(new Entry(i + offSet, kdjEntity.getJ().get(i)));
    }
    lineDataKDJ.add(setALine(ColorType.blue, kData, "KDJ" + N1, false));
    lineDataKDJ.add(setALine(ColorType.yellow, dData, "KDJ" + N2, false));
    lineDataKDJ.add(setALine(ColorType.purple, jData, "KDJ" + N3, true));
}
 
Example #14
Source File: ListViewMultiChartActivity.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
/**
 * generates a random ChartData object with just one DataSet
 * 
 * @return
 */
private LineData generateDataLine(int cnt) {

    ArrayList<Entry> e1 = new ArrayList<Entry>();

    for (int i = 0; i < 12; i++) {
        e1.add(new Entry((int) (Math.random() * 65) + 40, i));
    }

    LineDataSet d1 = new LineDataSet(e1, "New DataSet " + cnt + ", (1)");
    d1.setLineWidth(2.5f);
    d1.setCircleRadius(4.5f);
    d1.setHighLightColor(Color.rgb(244, 117, 117));
    d1.setDrawValues(false);
    
    ArrayList<Entry> e2 = new ArrayList<Entry>();

    for (int i = 0; i < 12; i++) {
        e2.add(new Entry(e1.get(i).getVal() - 30, i));
    }

    LineDataSet d2 = new LineDataSet(e2, "New DataSet " + cnt + ", (2)");
    d2.setLineWidth(2.5f);
    d2.setCircleRadius(4.5f);
    d2.setHighLightColor(Color.rgb(244, 117, 117));
    d2.setColor(ColorTemplate.VORDIPLOM_COLORS[0]);
    d2.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[0]);
    d2.setDrawValues(false);
    
    ArrayList<ILineDataSet> sets = new ArrayList<ILineDataSet>();
    sets.add(d1);
    sets.add(d2);
    
    LineData cd = new LineData(getMonths(), sets);
    return cd;
}
 
Example #15
Source File: Transformer.java    From iMoney with Apache License 2.0 5 votes vote down vote up
/**
 * Transforms an List of Entry into a float array containing the x and
 * y values transformed with all matrices for the BARCHART.
 * 
 * @param entries
 * @param dataSet the dataset index
 * @return
 */
public float[] generateTransformedValuesHorizontalBarChart(List<? extends Entry> entries,
        int dataSet, BarData bd, float phaseY) {

    float[] valuePoints = new float[entries.size() * 2];

    int setCount = bd.getDataSetCount();
    float space = bd.getGroupSpace();

    for (int j = 0; j < valuePoints.length; j += 2) {

        Entry e = entries.get(j / 2);
        int i = e.getXIndex();

        // calculate the x-position, depending on datasetcount
        float x = i + i * (setCount - 1) + dataSet + space * i
                + space / 2f ;
        float y = e.getVal();

        valuePoints[j] = y * phaseY;
        valuePoints[j + 1] = x;
    }

    getValueToPixelMatrix().mapPoints(valuePoints);

    return valuePoints;
}
 
Example #16
Source File: TempLineDataSet.java    From octoandroid with GNU General Public License v3.0 5 votes vote down vote up
public TempLineDataSet(List<Entry> yVals, String label, LineDataSetModel model) {
    super(yVals, label);
    setColor(model.color());
    setDrawCircles(false);
    setDrawValues(false);
    if (model.actual()) {
        setLineWidth(2f);
    } else {
        enableDashedLine(10f, 5f, 0f);
    }
}
 
Example #17
Source File: StockGraphFragment.java    From Stock-Hawk with Apache License 2.0 5 votes vote down vote up
@Override
public void showFinanceChartData(FinanceChartCallBack financeChartCallBack) {
    getActivity().setTitle(financeChartCallBack.getMeta().getCompanyName());
    lables = Utils.getPlottingLables(getActivity(), financeChartCallBack.getSeries());
    values = Utils.getPlottingValues(financeChartCallBack.getSeries());

    getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {

            ArrayList<Entry> val = new ArrayList<Entry>();
            for (int i = 0; i < lables.size(); i++) {
                val.add(new Entry(values.get(i), i));
            }

            LineDataSet set = new LineDataSet(val, "Stocks Data");

            set.enableDashedLine(10f, 5f, 0f);
            set.enableDashedHighlightLine(10f, 5f, 0f);
            set.setColor(Color.BLACK);
            set.setCircleColor(Color.BLACK);
            set.setLineWidth(1f);
            set.setCircleRadius(3f);
            set.setDrawCircleHole(false);
            set.setValueTextSize(9f);
            set.setDrawFilled(true);

            ArrayList<String> dates = new ArrayList<String>();
            for (int i = 0; i < lables.size(); i++) {
                dates.add(i, lables.get(i));
            }
            LineData data = new LineData(lables, set);
            mChart.setData(data);
            mChart.invalidate();

        }
    });
}
 
Example #18
Source File: PieChartManager.java    From react-native-mp-android-chart with MIT License 5 votes vote down vote up
@Override
void dataSetConfig(IDataSet<Entry> dataSet, ReadableMap config) {
    PieDataSet pieDataSet = (PieDataSet) dataSet;

    ChartDataSetConfigUtils.commonConfig(pieDataSet, config);

    // PieDataSet only config
    if (BridgeUtils.validate(config, ReadableType.Number, "sliceSpace")) {
        pieDataSet.setSliceSpace((float) config.getDouble("sliceSpace"));
    }
    if (BridgeUtils.validate(config, ReadableType.Number, "selectionShift")) {
        pieDataSet.setSelectionShift((float) config.getDouble("selectionShift"));
    }
}
 
Example #19
Source File: PieChart.java    From iMoney with Apache License 2.0 5 votes vote down vote up
@Override
protected float[] getMarkerPosition(Entry e, Highlight highlight) {

    PointF center = getCenterCircleBox();
    float r = getRadius();

    float off = r / 10f * 3.6f;

    if (isDrawHoleEnabled()) {
        off = (r - (r / 100f * getHoleRadius())) / 2f;
    }

    r -= off; // offset to keep things inside the chart

    float rotationAngle = getRotationAngle();

    int i = e.getXIndex();

    // offset needed to center the drawn text in the slice
    float offset = mDrawAngles[i] / 2;

    // calculate the text position
    float x = (float) (r
            * Math.cos(Math.toRadians((rotationAngle + mAbsoluteAngles[i] - offset)
            * mAnimator.getPhaseY())) + center.x);
    float y = (float) (r
            * Math.sin(Math.toRadians((rotationAngle + mAbsoluteAngles[i] - offset)
            * mAnimator.getPhaseY())) + center.y);

    return new float[]{x, y};
}
 
Example #20
Source File: Transformer.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
/**
 * Transforms an List of Entry into a float array containing the x and
 * y values transformed with all matrices for the SCATTERCHART.
 *
 * @param data
 * @return
 */
public float[] generateTransformedValuesScatter(IScatterDataSet data, float phaseX,
                                                float phaseY, int from, int to) {

    final int count = (int) ((to - from) * phaseX + 1) * 2;

    if (valuePointsForGenerateTransformedValuesScatter.length != count) {
        valuePointsForGenerateTransformedValuesScatter = new float[count];
    }
    float[] valuePoints = valuePointsForGenerateTransformedValuesScatter;

    for (int j = 0; j < count; j += 2) {

        Entry e = data.getEntryForIndex(j / 2 + from);

        if (e != null) {
            valuePoints[j] = e.getX();
            valuePoints[j + 1] = e.getY() * phaseY;
        } else {
            valuePoints[j] = 0;
            valuePoints[j + 1] = 0;
        }
    }

    getValueToPixelMatrix().mapPoints(valuePoints);

    return valuePoints;
}
 
Example #21
Source File: RecordingList.java    From voice-pitch-analyzer with GNU Affero General Public License v3.0 5 votes vote down vote up
/***
 * get the graph entries for progress fragment
 * only one entry per day
 * if there are more than one recordings per day,
 * only use the first entry of that day
 * for future: calculate average as this day's value
 *
 * @return
 */
public List<Entry> getGraphEntries()
{
    List<Entry> result = new ArrayList<Entry>();

    Log.i("test", String.format("duration: %s", (int) new Duration(new DateTime(this.getBeginning()), new DateTime(this.getEnd())).getStandardDays()));

    for (Hashtable.Entry<DateTime, Recording> record : this.getRecordings().entrySet())
    {
        // reset time of day so .getDuration() will always calculate a duration of one day between two different dates
        DateTime recordTime = new DateTime(record.getKey().getYear(), record.getKey().getMonthOfYear(), record.getKey().getDayOfMonth(), 0, 0, 0, 0);

        // list index as duration in days since first recording
        int index = (int) new Duration(this.getBeginningAsDate(), recordTime).getStandardDays();

        // check if there are multiple entries for this date
        // and only add date if recording contains any pitch data
        if (!this.containsIndex(result, index) && record.getValue().getRange().getAvg() > 0)
        {
            Log.i("RecordingList", String.format("beginning: %s", new DateTime(this.getBeginning()).toDateTime()));
            result.add(new Entry((float) record.getValue().getRange().getAvg(), index));
        }
    }

    Collections.sort(result, new EntryComparator());

    for (Entry entry : result)
    {
        Log.i("result", String.format("%s: %s", entry.getXIndex(), entry.getVal()));
    }

    return result;
}
 
Example #22
Source File: BarLineChartBase.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
/**
 * Returns a recyclable MPPointF instance.
 * Returns the position (in pixels) the provided Entry has inside the chart
 * view or null, if the provided Entry is null.
 *
 * @param e
 * @return
 */
public MPPointF getPosition(Entry e, AxisDependency axis) {

    if (e == null) {
        return null;
    }

    mGetPositionBuffer[0] = e.getX();
    mGetPositionBuffer[1] = e.getY();

    getTransformer(axis).pointValuesToPixel(mGetPositionBuffer);

    return MPPointF.getInstance(mGetPositionBuffer[0], mGetPositionBuffer[1]);
}
 
Example #23
Source File: RadarChart.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
protected float[] getMarkerPosition(Entry e, Highlight highlight) {

    float angle = getSliceAngle() * e.getXIndex() + getRotationAngle();
    float val = e.getVal() * getFactor();
    PointF c = getCenterOffsets();

    PointF p = new PointF((float) (c.x + val * Math.cos(Math.toRadians(angle))),
            (float) (c.y + val * Math.sin(Math.toRadians(angle))));

    return new float[]{
            p.x, p.y
    };
}
 
Example #24
Source File: LineChartRenderer.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
/**
 * Generates a path that is used for filled drawing.
 *
 * @param dataSet    The dataset from which to read the entries.
 * @param startIndex The index from which to start reading the dataset
 * @param endIndex   The index from which to stop reading the dataset
 * @param outputPath The path object that will be assigned the chart data.
 * @return
 */
private void generateFilledPath(final ILineDataSet dataSet, final int startIndex, final int endIndex, final Path outputPath) {

    final float fillMin = dataSet.getFillFormatter().getFillLinePosition(dataSet, mChart);
    final float phaseY = mAnimator.getPhaseY();
    final boolean isDrawSteppedEnabled = dataSet.getMode() == LineDataSet.Mode.STEPPED;

    final Path filled = outputPath;
    filled.reset();

    final Entry entry = dataSet.getEntryForIndex(startIndex);

    filled.moveTo(entry.getX(), fillMin);
    filled.lineTo(entry.getX(), entry.getY() * phaseY);

    // create a new path
    Entry currentEntry = null;
    Entry previousEntry = entry;
    for (int x = startIndex + 1; x <= endIndex; x++) {

        currentEntry = dataSet.getEntryForIndex(x);

        if (isDrawSteppedEnabled) {
            filled.lineTo(currentEntry.getX(), previousEntry.getY() * phaseY);
        }

        filled.lineTo(currentEntry.getX(), currentEntry.getY() * phaseY);

        previousEntry = currentEntry;
    }

    // close up
    if (currentEntry != null) {
        filled.lineTo(currentEntry.getX(), fillMin);
    }

    filled.close();
}
 
Example #25
Source File: PerformanceLineChart.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
private void setData(int count, float range) {

        ArrayList<Entry> values = new ArrayList<>();

        for (int i = 0; i < count; i++) {
            float val = (float) (Math.random() * (range + 1)) + 3;
            values.add(new Entry(i * 0.001f, val));
        }

        // create a dataset and give it a type
        LineDataSet set1 = new LineDataSet(values, "DataSet 1");

        set1.setColor(Color.BLACK);
        set1.setLineWidth(0.5f);
        set1.setDrawValues(false);
        set1.setDrawCircles(false);
        set1.setMode(LineDataSet.Mode.LINEAR);
        set1.setDrawFilled(false);

        // create a data object with the data sets
        LineData data = new LineData(set1);

        // set data
        chart.setData(data);

        // get the legend (only possible after setting data)
        Legend l = chart.getLegend();
        l.setEnabled(false);
    }
 
Example #26
Source File: Chart.java    From Notification-Analyser with MIT License 5 votes vote down vote up
/**
 * Transforms an arraylist of Entry into a float array containing the x and
 * y values transformed with all matrices for the BARCHART.
 * 
 * @param entries
 * @param dataSet the dataset index
 * @return
 */
protected float[] generateTransformedValuesBarChart(ArrayList<? extends Entry> entries,
        int dataSet) {

    float[] valuePoints = new float[entries.size() * 2];

    int setCount = mOriginalData.getDataSetCount();
    BarData bd = (BarData) mOriginalData;
    float space = bd.getGroupSpace();

    for (int j = 0; j < valuePoints.length; j += 2) {

        Entry e = entries.get(j / 2);

        // calculate the x-position, depending on datasetcount
        float x = e.getXIndex() + (j / 2 * (setCount - 1)) + dataSet + 0.5f + space * (j / 2)
                + space / 2f;
        float y = e.getVal();

        valuePoints[j] = x;
        valuePoints[j + 1] = y * mPhaseY;
    }

    transformPointArray(valuePoints);

    return valuePoints;
}
 
Example #27
Source File: MarkerView.java    From android-kline with Apache License 2.0 5 votes vote down vote up
@Override
public void refreshContent(Entry e, Highlight highlight) {

    measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    layout(0, 0, getMeasuredWidth(), getMeasuredHeight());

}
 
Example #28
Source File: RecordingFragment.java    From go-bees with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Configure wind chart and the data.
 *
 * @param meteo meteo records.
 */
private void setupWindChart(List<MeteoRecord> meteo) {
    // Setup data
    List<Entry> entries = new ArrayList<>();
    // Add as first entry a copy of the first wind record
    // First relative timestamp is 0
    entries.add(new Entry(0, (float) meteo.get(0).getWindSpeed()));
    // Add all wind records
    float maxWind = Float.MIN_VALUE;
    for (MeteoRecord meteoRecord : meteo) {
        // Convert timestamp to seconds and relative to first timestamp
        long timestamp = meteoRecord.getTimestamp().getTime() / 1000 - referenceTimestamp;
        float wind = (float) meteoRecord.getWindSpeed();
        entries.add(new Entry(timestamp, wind));
        // Get max and min temperature
        if (wind > maxWind) {
            maxWind = wind;
        }
    }
    // Add as last entry a copy of the last wind record
    entries.add(new Entry(lastTimestamp, (float) meteo.get(meteo.size() - 1).getWindSpeed()));
    // Style char lines (type, color, etc.)
    WindValueFormatter windValueFormatter = new WindValueFormatter(WindValueFormatter.Unit.MS);
    windChart.setData(new LineData(
            configureWeatherChart(windChart, R.string.wind,
                    R.color.colorLineWindChart, R.color.colorFillWindChart,
                    entries, windValueFormatter, 0, maxWind + 5)
    ));
}
 
Example #29
Source File: MiniDateGraph.java    From fastnfitness with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private String arrayToString(ArrayList<Entry> entries) {
    StringBuilder output = new StringBuilder();
    String delimiter = "\n"; // Can be new line \n tab \t etc...
    for (int i = 0; i < entries.size(); i++) {
        output.append(entries.get(i).getY()).append(" / ").append(entries.get(i).getX()).append(delimiter);
    }

    return output.toString();
}
 
Example #30
Source File: BarLineScatterCandleBubbleRenderer.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
/**
 * Calculates the minimum and maximum x values as well as the range between them.
 *
 * @param chart
 * @param dataSet
 */
public void set(BarLineScatterCandleBubbleDataProvider chart, IBarLineScatterCandleBubbleDataSet dataSet) {
    float phaseX = Math.max(0.f, Math.min(1.f, mAnimator.getPhaseX()));

    float low = chart.getLowestVisibleX();
    float high = chart.getHighestVisibleX();

    Entry entryFrom = dataSet.getEntryForXValue(low, Float.NaN, DataSet.Rounding.DOWN);
    Entry entryTo = dataSet.getEntryForXValue(high, Float.NaN, DataSet.Rounding.UP);

    min = entryFrom == null ? 0 : dataSet.getEntryIndex(entryFrom);
    max = entryTo == null ? 0 : dataSet.getEntryIndex(entryTo);
    range = (int) ((max - min) * phaseX);
}