当前位置: 首页>>代码示例>>Java>>正文


Java ValueFormatter类代码示例

本文整理汇总了Java中com.github.mikephil.charting.formatter.ValueFormatter的典型用法代码示例。如果您正苦于以下问题:Java ValueFormatter类的具体用法?Java ValueFormatter怎么用?Java ValueFormatter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ValueFormatter类属于com.github.mikephil.charting.formatter包,在下文中一共展示了ValueFormatter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: drawValue

import com.github.mikephil.charting.formatter.ValueFormatter; //导入依赖的package包/类
/**
 * 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, ValueFormatter formatter, float value, Entry entry,
                      int dataSetIndex, float x, float y) {
    // 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);
}
 
开发者ID:aricneto,项目名称:TwistyTimer,代码行数:33,代码来源:OffsetValuesLineChartRenderer.java

示例2: setValueFormatter

import com.github.mikephil.charting.formatter.ValueFormatter; //导入依赖的package包/类
@Override
public void setValueFormatter(ValueFormatter f) {

    if (f == null)
        return;
    else
        mValueFormatter = f;
}
 
开发者ID:rahulmaddineni,项目名称:Stayfit,代码行数:9,代码来源:BaseDataSet.java

示例3: setValueFormatter

import com.github.mikephil.charting.formatter.ValueFormatter; //导入依赖的package包/类
/**
 * Sets a custom ValueFormatter for all DataSets this data object contains.
 *
 * @param f
 */
public void setValueFormatter(ValueFormatter f) {
    if (f == null)
        return;
    else {
        for (IDataSet set : mDataSets) {
            set.setValueFormatter(f);
        }
    }
}
 
开发者ID:rahulmaddineni,项目名称:Stayfit,代码行数:15,代码来源:ChartData.java

示例4: needsDefaultFormatter

import com.github.mikephil.charting.formatter.ValueFormatter; //导入依赖的package包/类
/**
 * If this component has no ValueFormatter or is only equipped with the
 * default one (no custom set), return true.
 *
 * @return
 */
public static boolean needsDefaultFormatter(ValueFormatter formatter) {
    if (formatter == null)
        return true;
    if (formatter instanceof DefaultValueFormatter)
        return true;

    return false;
}
 
开发者ID:rahulmaddineni,项目名称:Stayfit,代码行数:15,代码来源:Utils.java

示例5: setValueFormatter

import com.github.mikephil.charting.formatter.ValueFormatter; //导入依赖的package包/类
/**
 * Sets a custom ValueFormatter for all DataSets this data object contains.
 *
 * @param f
 */
public void setValueFormatter(ValueFormatter f) {
    if (f == null)
        return;
    else {
        for (DataSet<?> set : mDataSets) {
            set.setValueFormatter(f);
        }
    }
}
 
开发者ID:xinpengfei520,项目名称:P2P,代码行数:15,代码来源:ChartData.java

示例6: setValueFormatter

import com.github.mikephil.charting.formatter.ValueFormatter; //导入依赖的package包/类
/**
 * Sets a custom ValueFormatter for all DataSets this data object contains.
 *
 * @param f
 */
public void setValueFormatter(ValueFormatter f) {
    if (f == null)
        return;
    else {

        for (int i = 0; i < mDataSets.size(); i++) {
            T set = mDataSets.get(i);
            set.setValueFormatter(f);
        }
    }
}
 
开发者ID:letolab,项目名称:LETO-Toggl_Android,代码行数:17,代码来源:ChartData.java

示例7: needsDefaultFormatter

import com.github.mikephil.charting.formatter.ValueFormatter; //导入依赖的package包/类
/**
 * If this component has no ValueFormatter or is only equipped with the
 * default one (no custom set), return true.
 *
 * @return
 */
public static boolean needsDefaultFormatter(ValueFormatter formatter) {
    if (formatter == null)
        return true;
    return formatter instanceof DefaultValueFormatter;

}
 
开发者ID:muyoumumumu,项目名称:QuShuChe,代码行数:13,代码来源:Utils.java

示例8: setData

import com.github.mikephil.charting.formatter.ValueFormatter; //导入依赖的package包/类
private void setData(PieChart mChart, Station station) {

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

        float inactive = (float) Integer.parseInt(station.getNumberBases()) - Integer.parseInt(station.getBasesFree()) - Integer.parseInt(station.getBikeEngaged());

        yVals1.add(new Entry(Float.parseFloat(station.getBasesFree()), 0));
        yVals1.add(new Entry(Float.parseFloat(station.getBikeEngaged()), 1));
        yVals1.add(new Entry(inactive, 2));

        ArrayList<String> xVals = new ArrayList<String>();

        for (int i = 0; i < mParties.length + 1; i++)
            xVals.add(mParties[i % mParties.length]);

        PieDataSet dataSet = new PieDataSet(yVals1, getString(R.string.base_state));
        dataSet.setSliceSpace(2f);
        dataSet.setSelectionShift(5f);

        ArrayList<Integer> colors = new ArrayList<Integer>();
        colors.add(ContextCompat.getColor(getActivity(), R.color.red_chart));
        colors.add(ContextCompat.getColor(getActivity(), R.color.green_chart));
        colors.add(ContextCompat.getColor(getActivity(), R.color.gray_chart));

        dataSet.setColors(colors);

        PieData data = new PieData(xVals, dataSet);
        data.setValueFormatter(new ValueFormatter() {
            @Override
            public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
                return "" + (int) value;
            }
        });
        data.setValueTextSize(11f);
        data.setValueTextColor(Color.BLACK);
        mChart.setData(data);

        mChart.highlightValues(null);

        mChart.invalidate();
    }
 
