Search in sources :

Example 1 with PercentFormatter

use of com.github.mikephil.charting.formatter.PercentFormatter in project MPAndroidChart by PhilJay.

the class RealmBaseActivity method styleData.

protected void styleData(ChartData data) {
    data.setValueTypeface(mTf);
    data.setValueTextSize(8f);
    data.setValueTextColor(Color.DKGRAY);
    data.setValueFormatter(new PercentFormatter());
}
Also used : PercentFormatter(com.github.mikephil.charting.formatter.PercentFormatter)

Example 2 with PercentFormatter

use of com.github.mikephil.charting.formatter.PercentFormatter in project MPAndroidChart by PhilJay.

the class RealmBaseActivity method setup.

protected void setup(Chart<?> chart) {
    mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
    // no description text
    chart.getDescription().setEnabled(false);
    // enable touch gestures
    chart.setTouchEnabled(true);
    if (chart instanceof BarLineChartBase) {
        BarLineChartBase mChart = (BarLineChartBase) chart;
        mChart.setDrawGridBackground(false);
        // enable scaling and dragging
        mChart.setDragEnabled(true);
        mChart.setScaleEnabled(true);
        // if disabled, scaling can be done on x- and y-axis separately
        mChart.setPinchZoom(false);
        YAxis leftAxis = mChart.getAxisLeft();
        // reset all limit lines to avoid overlapping lines
        leftAxis.removeAllLimitLines();
        leftAxis.setTypeface(mTf);
        leftAxis.setTextSize(8f);
        leftAxis.setTextColor(Color.DKGRAY);
        leftAxis.setValueFormatter(new PercentFormatter());
        XAxis xAxis = mChart.getXAxis();
        xAxis.setTypeface(mTf);
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        xAxis.setTextSize(8f);
        xAxis.setTextColor(Color.DKGRAY);
        mChart.getAxisRight().setEnabled(false);
    }
}
Also used : PercentFormatter(com.github.mikephil.charting.formatter.PercentFormatter) BarLineChartBase(com.github.mikephil.charting.charts.BarLineChartBase) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Example 3 with PercentFormatter

use of com.github.mikephil.charting.formatter.PercentFormatter in project MPAndroidChart by PhilJay.

the class PiePolylineChartActivity method setData.

private void setData(int count, float range) {
    float mult = range;
    ArrayList<PieEntry> entries = new ArrayList<PieEntry>();
    // the chart.
    for (int i = 0; i < count; i++) {
        entries.add(new PieEntry((float) (Math.random() * mult) + mult / 5, mParties[i % mParties.length]));
    }
    PieDataSet dataSet = new PieDataSet(entries, "Election Results");
    dataSet.setSliceSpace(3f);
    dataSet.setSelectionShift(5f);
    // add a lot of colors
    ArrayList<Integer> colors = new ArrayList<Integer>();
    for (int c : ColorTemplate.VORDIPLOM_COLORS) colors.add(c);
    for (int c : ColorTemplate.JOYFUL_COLORS) colors.add(c);
    for (int c : ColorTemplate.COLORFUL_COLORS) colors.add(c);
    for (int c : ColorTemplate.LIBERTY_COLORS) colors.add(c);
    for (int c : ColorTemplate.PASTEL_COLORS) colors.add(c);
    colors.add(ColorTemplate.getHoloBlue());
    dataSet.setColors(colors);
    //dataSet.setSelectionShift(0f);
    dataSet.setValueLinePart1OffsetPercentage(80.f);
    dataSet.setValueLinePart1Length(0.2f);
    dataSet.setValueLinePart2Length(0.4f);
    //dataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
    dataSet.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
    PieData data = new PieData(dataSet);
    data.setValueFormatter(new PercentFormatter());
    data.setValueTextSize(11f);
    data.setValueTextColor(Color.BLACK);
    data.setValueTypeface(tf);
    mChart.setData(data);
    // undo all highlights
    mChart.highlightValues(null);
    mChart.invalidate();
}
Also used : PercentFormatter(com.github.mikephil.charting.formatter.PercentFormatter) PieEntry(com.github.mikephil.charting.data.PieEntry) PieDataSet(com.github.mikephil.charting.data.PieDataSet) ArrayList(java.util.ArrayList) PieData(com.github.mikephil.charting.data.PieData)

Example 4 with PercentFormatter

