com.github.mikephil.charting.formatter.IValueFormatter Java Examples

The following examples show how to use com.github.mikephil.charting.formatter.IValueFormatter. 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: BaseDataSet.java    From android-kline with Apache License 2.0 5 votes vote down vote up
@Override
public void setValueFormatter(IValueFormatter f) {

    if (f == null)
        return;
    else
        mValueFormatter = f;
}
 
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: OffsetValuesLineChartRenderer.java    From TwistyTimer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Overrides the default drawing position by offsetting the Y-coordinate of the default value
 * position. The value text is drawn if the data point is in bounds, so the value text may be
 * slightly out-of-bounds.
 */
@Override
public void drawValue(Canvas c, IValueFormatter formatter, float value, Entry entry, int dataSetIndex, float x, float y, int color) {
    // NOTE: The given value of "y" is calculated in "LineChartRenderer.drawValues". It is the
    // Y-coordinate for the *baseline* of the drawn text. By default, it is offset above the
    // data point based on the circle radius value (even if drawing of circles is disabled) and
    // is offset even more if drawing of circles is enabled. Setting a negative circle radius
    // actually works to reposition the text, but then the circles are not drawn.
    //
    // Therefore, choosing a value for "mValueYOffset" depends on the circle radius and whether
    // or not circles are enabled. However, because the text extends *up* from its baseline,
    // if the text is drawn below the data point, the size of the text must also be considered
    // when choosing the value of the Y offset, as larger text must be offset more to keep the
    // top of the text below the data point.
    //
    // Because the values are numeric, there are no descenders below the baseline (e.g., like
    // the descending loop of a lower-case "g"). To prevent the value text being drawn if it
    // touches or crosses the bottom horizontal axis, simply guard the call to "super.drawValue"
    // with a test of "mViewPortHandler.isInBoundsBottom(y + mValueYOffsetPX)". However, without
    // this bounds-checking, it looks quite nice: drawing the text outside the axis until the
    // point itself touches the axis. Zoom in and drag the chart around to experiment.

    // TODO: It might be worth considering if these should be painted in "reverse video" to
    // make them more readable, i.e., draw a rectangle in the "text color" and then draw the
    // text on top in a contrasting color (maybe just black or white).
    super.drawValue(c, formatter, value, entry, dataSetIndex, x, y + mValueYOffsetPX, color);
}
 
Example #4
Source File: TestCaseRunner.java    From SQLite-Performance with The Unlicense 5 votes vote down vote up
TestCaseRunner(int iterations, BarChart chart, String title, int color, IValueFormatter valueFormatter) {
    mIterations = iterations;
    mChart = chart;
    mEntries = new LinkedList<>();
    mDataSet = new BarDataSet(mEntries, title);
    mDataSet.setValueFormatter(valueFormatter);
    mDataSet.setColor(color);
}
 
Example #5
Source File: ChartData.java    From android-kline with Apache License 2.0 5 votes vote down vote up
/**
 * Sets a custom IValueFormatter for all DataSets this data object contains.
 *
 * @param f
 */
public void setValueFormatter(IValueFormatter f) {
    if (f == null)
        return;
    else {
        for (IDataSet set : mDataSets) {
            set.setValueFormatter(f);
        }
    }
}
 
Example #6
Source File: BaseDataSet.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
@Override
public void setValueFormatter(IValueFormatter f) {

    if (f == null)
        return;
    else
        mValueFormatter = f;
}
 
Example #7
Source File: ChartData.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
/**
 * Sets a custom IValueFormatter for all DataSets this data object contains.
 *
 * @param f
 */
public void setValueFormatter(IValueFormatter f) {
    if (f == null)
        return;
    else {
        for (IDataSet set : mDataSets) {
            set.setValueFormatter(f);
        }
    }
}
 
Example #8
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 #9
Source File: Utils.java    From Ticket-Analysis with MIT License 4 votes vote down vote up
private static IValueFormatter generateDefaultValueFormatter() {
    final DefaultValueFormatter formatter = new DefaultValueFormatter(1);
    return formatter;
}
 
Example #10
Source File: Utils.java    From Ticket-Analysis with MIT License 4 votes vote down vote up
public static IValueFormatter getDefaultValueFormatter()
{
    return mDefaultValueFormatter;
}
 
Example #11
Source File: BaseDataSet.java    From Ticket-Analysis with MIT License 4 votes vote down vote up
@Override
public IValueFormatter getValueFormatter() {
    if (needsFormatter())
        return Utils.getDefaultValueFormatter();
    return mValueFormatter;
}
 
Example #12
Source File: StatisticsActivity.java    From ActivityDiary with GNU General Public License v3.0 4 votes vote down vote up
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    // Swap the new cursor in.  (The framework will take care of closing the
    // old cursor once we return.)

    List<PieEntry> entries = new ArrayList<>();
    List<Integer> colors = new ArrayList<>();

    int portion_idx = data.getColumnIndex(ActivityDiaryContract.DiaryStats.PORTION);
    int name_idx = data.getColumnIndex(ActivityDiaryContract.DiaryStats.NAME);
    int col_idx = data.getColumnIndex(ActivityDiaryContract.DiaryStats.COLOR);
    int dur_idx = data.getColumnIndex(ActivityDiaryContract.DiaryStats.DURATION);

    if ((data != null) && data.moveToFirst()) {
        float acc = 0.0f;
        float acc_po = 0.0f;
        while (!data.isAfterLast()) {
            float portion = data.getFloat(portion_idx);
            long duration = data.getLong(dur_idx);
            if(portion > 3.0f){
                PieEntry ent = new PieEntry((float)duration, data.getString(name_idx));
                entries.add(ent);
                colors.add(data.getInt(col_idx));
            }else{
                // accumulate the small, not shown entries
                acc += duration;
                acc_po += portion;
            }
            data.moveToNext();
        }
        if(acc_po > 2.0f) {
            entries.add(new PieEntry(acc, getResources().getString(R.string.statistics_others)));
            colors.add(Color.GRAY);
        }
    }

    PieDataSet set = new PieDataSet(entries, getResources().getString(R.string.activities));
    PieData dat = new PieData(set);
    set.setColors(colors);

    set.setValueFormatter(new IValueFormatter() {
        @Override
        public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
            PieEntry e = (PieEntry)entry;
            return TimeSpanFormatter.format((long)e.getValue());
        }
    });
    chart.setData(dat);
    chart.setUsePercentValues(true);
    chart.setRotationAngle(180.0f);
    chart.invalidate(); // refresh

}
 