开发者ID:Mun0n,项目名称:MADBike,代码行数:42,代码来源:MapFragment.java

示例9: setData

import com.github.mikephil.charting.formatter.ValueFormatter; //导入依赖的package包/类
private void setData(Station station) {

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

        float inactive = (float) Integer.parseInt(station.getNumberBases()) - Integer.parseInt(station.getBasesFree()) - Integer.parseInt(station.getBikeEngaged());

        yVals1.add(new Entry(Float.parseFloat(station.getBasesFree()), 0));
        yVals1.add(new Entry(Float.parseFloat(station.getBikeEngaged()), 1));
        yVals1.add(new Entry(inactive, 2));

        ArrayList<String> xVals = new ArrayList<String>();
        mParties = context.getResources().getStringArray(R.array.states_values);
        for (int i = 0; i < mParties.length + 1; i++)
            xVals.add(mParties[i % mParties.length]);

        PieDataSet dataSet = new PieDataSet(yVals1, context.getString(R.string.base_state));
        dataSet.setSliceSpace(2f);
        dataSet.setSelectionShift(5f);

        ArrayList<Integer> colors = new ArrayList<Integer>();
        colors.add(ContextCompat.getColor(context, R.color.red_chart));
        colors.add(ContextCompat.getColor(context, R.color.green_chart));
        colors.add(ContextCompat.getColor(context, R.color.gray_chart));

        dataSet.setColors(colors);

        PieData data = new PieData(xVals, dataSet);
        data.setValueFormatter(new ValueFormatter() {
            @Override
            public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
                return "" + (int) value;
            }
        });
        data.setValueTextSize(11f);
        data.setValueTextColor(Color.BLACK);
        mChart.setData(data);

        mChart.highlightValues(null);

        mChart.invalidate();
    }
 
开发者ID:Mun0n,项目名称:MADBike,代码行数:42,代码来源:StationHolder.java

示例10: getValueFormatter

import com.github.mikephil.charting.formatter.ValueFormatter; //导入依赖的package包/类
@Override
public ValueFormatter getValueFormatter() {
    if (mValueFormatter == null)
        return new DefaultValueFormatter(1);
    return mValueFormatter;
}
 
开发者ID:rahulmaddineni,项目名称:Stayfit,代码行数:7,代码来源:BaseDataSet.java

示例11: getValueFormatter

import com.github.mikephil.charting.formatter.ValueFormatter; //导入依赖的package包/类
/**
 * Returns the formatter used for drawing the values inside the chart.
 *
 * @return
 */
public ValueFormatter getValueFormatter() {
    if (mValueFormatter == null)
        return new DefaultValueFormatter(1);
    return mValueFormatter;
}
 
开发者ID:xinpengfei520,项目名称:P2P,代码行数:11,代码来源:DataSet.java

示例12: getValueFormatter

import com.github.mikephil.charting.formatter.ValueFormatter; //导入依赖的package包/类
@Override
public ValueFormatter getValueFormatter() {
    if (needsFormatter())
        return new DefaultValueFormatter(1);
    return mValueFormatter;
}
 
开发者ID:letolab,项目名称:LETO-Toggl_Android,代码行数:7,代码来源:BaseDataSet.java

示例13: setChartView