use of com.github.mikephil.charting.formatter.PercentFormatter in project MPAndroidChart by PhilJay.

the class HalfPieChartActivity method setData.

private void setData(int count, float range) {
    ArrayList<PieEntry> values = new ArrayList<PieEntry>();
    for (int i = 0; i < count; i++) {
        values.add(new PieEntry((float) ((Math.random() * range) + range / 5), mParties[i % mParties.length]));
    }
    PieDataSet dataSet = new PieDataSet(values, "Election Results");
    dataSet.setSliceSpace(3f);
    dataSet.setSelectionShift(5f);
    dataSet.setColors(ColorTemplate.MATERIAL_COLORS);
    //dataSet.setSelectionShift(0f);
    PieData data = new PieData(dataSet);
    data.setValueFormatter(new PercentFormatter());
    data.setValueTextSize(11f);
    data.setValueTextColor(Color.WHITE);
    data.setValueTypeface(mTfLight);
    mChart.setData(data);
    mChart.invalidate();
}
Also used : PercentFormatter(com.github.mikephil.charting.formatter.PercentFormatter) PieEntry(com.github.mikephil.charting.data.PieEntry) PieDataSet(com.github.mikephil.charting.data.PieDataSet) ArrayList(java.util.ArrayList) PieData(com.github.mikephil.charting.data.PieData) Point(android.graphics.Point)

Example 5 with PercentFormatter

use of com.github.mikephil.charting.formatter.PercentFormatter in project MPAndroidChart by PhilJay.

the class PieChartActivity method setData.

private void setData(int count, float range) {
    float mult = range;
    ArrayList<PieEntry> entries = new ArrayList<PieEntry>();
    // the chart.
    for (int i = 0; i < count; i++) {
        entries.add(new PieEntry((float) ((Math.random() * mult) + mult / 5), mParties[i % mParties.length], getResources().getDrawable(R.drawable.star)));
    }
    PieDataSet dataSet = new PieDataSet(entries, "Election Results");
    dataSet.setDrawIcons(false);
    dataSet.setSliceSpace(3f);
    dataSet.setIconsOffset(new MPPointF(0, 40));
    dataSet.setSelectionShift(5f);
    // add a lot of colors
    ArrayList<Integer> colors = new ArrayList<Integer>();
    for (int c : ColorTemplate.VORDIPLOM_COLORS) colors.add(c);
    for (int c : ColorTemplate.JOYFUL_COLORS) colors.add(c);
    for (int c : ColorTemplate.COLORFUL_COLORS) colors.add(c);
    for (int c : ColorTemplate.LIBERTY_COLORS) colors.add(c);
    for (int c : ColorTemplate.PASTEL_COLORS) colors.add(c);
    colors.add(ColorTemplate.getHoloBlue());
    dataSet.setColors(colors);
    //dataSet.setSelectionShift(0f);
    PieData data = new PieData(dataSet);
    data.setValueFormatter(new PercentFormatter());
    data.setValueTextSize(11f);
    data.setValueTextColor(Color.WHITE);
    data.setValueTypeface(mTfLight);
    mChart.setData(data);
    // undo all highlights
    mChart.highlightValues(null);
    mChart.invalidate();
}
Also used : PercentFormatter(com.github.mikephil.charting.formatter.PercentFormatter) PieEntry(com.github.mikephil.charting.data.PieEntry) PieDataSet(com.github.mikephil.charting.data.PieDataSet) MPPointF(com.github.mikephil.charting.utils.MPPointF) ArrayList(java.util.ArrayList) PieData(com.github.mikephil.charting.data.PieData)

Aggregations

PercentFormatter (com.github.mikephil.charting.formatter.PercentFormatter)6 PieData (com.github.mikephil.charting.data.PieData)3 PieDataSet (com.github.mikephil.charting.data.PieDataSet)3 PieEntry (com.github.mikephil.charting.data.PieEntry)3 ArrayList (java.util.ArrayList)3 Point (android.graphics.Point)1 BarLineChartBase (com.github.mikephil.charting.charts.BarLineChartBase)1 Legend (com.github.mikephil.charting.components.Legend)1 XAxis (com.github.mikephil.charting.components.XAxis)1 YAxis (com.github.mikephil.charting.components.YAxis)1 MPPointF (com.github.mikephil.charting.utils.MPPointF)1