Example #13
Source File: BaseDataSet.java    From android-kline with Apache License 2.0 4 votes vote down vote up
@Override
public IValueFormatter getValueFormatter() {
    if (needsFormatter())
        return Utils.getDefaultValueFormatter();
    return mValueFormatter;
}
 
Example #14
Source File: Utils.java    From android-kline with Apache License 2.0 4 votes vote down vote up
public static IValueFormatter getDefaultValueFormatter()
{
    return mDefaultValueFormatter;
}
 
Example #15
Source File: Utils.java    From android-kline with Apache License 2.0 4 votes vote down vote up
private static IValueFormatter generateDefaultValueFormatter() {
    final DefaultValueFormatter formatter = new DefaultValueFormatter(1);
    return formatter;
}
 
Example #16
Source File: DataRenderer.java    From android-kline with Apache License 2.0 2 votes vote down vote up
/**
 * Draws the value of the given entry by using the provided IValueFormatter.
 *
 * @param c            canvas
 * @param formatter    formatter for custom value-formatting
 * @param value        the value to be drawn
 * @param entry        the entry the value belongs to
 * @param dataSetIndex the index of the DataSet the drawn Entry belongs to
 * @param x            position
 * @param y            position
 * @param color
 */
public void drawValue(Canvas c, IValueFormatter formatter, float value, Entry entry, int dataSetIndex, float x, float y, int color) {
    mValuePaint.setColor(color);
    c.drawText(formatter.getFormattedValue(value, entry, dataSetIndex, mViewPortHandler), x, y, mValuePaint);
}
 
Example #17
Source File: Chart.java    From Ticket-Analysis with MIT License 2 votes vote down vote up
/**
 * Returns the default IValueFormatter that has been determined by the chart
 * considering the provided minimum and maximum values.
 *
 * @return
 */
public IValueFormatter getDefaultValueFormatter() {
    return mDefaultValueFormatter;
}
 
Example #18
Source File: IDataSet.java    From android-kline with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the formatter used for drawing the values inside the chart.
 *
 * @return
 */
IValueFormatter getValueFormatter();
 
Example #19
Source File: IDataSet.java    From android-kline with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the formatter to be used for drawing the values inside the chart. If
 * no formatter is set, the chart will automatically determine a reasonable
 * formatting (concerning decimals) for all the values that are drawn inside
 * the chart. Use chart.getDefaultValueFormatter() to use the formatter
 * calculated by the chart.
 *
 * @param f
 */
void setValueFormatter(IValueFormatter f);
 
Example #20
Source File: DataRenderer.java    From Ticket-Analysis with MIT License 2 votes vote down vote up
/**
 * Draws the value of the given entry by using the provided IValueFormatter.
 *
 * @param c            canvas
 * @param formatter    formatter for custom value-formatting
 * @param value        the value to be drawn
 * @param entry        the entry the value belongs to
 * @param dataSetIndex the index of the DataSet the drawn Entry belongs to
 * @param x            position
 * @param y            position
 * @param color
 */
public void drawValue(Canvas c, IValueFormatter formatter, float value, Entry entry, int dataSetIndex, float x, float y, int color) {
    mValuePaint.setColor(color);
    c.drawText(formatter.getFormattedValue(value, entry, dataSetIndex, mViewPortHandler), x, y, mValuePaint);
}
 
Example #21
Source File: Chart.java    From android-kline with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the default IValueFormatter that has been determined by the chart
 * considering the provided minimum and maximum values.
 *
 * @return
 */
public IValueFormatter getDefaultValueFormatter() {
    return mDefaultValueFormatter;
}
 
Example #22
Source File: IDataSet.java    From Ticket-Analysis with MIT License 2 votes vote down vote up
/**
 * Returns the formatter used for drawing the values inside the chart.
 *
 * @return
 */
IValueFormatter getValueFormatter();
 
Example #23
Source File: IDataSet.java    From Ticket-Analysis with MIT License 2 votes vote down vote up
/**
 * Sets the formatter to be used for drawing the values inside the chart. If
 * no formatter is set, the chart will automatically determine a reasonable
 * formatting (concerning decimals) for all the values that are drawn inside
 * the chart. Use chart.getDefaultValueFormatter() to use the formatter
 * calculated by the chart.
 *
 * @param f
 */
void setValueFormatter(IValueFormatter f);
 
Example #24
Source File: ChartInterface.java    From android-kline with Apache License 2.0 votes vote down vote up
IValueFormatter getDefaultValueFormatter(); 
Example #25
Source File: ChartInterface.java    From Ticket-Analysis with MIT License votes vote down vote up
IValueFormatter getDefaultValueFormatter();