Search in sources :

Example 1 with Fill

use of com.github.mikephil.charting.utils.Fill in project MPAndroidChart by PhilJay.

the class BarDataSet method setGradientColor.

/**
 * Sets the start and end color for gradient color, ONLY color that should be used for this DataSet.
 *
 * @param startColor
 * @param endColor
 */
public void setGradientColor(int startColor, int endColor) {
    mFills.clear();
    mFills.add(new Fill(startColor, endColor));
}
Also used : Fill(com.github.mikephil.charting.utils.Fill)

Example 2 with Fill

use of com.github.mikephil.charting.utils.Fill in project MPAndroidChart by PhilJay.

the class BarChartActivity method setData.

private void setData(int count, float range) {
    float start = 1f;
    ArrayList<BarEntry> values = new ArrayList<>();
    for (int i = (int) start; i < start + count; i++) {
        float val = (float) (Math.random() * (range + 1));
        if (Math.random() * 100 < 25) {
            values.add(new BarEntry(i, val, getResources().getDrawable(R.drawable.star)));
        } else {
            values.add(new BarEntry(i, val));
        }
    }
    BarDataSet set1;
    if (chart.getData() != null && chart.getData().getDataSetCount() > 0) {
        set1 = (BarDataSet) chart.getData().getDataSetByIndex(0);
        set1.setValues(values);
        chart.getData().notifyDataChanged();
        chart.notifyDataSetChanged();
    } else {
        set1 = new BarDataSet(values, "The year 2017");
        set1.setDrawIcons(false);
        int startColor1 = ContextCompat.getColor(this, android.R.color.holo_orange_light);
        int startColor2 = ContextCompat.getColor(this, android.R.color.holo_blue_light);
        int startColor3 = ContextCompat.getColor(this, android.R.color.holo_orange_light);
        int startColor4 = ContextCompat.getColor(this, android.R.color.holo_green_light);
        int startColor5 = ContextCompat.getColor(this, android.R.color.holo_red_light);
        int endColor1 = ContextCompat.getColor(this, android.R.color.holo_blue_dark);
        int endColor2 = ContextCompat.getColor(this, android.R.color.holo_purple);
        int endColor3 = ContextCompat.getColor(this, android.R.color.holo_green_dark);
        int endColor4 = ContextCompat.getColor(this, android.R.color.holo_red_dark);
        int endColor5 = ContextCompat.getColor(this, android.R.color.holo_orange_dark);
        List<Fill> gradientFills = new ArrayList<>();
        gradientFills.add(new Fill(startColor1, endColor1));
        gradientFills.add(new Fill(startColor2, endColor2));
        gradientFills.add(new Fill(startColor3, endColor3));
        gradientFills.add(new Fill(startColor4, endColor4));
        gradientFills.add(new Fill(startColor5, endColor5));
        set1.setFills(gradientFills);
        ArrayList<IBarDataSet> dataSets = new ArrayList<>();
        dataSets.add(set1);
        BarData data = new BarData(dataSets);
        data.setValueTextSize(10f);
        data.setValueTypeface(tfLight);
        data.setBarWidth(0.9f);
        chart.setData(data);
    }
}
Also used : Fill(com.github.mikephil.charting.utils.Fill) BarDataSet(com.github.mikephil.charting.data.BarDataSet) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) BarData(com.github.mikephil.charting.data.BarData) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) ArrayList(java.util.ArrayList) BarEntry(com.github.mikephil.charting.data.BarEntry)

Aggregations

Fill (com.github.mikephil.charting.utils.Fill)2 BarData (com.github.mikephil.charting.data.BarData)1 BarDataSet (com.github.mikephil.charting.data.BarDataSet)1 BarEntry (com.github.mikephil.charting.data.BarEntry)1 IBarDataSet (com.github.mikephil.charting.interfaces.datasets.IBarDataSet)1 ArrayList (java.util.ArrayList)1