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

The following examples show how to use com.github.mikephil.charting.data.Entry. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: Bluefruit_LE_Connect_Android_V2   Source File: PlotterFragment.java    License: 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 2
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 3
Source Project: Stayfit   Source File: Approximator.java    License: 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 4
/**
 * 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 5
/**
 * 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 6
Source Project: NetKnight   Source File: Approximator.java    License: 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 7
Source Project: Synapse   Source File: ModelDetailActivity.java    License: 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 8
Source Project: StockChart-MPAndroidChart   Source File: KLineDataManage.java    License: 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 9
@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 Project: StockChart-MPAndroidChart   Source File: SimpleFragment.java    License: 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 11
Source Project: Ticket-Analysis   Source File: StackedValueFormatter.java    License: 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 12
Source Project: Stayfit   Source File: Approximator.java    License: 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 13
Source Project: StockChart-MPAndroidChart   Source File: KLineDataManage.java    License: 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
@Override
protected void initData() {
    //给上面的X、Y轴数据源做假数据测试
    for (int i = 0; i < 20; i++) {
        float mult = 30 / 2f;
        float val = (float) (Math.random() * mult) + 50;
        yDataList.add(new Entry(i, val));
    }
    //显示图表,参数( 上下文,图表对象数据,图表标题,曲线图例名称,坐标点击弹出提示框中数字单位)
    ChartUtil.showChart(this, mChart, yDataList, "", "", "");

    showProgress();
    presenter.getSparklinesData();


    mPostChainHistoryBean.setFrom(mCoinUserNumber.getText().toString());
    mPostChainHistoryBean.setTo(mCoinUserNumber.getText().toString());
    mPostChainHistoryBean.setPage(page);
    mPostChainHistoryBean.setPageSize(size);
    List<PostChainHistoryBean.SymbolsBean> symbolsBeans = new ArrayList<>();
    PostChainHistoryBean.SymbolsBean symbolsBeanEos = new PostChainHistoryBean.SymbolsBean();
    symbolsBeanEos.setSymbolName("EOS");
    symbolsBeanEos.setContractName(com.oraclechain.pocketeos.base.Constants.EOSCONTRACT);
    PostChainHistoryBean.SymbolsBean symbolsBeanOCT = new PostChainHistoryBean.SymbolsBean();
    symbolsBeanOCT.setSymbolName("OCT");
    symbolsBeanOCT.setContractName(com.oraclechain.pocketeos.base.Constants.OCTCONTRACT);
    symbolsBeans.add(symbolsBeanEos);
    symbolsBeans.add(symbolsBeanOCT);
    mPostChainHistoryBean.setSymbols(symbolsBeans);
    presenter.getTransferHistoryData(mPostChainHistoryBean);


    mHistoryAdapter = new EmptyWrapper(AdapterManger.getCoinDetailsHistoryAdapter(this, mDataBeanList, mCoinUserNumber.getText().toString()));
    mHistoryAdapter.setEmptyView(R.layout.empty_project);

    mRecycleCoinHistory.setAdapter(mHistoryAdapter);

}
 
Example 15
Source Project: Ticket-Analysis   Source File: Chart.java    License: MIT License 5 votes vote down vote up
/**
 * draws all MarkerViews on the highlighted positions
 */
protected void drawMarkers(Canvas canvas) {

    // if there is no marker view or drawing marker is disabled
    if (mMarker == null || !isDrawMarkersEnabled() || !valuesToHighlight())
        return;

    for (int i = 0; i < mIndicesToHighlight.length; i++) {

        Highlight highlight = mIndicesToHighlight[i];

        IDataSet set = mData.getDataSetByIndex(highlight.getDataSetIndex());

        Entry e = mData.getEntryForHighlight(mIndicesToHighlight[i]);
        int entryIndex = set.getEntryIndex(e);

        // make sure entry not null
        if (e == null || entryIndex > set.getEntryCount() * mAnimator.getPhaseX())
            continue;

        float[] pos = getMarkerPosition(highlight);

        // check bounds
        if (!mViewPortHandler.isInBounds(pos[0], pos[1]))
            continue;

        // callbacks to update the content
        mMarker.refreshContent(e, highlight);

        // draw the marker
        mMarker.draw(canvas, pos[0], pos[1]);
    }
}
 
Example 16
Source Project: Ticket-Analysis   Source File: DataMarkView.java    License: MIT License 5 votes vote down vote up
@Override
    public void refreshContent(Entry e, Highlight highlight) {
//        if (e instanceof CandleEntry) {
//            CandleEntry ce = (CandleEntry) e;
////            tvContent.setText(Utils.formatNumber(ce.getHigh() * multiply, digits, true) + unit);
//        } else {
//            tvContent.setText(e.getX() + unit + ":" + e.getY());
//        }
        tvContent.setText(iDataValueFormat.format(e, highlight));
    }
 