import com.github.mikephil.charting.formatter.ValueFormatter; //导入依赖的package包/类
private void setChartView() {
    chart.setNoDataText("绩点信息");
    chart.setDescription("");
    ArrayList<Entry> vals = new ArrayList<>();
    ArrayList<String> xVals = new ArrayList<>();
    for (int i = 0; i < ResourceManager.getInstance().getGPATable().semesters.size(); i++) {
        vals.add(new Entry(ResourceManager.getInstance().getGPATable().semesters.get(i).semaster_gpa, i));
        xVals.add("Sem." + (i + 1));
    }
    textGpaAvg.setText("总平均绩点:" + ResourceManager.getInstance().getGPATable().total_gpa);

    LineDataSet dataSet = new LineDataSet(vals, "GPA");
    dataSet.setAxisDependency(YAxis.AxisDependency.LEFT);

    ArrayList<ILineDataSet> dataSets = new ArrayList<>();
    dataSets.add(dataSet);

    LineData data = new LineData(xVals, dataSets);
    data.setValueTextColor(Color.WHITE);
    data.setValueFormatter(new ValueFormatter() {
        @Override
        public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
            return String.valueOf(value);
        }
    });
    data.setValueTextSize(12);
    dataSet.setDrawCircleHole(true);
    dataSet.setCircleColorHole(ContextCompat.getColor(MainActivity.getContext(), R.color.home_gpa_table_background));
    dataSet.setDrawCubic(true);
    dataSet.setDrawFilled(true);
    dataSet.setFillDrawable(ContextCompat.getDrawable(MainActivity.getContext(), R.drawable.gpa_table_bg));
    dataSet.setLineWidth(1.5f);

    XAxis xAxis = chart.getXAxis();
    YAxis left = chart.getAxisLeft();
    left.setDrawLabels(false); // no axis labels
    left.setDrawAxisLine(false); // no axis line
    left.setDrawGridLines(false); // no grid lines
    left.setDrawZeroLine(true); // draw a zero line
    left.setGridColor(Color.LTGRAY);
    chart.getAxisRight().setEnabled(false); // no right axis
    Legend legend = chart.getLegend();
    legend.setEnabled(false);

    chart.setData(data);
    chart.setTouchEnabled(false);
    chart.setDrawGridBackground(false);
    chart.setBackgroundColor(Color.TRANSPARENT);
    chart.setDrawBorders(false);
    chart.animateY(1000, Easing.EasingOption.EaseOutBack);
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setAvoidFirstLastClipping(false);
    xAxis.setTextColor(Color.WHITE);
    xAxis.setGridColor(Color.WHITE);
    xAxis.setDrawGridLines(false);
    xAxis.setAxisLineColor(Color.TRANSPARENT);
    chart.invalidate();
}
 
开发者ID:Novemser,项目名称:iTongJi-App,代码行数:59,代码来源:RecyclerAdapter.java

示例14: setChartView

import com.github.mikephil.charting.formatter.ValueFormatter; //导入依赖的package包/类
private void setChartView() {
    chart.setNoDataText("绩点信息");
    chart.setDescription("");
    ArrayList<Entry> vals = new ArrayList<>();
    ArrayList<String> xVals = new ArrayList<>();
    for (int i = 0; i < studentGPASubject.semesters.size(); i++) {
        vals.add(new Entry(studentGPASubject.semesters.get(i).semaster_gpa, i));
        xVals.add("Sem." + (i + 1));
    }
    textGpaAvg.setText("总平均绩点:" + studentGPASubject.total_gpa);

    LineDataSet dataSet = new LineDataSet(vals, "GPA");
    dataSet.setAxisDependency(YAxis.AxisDependency.LEFT);

    ArrayList<ILineDataSet> dataSets = new ArrayList<>();
    dataSets.add(dataSet);

    LineData data = new LineData(xVals, dataSets);
    data.setValueTextColor(Color.WHITE);
    data.setValueFormatter(new ValueFormatter() {
        @Override
        public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
            return String.valueOf(value);
        }
    });
    data.setValueTextSize(12);
    dataSet.setDrawCircleHole(true);
    dataSet.setCircleColorHole(ContextCompat.getColor(MainActivity.getContext(), R.color.home_gpa_table_background));
    dataSet.setDrawCubic(true);
    dataSet.setDrawFilled(true);
    dataSet.setFillDrawable(ContextCompat.getDrawable(MainActivity.getContext(), R.drawable.gpa_table_bg));
    dataSet.setLineWidth(1.5f);

    XAxis xAxis = chart.getXAxis();
    YAxis left = chart.getAxisLeft();
    left.setDrawLabels(false); // no axis labels
    left.setDrawAxisLine(false); // no axis line
    left.setDrawGridLines(false); // no grid lines
    left.setDrawZeroLine(true); // draw a zero line
    left.setGridColor(Color.LTGRAY);
    chart.getAxisRight().setEnabled(false); // no right axis
    Legend legend = chart.getLegend();
    legend.setEnabled(false);

    chart.setData(data);
    chart.setTouchEnabled(false);
    chart.setDrawGridBackground(false);
    chart.setBackgroundColor(Color.TRANSPARENT);
    chart.setDrawBorders(false);
    chart.animateY(1000, Easing.EasingOption.EaseOutBack);
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setAvoidFirstLastClipping(false);
    xAxis.setTextColor(Color.WHITE);
    xAxis.setGridColor(Color.WHITE);
    xAxis.setDrawGridLines(false);
    xAxis.setAxisLineColor(Color.TRANSPARENT);
    chart.invalidate();
}
 
开发者ID:Novemser,项目名称:iTongJi-App,代码行数:59,代码来源:Home_Recycler_Adapter.java

示例15: setValueFormatter

import com.github.mikephil.charting.formatter.ValueFormatter; //导入依赖的package包/类
/**
 * 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
 */
public void setValueFormatter(ValueFormatter f) {

    if (f == null)
        return;
    else
        mValueFormatter = f;
}
 
开发者ID:xinpengfei520,项目名称:P2P,代码行数:17,代码来源:DataSet.java


注:本文中的com.github.mikephil.charting.formatter.ValueFormatter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。