com.github.mikephil.charting.utils.EntryXComparator Java Examples

The following examples show how to use com.github.mikephil.charting.utils.EntryXComparator. 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: InvertedLineChartActivity.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
private void setData(int count, float range) {

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

        for (int i = 0; i < count; i++) {
            float xVal = (float) (Math.random() * range);
            float yVal = (float) (Math.random() * range);
            entries.add(new Entry(xVal, yVal));
        }

        // sort by x-value
        Collections.sort(entries, new EntryXComparator());

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

        set1.setLineWidth(1.5f);
        set1.setCircleRadius(4f);

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

        // set data
        chart.setData(data);
    }
 
Example #2
Source File: BarGraph.java    From fastnfitness with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void draw(List<BarEntry> entries, ArrayList<String> xAxisLabel) {
    mChart.clear();
    if (entries.isEmpty()) {
        return;
    }

    XAxis xAxis = this.mChart.getXAxis();
    xAxis.setValueFormatter(new IndexAxisValueFormatter(xAxisLabel));

    Collections.sort(entries, new EntryXComparator());

    BarDataSet set1 = new BarDataSet(entries, mChartName);
    set1.setColor(mContext.getResources().getColor(R.color.toolbar_background));

    // Create a data object with the datasets
    BarData data = new BarData(set1);

    data.setValueTextSize(12);
    data.setValueFormatter(new IValueFormatter() {
        private DecimalFormat mFormat = new DecimalFormat("#.## kg");

        @Override
        public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
            return mFormat.format(value);
        }
    });

    // Set data
    mChart.setData(data);

    mChart.getAxisLeft().setAxisMinimum(0f);

    mChart.invalidate();
}
 
Example #3
Source File: DateGraph.java    From fastnfitness with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void draw(ArrayList<Entry> entries) {
    mChart.clear();
    if (entries.isEmpty()) {
        return;
    }

    Collections.sort(entries, new EntryXComparator());

    //Log.d("DEBUG", arrayToString(entries));

    LineDataSet set1 = new LineDataSet(entries, mChartName);
    set1.setLineWidth(3f);
    set1.setCircleRadius(4f);
    set1.setDrawFilled(true);
    if (Utils.getSDKInt() >= 18) {
        // fill drawable only supported on api level 18 and above
        Drawable drawable = ContextCompat.getDrawable(mContext, R.drawable.fade_blue);
        set1.setFillDrawable(drawable);
    } else {
        set1.setFillColor(ColorTemplate.getHoloBlue());
    }
    set1.setFillAlpha(100);
    set1.setColor(mContext.getResources().getColor(R.color.toolbar_background));
    set1.setCircleColor(mContext.getResources().getColor(R.color.toolbar_background));

    // Create a data object with the datasets
    LineData data = new LineData(set1);

    data.setValueFormatter(new IValueFormatter() {
        private DecimalFormat mFormat = new DecimalFormat("#.##");

        @Override
        public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
            return mFormat.format(value);
        }
    });

    // Set data
    mChart.setData(data);

    mChart.invalidate();
    //mChart.animateY(500, Easing.EasingOption.EaseInBack);    //refresh graph

}
 
Example #4
Source File: MiniDateGraph.java    From fastnfitness with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void draw(ArrayList<Entry> entries) {
    mChart.clear();
    if (entries.isEmpty()) {
        return;
    }

    Collections.sort(entries, new EntryXComparator());

    //Log.d("DEBUG", arrayToString(entries));

    LineDataSet set1 = new LineDataSet(entries, mChartName);
    set1.setLineWidth(3f);
    set1.setCircleRadius(0f);
    set1.setDrawFilled(true);
    if (Utils.getSDKInt() >= 18) {
        // fill drawable only supported on api level 18 and above
        Drawable drawable = ContextCompat.getDrawable(mContext, R.drawable.fade_blue);
        set1.setFillDrawable(drawable);
    } else {
        set1.setFillColor(ColorTemplate.getHoloBlue());
    }
    set1.setFillAlpha(100);
    set1.setColor(mContext.getResources().getColor(R.color.toolbar_background));
    set1.setCircleColor(mContext.getResources().getColor(R.color.toolbar_background));

    // Create a data object with the datasets
    LineData data = new LineData(set1);
    data.setDrawValues(false);

    /*data.setValueFormatter(new IValueFormatter() {
        private DecimalFormat mFormat = new DecimalFormat("#.##");

        @Override
        public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
            return mFormat.format(value);
        }
    });*/

    // Set data
    mChart.setData(data);

    mChart.invalidate();
    //mChart.animateY(500, Easing.EasingOption.EaseInBack);    //refresh graph

}