Example 17
Source Project: iMoney   Source File: PieChart.java    License: 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 18
Source Project: iMoney   Source File: Transformer.java    License: 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 19
Source Project: Stayfit   Source File: ListViewMultiChartActivity.java    License: 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 20
Source Project: memorize   Source File: StatisticActivity.java    License: MIT License 5 votes vote down vote up
private LineData generateDataLine(int cnt) {

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

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

        LineDataSet d1 = new LineDataSet(values1, "New DataSet " + cnt + ", (1)");
        d1.setLineWidth(2.5f);
        d1.setCircleRadius(4.5f);
        d1.setHighLightColor(Color.rgb(244, 117, 117));
        d1.setDrawValues(false);

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

        for (int i = 0; i < 12; i++) {
            values2.add(new Entry(i, values1.get(i).getY() - 30));
        }

        LineDataSet d2 = new LineDataSet(values2, "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<>();
        sets.add(d1);
        sets.add(d2);

        return new LineData(sets);
    }
 
Example 21
Source Project: Ticket-Analysis   Source File: Transformer.java    License: 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 22
Source Project: Stayfit   Source File: LineChartActivityColored.java    License: Apache License 2.0 5 votes vote down vote up
private LineData getData(int count, float range) {

        ArrayList<String> xVals = new ArrayList<String>();
        for (int i = 0; i < count; i++) {
            xVals.add(mMonths[i % 12]);
        }

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

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

        // create a dataset and give it a type
        LineDataSet set1 = new LineDataSet(yVals, "DataSet 1");
        // set1.setFillAlpha(110);
        // set1.setFillColor(Color.RED);

        set1.setLineWidth(1.75f);
        set1.setCircleRadius(3f);
        set1.setColor(Color.WHITE);
        set1.setCircleColor(Color.WHITE);
        set1.setHighLightColor(Color.WHITE);
        set1.setDrawValues(false);

        ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
        dataSets.add(set1); // add the datasets

        // create a data object with the datasets
        LineData data = new LineData(xVals, dataSets);

        return data;
    }
 
Example 23
Source Project: NoiseCapture   Source File: Results.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void setRNEData(List<Double> classRangeValue) {
    ArrayList<Entry> yVals1 = new ArrayList<Entry>();

    // IMPORTANT: In a PieChart, no values (Entry) should have the same
    // xIndex (even if from different DataSets), since no values can be
    // drawn above each other.
    catNE= getResources().getStringArray(R.array.catNE_list_array);
    ArrayList<String> xVals = new ArrayList<String>();
    double maxValue = 0;
    int maxClassId = 0;
    for (int idEntry = 0; idEntry < classRangeValue.size(); idEntry++) {
        float value = classRangeValue.get(classRangeValue.size() - 1 - idEntry).floatValue();
        // Fix background color issue if the pie is too thin
        if(value < 0.01) {
            value = 0;
        }
        yVals1.add(new Entry(value, idEntry));
        xVals.add(catNE[idEntry]);
        if (value > maxValue) {
            maxClassId = idEntry;
            maxValue = value;
        }
    }

    PieDataSet dataSet = new PieDataSet(yVals1,Results.this.getString(R.string.caption_SL));
    dataSet.setSliceSpace(3f);
    dataSet.setColors(NE_COLORS);

    PieData data = new PieData(xVals, dataSet);
    data.setValueFormatter(new CustomPercentFormatter());
    data.setValueTextSize(8f);
    data.setValueTextColor(Color.BLACK);
    rneChart.setData(data);

    // highlight the maximum value of the RNE
    // Find the maximum of the array, in order to be highlighted
    Highlight h = new Highlight(maxClassId, 0);
    rneChart.highlightValues(new Highlight[] { h });
    rneChart.invalidate();
}
 
Example 24
Source Project: Aria2App   Source File: PeerSheet.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void update(@NonNull Peer peer) {
    LineData data = chart.getLineData();
    if (data != null) {
        int pos = data.getEntryCount() + 1;
        data.addEntry(new Entry(pos, peer.downloadSpeed), Utils.CHART_DOWNLOAD_SET);
        data.addEntry(new Entry(pos, peer.uploadSpeed), Utils.CHART_UPLOAD_SET);
        data.notifyDataChanged();
        chart.notifyDataSetChanged();
        chart.setVisibleXRangeMaximum(60);
        chart.moveViewToX(data.getEntryCount());
    }

    seeder.setHtml(R.string.seeder, String.valueOf(peer.seeder));
    peerChoking.setHtml(R.string.peerChoking, String.valueOf(peer.peerChoking));
    amChoking.setHtml(R.string.amChoking, String.valueOf(peer.amChoking));
    downloadSpeed.setText(CommonUtils.speedFormatter(peer.downloadSpeed, false));
    uploadSpeed.setText(CommonUtils.speedFormatter(peer.uploadSpeed, false));
    bitfield.update(peer.bitfield, numPieces);

    int knownPieces = BitfieldVisualizer.knownPieces(peer.bitfield, numPieces);
    health.setHtml(R.string.health, ((float) knownPieces / (float) numPieces) * 100f, knownPieces, numPieces);

    PeerIdParser.Parsed parsed = peer.peerId();
    if (parsed == null)
        peerId.setHtml(R.string.peerId, getString(R.string.unknown).toLowerCase());
    else
        peerId.setHtml(R.string.peerId, parsed.toString());
}
 
Example 25
Source Project: octoandroid   Source File: TempLineDataSet.java    License: 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 26
/***
 * 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 27
Source Project: StockChart-MPAndroidChart   Source File: BarLineChartBase.java    License: 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 28
Source Project: NetKnight   Source File: RadarChart.java    License: 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 29
Source Project: StockChart-MPAndroidChart   Source File: PerformanceLineChart.java    License: 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 30
Source Project: android-kline   Source File: MarkerView.java    License: 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());

}