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

The following examples show how to use com.github.mikephil.charting.utils.ColorTemplate. 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: RealtimeLineChartActivity.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
private LineDataSet createSet() {

        LineDataSet set = new LineDataSet(null, "Dynamic Data");
        set.setAxisDependency(AxisDependency.LEFT);
        set.setColor(ColorTemplate.getHoloBlue());
        set.setCircleColor(Color.WHITE);
        set.setLineWidth(2f);
        set.setCircleRadius(4f);
        set.setFillAlpha(65);
        set.setFillColor(ColorTemplate.getHoloBlue());
        set.setHighLightColor(Color.rgb(244, 117, 117));
        set.setValueTextColor(Color.WHITE);
        set.setValueTextSize(9f);
        set.setDrawValues(false);
        return set;
    }
 
Example #2
Source File: CombinedChartActivity.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
private BubbleData generateBubbleData() {

        BubbleData bd = new BubbleData();

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

        for (int index = 0; index < count; index++) {
            float y = getRandom(10, 105);
            float size = getRandom(100, 105);
            entries.add(new BubbleEntry(index + 0.5f, y, size));
        }

        BubbleDataSet set = new BubbleDataSet(entries, "Bubble DataSet");
        set.setColors(ColorTemplate.VORDIPLOM_COLORS);
        set.setValueTextSize(10f);
        set.setValueTextColor(Color.WHITE);
        set.setHighlightCircleWidth(1.5f);
        set.setDrawValues(true);
        bd.addDataSet(set);

        return bd;
    }
 
Example #3
Source File: ListViewMultiChartActivity.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
/**
 * generates a random ChartData object with just one DataSet
 * 
 * @return
 */
private BarData generateDataBar(int cnt) {

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

    for (int i = 0; i < 12; i++) {
        entries.add(new BarEntry((int) (Math.random() * 70) + 30, i));
    }

    BarDataSet d = new BarDataSet(entries, "New DataSet " + cnt);
    d.setBarSpacePercent(20f);
    d.setColors(ColorTemplate.VORDIPLOM_COLORS);
    d.setHighLightAlpha(255);
    
    BarData cd = new BarData(getMonths(), d);
    return cd;
}
 
Example #4
Source File: ListViewBarChartActivity.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
/**
 * generates a random ChartData object with just one DataSet
 *
 * @return Bar data
 */
private BarData generateData(int cnt) {

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

    for (int i = 0; i < 12; i++) {
        entries.add(new BarEntry(i, (float) (Math.random() * 70) + 30));
    }

    BarDataSet d = new BarDataSet(entries, "New DataSet " + cnt);
    d.setColors(ColorTemplate.VORDIPLOM_COLORS);
    d.setBarShadowColor(Color.rgb(203, 203, 203));

    ArrayList<IBarDataSet> sets = new ArrayList<>();
    sets.add(d);

    BarData cd = new BarData(sets);
    cd.setBarWidth(0.9f);
    return cd;
}
 
Example #5
Source File: RealmDatabaseActivityPie.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
private void setData() {

        RealmResults<RealmDemoData> result = mRealm.allObjects(RealmDemoData.class);

        //RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "stackValues", "xIndex"); // normal entries
        RealmPieDataSet<RealmDemoData> set = new RealmPieDataSet<RealmDemoData>(result, "value", "xIndex"); // stacked entries
        set.setColors(ColorTemplate.VORDIPLOM_COLORS);
        set.setLabel("Example market share");
        set.setSliceSpace(2);

        // create a data object with the dataset list
        RealmPieData data = new RealmPieData(result, "xValue", set);
        styleData(data);
        data.setValueTextColor(Color.WHITE);
        data.setValueTextSize(12f);

        // set data
        mChart.setData(data);
        mChart.animateY(1400);
    }
 
Example #6
Source File: SimpleFragment.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
protected LineData generateLineData() {

        ArrayList<ILineDataSet> sets = new ArrayList<>();
        LineDataSet ds1 = new LineDataSet(FileUtils.loadEntriesFromAssets(context.getAssets(), "sine.txt"), "Sine function");
        LineDataSet ds2 = new LineDataSet(FileUtils.loadEntriesFromAssets(context.getAssets(), "cosine.txt"), "Cosine function");

        ds1.setLineWidth(2f);
        ds2.setLineWidth(2f);

        ds1.setDrawCircles(false);
        ds2.setDrawCircles(false);

        ds1.setColor(ColorTemplate.VORDIPLOM_COLORS[0]);
        ds2.setColor(ColorTemplate.VORDIPLOM_COLORS[1]);

        // load DataSets from files in assets folder
        sets.add(ds1);
        sets.add(ds2);

        LineData d = new LineData(sets);
        d.setValueTypeface(tf);
        return d;
    }
 
Example #7
Source File: RealmDatabaseActivityBar.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
private void setData() {

        RealmResults<RealmDemoData> result = mRealm.allObjects(RealmDemoData.class);

        //RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "stackValues", "xIndex"); // normal entries
        RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "value", "xIndex"); // stacked entries
        set.setColors(new int[] {ColorTemplate.rgb("#FF5722"), ColorTemplate.rgb("#03A9F4")});
        set.setLabel("Realm BarDataSet");

        ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
        dataSets.add(set); // add the dataset

        // create a data object with the dataset list
        RealmBarData data = new RealmBarData(result, "xValue", dataSets);
        styleData(data);

        // set data
        mChart.setData(data);
        mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
    }
 
Example #8
Source File: SimpleFragment.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
protected ScatterData generateScatterData(int dataSets, float range, int count) {
    
    ArrayList<IScatterDataSet> sets = new ArrayList<IScatterDataSet>();
    
    ScatterShape[] shapes = ScatterChart.getAllPossibleShapes();
    
    for(int i = 0; i < dataSets; i++) {
       
        ArrayList<Entry> entries = new ArrayList<Entry>();
        
        for(int j = 0; j < count; j++) {        
            entries.add(new Entry((float) (Math.random() * range) + range / 4, j));
        }
        
        ScatterDataSet ds = new ScatterDataSet(entries, getLabel(i));
        ds.setScatterShapeSize(12f);
        ds.setScatterShape(shapes[i % shapes.length]);
        ds.setColors(ColorTemplate.COLORFUL_COLORS);
        ds.setScatterShapeSize(9f);
        sets.add(ds);
    }
    
    ScatterData d = new ScatterData(ChartData.generateXVals(0, count), sets);
    d.setValueTypeface(tf);
    return d;
}
 
Example #9
Source File: SimpleFragment.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
protected BarData generateBarData(int dataSets, float range, int count) {

        ArrayList<IBarDataSet> sets = new ArrayList<>();

        for(int i = 0; i < dataSets; i++) {

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

            for(int j = 0; j < count; j++) {
                entries.add(new BarEntry(j, (float) (Math.random() * range) + range / 4));
            }

            BarDataSet ds = new BarDataSet(entries, getLabel(i));
            ds.setColors(ColorTemplate.VORDIPLOM_COLORS);
            sets.add(ds);
        }

        BarData d = new BarData(sets);
        d.setValueTypeface(tf);
        return d;
    }
 
Example #10
Source File: Legend.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
/**
 * Entries that will be appended to the end of the auto calculated
 *   entries after calculating the legend.
 * (if the legend has already been calculated, you will need to call notifyDataSetChanged()
 *   to let the changes take effect)
 */
public void setExtra(int[] colors, String[] labels) {

    List<LegendEntry> entries = new ArrayList<>();

    for (int i = 0; i < Math.min(colors.length, labels.length); i++) {
        final LegendEntry entry = new LegendEntry();
        entry.formColor = colors[i];
        entry.label = labels[i];

        if (entry.formColor == ColorTemplate.COLOR_SKIP ||
                entry.formColor == 0)
            entry.form = LegendForm.NONE;
        else if (entry.formColor == ColorTemplate.COLOR_NONE)
            entry.form = LegendForm.EMPTY;

        entries.add(entry);
    }

    mExtraEntries = entries.toArray(new LegendEntry[entries.size()]);
}
 
Example #11
Source File: Legend.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
/**
 * Entries that will be appended to the end of the auto calculated
 * entries after calculating the legend.
 * (if the legend has already been calculated, you will need to call notifyDataSetChanged()
 * to let the changes take effect)
 */
public void setExtra(int[] colors, String[] labels) {

    List<LegendEntry> entries = new ArrayList<>();

    for (int i = 0; i < Math.min(colors.length, labels.length); i++) {
        final LegendEntry entry = new LegendEntry();
        entry.formColor = colors[i];
        entry.label = labels[i];

        if (entry.formColor == ColorTemplate.COLOR_SKIP ||
                entry.formColor == 0) {
            entry.form = LegendForm.NONE;
        } else if (entry.formColor == ColorTemplate.COLOR_NONE) {
            entry.form = LegendForm.EMPTY;
        }

        entries.add(entry);
    }

    mExtraEntries = entries.toArray(new LegendEntry[entries.size()]);
}
 
Example #12
Source File: RealmDatabaseActivityRadar.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
private void setData() {

        RealmResults<RealmDemoData> result = mRealm.allObjects(RealmDemoData.class);

        //RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "stackValues", "xIndex"); // normal entries
        RealmRadarDataSet<RealmDemoData> set = new RealmRadarDataSet<RealmDemoData>(result, "value", "xIndex"); // stacked entries
        set.setLabel("Realm RadarDataSet");
        set.setDrawFilled(true);
        set.setColor(ColorTemplate.rgb("#009688"));
        set.setFillColor(ColorTemplate.rgb("#009688"));
        set.setFillAlpha(130);
        set.setLineWidth(2f);

        ArrayList<IRadarDataSet> dataSets = new ArrayList<IRadarDataSet>();
        dataSets.add(set); // add the dataset

        // create a data object with the dataset list
        RadarData data = new RadarData(new String[] {"2013", "2014", "2015", "2016", "2017", "2018", "2019"}, dataSets);
        styleData(data);

        // set data
        mChart.setData(data);
        mChart.animateY(1400);
    }
 
Example #13
Source File: ListViewBarChartActivity.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
/**
 * generates a random ChartData object with just one DataSet
 * 
 * @return
 */
private BarData generateData(int cnt) {

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

    for (int i = 0; i < 12; i++) {
        entries.add(new BarEntry((int) (Math.random() * 70) + 30, i));
    }

    BarDataSet d = new BarDataSet(entries, "New DataSet " + cnt);    
    d.setBarSpacePercent(20f);
    d.setColors(ColorTemplate.VORDIPLOM_COLORS);
    d.setBarShadowColor(Color.rgb(203, 203, 203));
    
    ArrayList<IBarDataSet> sets = new ArrayList<IBarDataSet>();
    sets.add(d);
    
    BarData cd = new BarData(getMonths(), sets);
    return cd;
}
 
Example #14
Source File: CombinedChartActivity.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
protected BubbleData generateBubbleData() {

        BubbleData bd = new BubbleData();

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

        for (int index = 0; index < itemcount; index++) {
            float rnd = getRandom(20, 30);
            entries.add(new BubbleEntry(index, rnd, rnd));
        }

        BubbleDataSet set = new BubbleDataSet(entries, "Bubble DataSet");
        set.setColors(ColorTemplate.VORDIPLOM_COLORS);
        set.setValueTextSize(10f);
        set.setValueTextColor(Color.WHITE);
        set.setHighlightCircleWidth(1.5f);
        set.setDrawValues(true);
        bd.addDataSet(set);

        return bd;
    }
 
Example #15
Source File: ScrollViewActivity.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
private void setData(int count) {
    
    ArrayList<BarEntry> yVals = new ArrayList<BarEntry>();
    ArrayList<String> xVals = new ArrayList<String>();

    for (int i = 0; i < count; i++) {
        float val = (float) (Math.random() * count) + 15;
        yVals.add(new BarEntry((int) val, i));
        xVals.add((int) val + "");
    }

    BarDataSet set = new BarDataSet(yVals, "Data Set");
    set.setColors(ColorTemplate.VORDIPLOM_COLORS);
    set.setDrawValues(false);

    BarData data = new BarData(xVals, set);

    mChart.setData(data);
    mChart.invalidate();
    mChart.animateY(800);
}
 
Example #16
Source File: SimpleFragment.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
protected BarData generateBarData(int dataSets, float range, int count) {
        
        ArrayList<IBarDataSet> sets = new ArrayList<IBarDataSet>();
        
        for(int i = 0; i < dataSets; i++) {
           
            ArrayList<BarEntry> entries = new ArrayList<BarEntry>();
            
//            entries = FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "stacked_bars.txt");
            
            for(int j = 0; j < count; j++) {        
                entries.add(new BarEntry((float) (Math.random() * range) + range / 4, j));
            }
            
            BarDataSet ds = new BarDataSet(entries, getLabel(i));
            ds.setColors(ColorTemplate.VORDIPLOM_COLORS);
            sets.add(ds);
        }
        
        BarData d = new BarData(ChartData.generateXVals(0, count), sets);
        d.setValueTypeface(tf);
        return d;
    }
 
Example #17
Source File: Legend.java    From android-kline with Apache License 2.0 6 votes vote down vote up
/**
 * Entries that will be appended to the end of the auto calculated
 *   entries after calculating the legend.
 * (if the legend has already been calculated, you will need to call notifyDataSetChanged()
 *   to let the changes take effect)
 */
public void setExtra(int[] colors, String[] labels) {

    List<LegendEntry> entries = new ArrayList<>();

    for (int i = 0; i < Math.min(colors.length, labels.length); i++) {
        final LegendEntry entry = new LegendEntry();
        entry.formColor = colors[i];
        entry.label = labels[i];

        if (entry.formColor == ColorTemplate.COLOR_SKIP ||
                entry.formColor == 0)
            entry.form = LegendForm.NONE;
        else if (entry.formColor == ColorTemplate.COLOR_NONE)
            entry.form = LegendForm.EMPTY;

        entries.add(entry);
    }

    mExtraEntries = entries.toArray(new LegendEntry[entries.size()]);
}
 
Example #18
Source File: LegendRenderer.java    From NetKnight with Apache License 2.0 6 votes vote down vote up
/**
 * Draws the Legend-form at the given position with the color at the given
 * index.
 *
 * @param c     canvas to draw with
 * @param x     position
 * @param y     position
 * @param index the index of the color to use (in the colors array)
 */
protected void drawForm(Canvas c, float x, float y, int index, Legend legend) {

    if (legend.getColors()[index] == ColorTemplate.COLOR_SKIP)
        return;

    mLegendFormPaint.setColor(legend.getColors()[index]);

    float formsize = legend.getFormSize();
    float half = formsize / 2f;

    switch (legend.getForm()) {
        case CIRCLE:
            c.drawCircle(x + half, y, half, mLegendFormPaint);
            break;
        case SQUARE:
            c.drawRect(x, y - half, x + formsize, y + half, mLegendFormPaint);
            break;
        case LINE:
            c.drawLine(x, y, x + formsize, y, mLegendFormPaint);
            break;
    }
}
 
Example #19
Source File: LegendRenderer.java    From iMoney with Apache License 2.0 6 votes vote down vote up
/**
 * Draws the Legend-form at the given position with the color at the given
 * index.
 *
 * @param c     canvas to draw with
 * @param x     position
 * @param y     position
 * @param index the index of the color to use (in the colors array)
 */
protected void drawForm(Canvas c, float x, float y, int index, Legend legend) {

    if (legend.getColors()[index] == ColorTemplate.COLOR_SKIP)
        return;

    mLegendFormPaint.setColor(legend.getColors()[index]);

    float formsize = legend.getFormSize();
    float half = formsize / 2f;

    switch (legend.getForm()) {
        case CIRCLE:
            c.drawCircle(x + half, y, half, mLegendFormPaint);
            break;
        case SQUARE:
            c.drawRect(x, y - half, x + formsize, y + half, mLegendFormPaint);
            break;
        case LINE:
            c.drawLine(x, y, x + formsize, y, mLegendFormPaint);
            break;
    }
}
 
Example #20
Source File: ListViewMultiChartActivity.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
/**
 * generates a random ChartData object with just one DataSet
 *
 * @return Pie data
 */
private PieData generateDataPie() {

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

    for (int i = 0; i < 4; i++) {
        entries.add(new PieEntry((float) ((Math.random() * 70) + 30), "Quarter " + (i+1)));
    }

    PieDataSet d = new PieDataSet(entries, "");

    // space between slices
    d.setSliceSpace(2f);
    d.setColors(ColorTemplate.VORDIPLOM_COLORS);

    return new PieData(d);
}
 
Example #21
Source File: BarChartActivity.java    From iMoney with Apache License 2.0 6 votes vote down vote up
/**
 * 生成柱状图的数据
 */
private BarData generateDataBar() {

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

    for (int i = 0; i < 12; i++) {
        entries.add(new BarEntry((int) (Math.random() * 70) + 30, i));
    }

    BarDataSet d = new BarDataSet(entries, "New DataSet ");
    // 设置柱状图之间的间距
    d.setBarSpacePercent(20f);
    // 设置显示的柱状图的颜色
    d.setColors(ColorTemplate.VORDIPLOM_COLORS);
    // 设置高亮的透明度:当点击柱状图时显示的透明度
    d.setHighLightAlpha(255);

    BarData cd = new BarData(getMonths(), d);
    return cd;
}
 
Example #22
Source File: ScrollViewActivity.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
private void setData(int count) {

        ArrayList<BarEntry> values = new ArrayList<>();

        for (int i = 0; i < count; i++) {
            float val = (float) (Math.random() * count) + 15;
            values.add(new BarEntry(i, (int) val));
        }

        BarDataSet set = new BarDataSet(values, "Data Set");
        set.setColors(ColorTemplate.VORDIPLOM_COLORS);
        set.setDrawValues(false);

        BarData data = new BarData(set);

        chart.setData(data);
        chart.invalidate();
        chart.animateY(800);
    }
 
Example #23
Source File: StatisticActivity.java    From memorize with MIT License 6 votes vote down vote up
private BarData generateDataBar(int cnt) {

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

        for (int i = 0; i < 12; i++) {
            entries.add(new BarEntry(i, (int) (Math.random() * 70) + 30));
        }

        BarDataSet d = new BarDataSet(entries, "New DataSet " + cnt);
        d.setColors(ColorTemplate.VORDIPLOM_COLORS);
        d.setHighLightAlpha(255);

        BarData cd = new BarData(d);
        cd.setBarWidth(0.9f);
        return cd;
    }
 
Example #24
Source File: PieChartActivity.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
private SpannableString generateCenterSpannableText() {

        SpannableString s = new SpannableString("MPAndroidChart\ndeveloped by Philipp Jahoda");
        s.setSpan(new RelativeSizeSpan(1.7f), 0, 14, 0);
        s.setSpan(new StyleSpan(Typeface.NORMAL), 14, s.length() - 15, 0);
        s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, s.length() - 15, 0);
        s.setSpan(new RelativeSizeSpan(.8f), 14, s.length() - 15, 0);
        s.setSpan(new StyleSpan(Typeface.ITALIC), s.length() - 14, s.length(), 0);
        s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), s.length() - 14, s.length(), 0);
        return s;
    }
 
Example #25
Source File: MainActivity.java    From android-ponewheel with MIT License 5 votes vote down vote up
public void updateBatteryRemaining(final int percent) {
    // Update ongoing notification
    notify.remain(percent);
    notify.alert(percent);

    runOnUiThread(() -> {
        try {
            ArrayList<PieEntry> entries = new ArrayList<>();
            entries.add(new PieEntry(percent, 0));
            entries.add(new PieEntry(100 - percent, 1));
            PieDataSet dataSet = new PieDataSet(entries, "battery percentage");
            ArrayList<Integer> mColors = new ArrayList<>();
            mColors.add(ColorTemplate.rgb("#2E7D32")); //green
            mColors.add(ColorTemplate.rgb("#C62828")); //red
            dataSet.setColors(mColors);
            dataSet.setDrawValues(false);

            PieData newPieData = new PieData( dataSet);
            mBatteryChart.setCenterText(percent + "%");
            mBatteryChart.setCenterTextTypeface(Typeface.DEFAULT_BOLD);
            mBatteryChart.setCenterTextColor(ColorTemplate.rgb("#616161"));
            mBatteryChart.setCenterTextSize(20f);
            mBatteryChart.setDescription(null);

            mBatteryChart.setData(newPieData);
            mBatteryChart.notifyDataSetChanged();
            mBatteryChart.invalidate();
        } catch (Exception e) {
            Timber.e( "Got an exception updating battery:" + e.getMessage());
        }
    });

    alertsController.handleChargePercentage(percent);
}
 
Example #26
Source File: ListViewMultiChartActivity.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
/**
 * generates a random ChartData object with just one DataSet
 * 
 * @return
 */
private LineData generateDataLine(int cnt) {

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

    for (int i = 0; i < 12; i++) {
        e1.add(new Entry((int) (Math.random() * 65) + 40, i));
    }

    LineDataSet d1 = new LineDataSet(e1, "New DataSet " + cnt + ", (1)");
    d1.setLineWidth(2.5f);
    d1.setCircleRadius(4.5f);
    d1.setHighLightColor(Color.rgb(244, 117, 117));
    d1.setDrawValues(false);
    
    ArrayList<Entry> e2 = new ArrayList<Entry>();

    for (int i = 0; i < 12; i++) {
        e2.add(new Entry(e1.get(i).getVal() - 30, i));
    }

    LineDataSet d2 = new LineDataSet(e2, "New DataSet " + cnt + ", (2)");
    d2.setLineWidth(2.5f);
    d2.setCircleRadius(4.5f);
    d2.setHighLightColor(Color.rgb(244, 117, 117));
    d2.setColor(ColorTemplate.VORDIPLOM_COLORS[0]);
    d2.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[0]);
    d2.setDrawValues(false);
    
    ArrayList<ILineDataSet> sets = new ArrayList<ILineDataSet>();
    sets.add(d1);
    sets.add(d2);
    
    LineData cd = new LineData(getMonths(), sets);
    return cd;
}
 
Example #27
Source File: RadarChartRenderer.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
public void drawHighlightCircle(Canvas c,
                                MPPointF point,
                                float innerRadius,
                                float outerRadius,
                                int fillColor,
                                int strokeColor,
                                float strokeWidth) {
    c.save();

    outerRadius = Utils.convertDpToPixel(outerRadius);
    innerRadius = Utils.convertDpToPixel(innerRadius);

    if (fillColor != ColorTemplate.COLOR_NONE) {
        Path p = mDrawHighlightCirclePathBuffer;
        p.reset();
        p.addCircle(point.x, point.y, outerRadius, Path.Direction.CW);
        if (innerRadius > 0.f) {
            p.addCircle(point.x, point.y, innerRadius, Path.Direction.CCW);
        }
        mHighlightCirclePaint.setColor(fillColor);
        mHighlightCirclePaint.setStyle(Paint.Style.FILL);
        c.drawPath(p, mHighlightCirclePaint);
    }

    if (strokeColor != ColorTemplate.COLOR_NONE) {
        mHighlightCirclePaint.setColor(strokeColor);
        mHighlightCirclePaint.setStyle(Paint.Style.STROKE);
        mHighlightCirclePaint.setStrokeWidth(Utils.convertDpToPixel(strokeWidth));
        c.drawCircle(point.x, point.y, outerRadius, mHighlightCirclePaint);
    }

    c.restore();
}
 
Example #28
Source File: MultiLineChartActivity.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

    chart.resetTracking();

    progress = seekBarX.getProgress();

    tvX.setText(String.valueOf(seekBarX.getProgress()));
    tvY.setText(String.valueOf(seekBarY.getProgress()));

    ArrayList<ILineDataSet> dataSets = new ArrayList<>();

    for (int z = 0; z < 3; z++) {

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

        for (int i = 0; i < progress; i++) {
            double val = (Math.random() * seekBarY.getProgress()) + 3;
            values.add(new Entry(i, (float) val));
        }

        LineDataSet d = new LineDataSet(values, "DataSet " + (z + 1));
        d.setLineWidth(2.5f);
        d.setCircleRadius(4f);

        int color = colors[z % colors.length];
        d.setColor(color);
        d.setCircleColor(color);
        dataSets.add(d);
    }

    // make the first DataSet dashed
    ((LineDataSet) dataSets.get(0)).enableDashedLine(10, 10, 0);
    ((LineDataSet) dataSets.get(0)).setColors(ColorTemplate.VORDIPLOM_COLORS);
    ((LineDataSet) dataSets.get(0)).setCircleColors(ColorTemplate.VORDIPLOM_COLORS);

    LineData data = new LineData(dataSets);
    chart.setData(data);
    chart.invalidate();
}
 
Example #29
Source File: SimpleFragment.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
/**
 * generates less data (1 DataSet, 4 values)
 * @return
 */
protected PieData generatePieData() {
    
    int count = 4;
    
    ArrayList<Entry> entries1 = new ArrayList<Entry>();
    ArrayList<String> xVals = new ArrayList<String>();
    
    xVals.add("Quarter 1");
    xVals.add("Quarter 2");
    xVals.add("Quarter 3");
    xVals.add("Quarter 4");
    
    for(int i = 0; i < count; i++) {
        xVals.add("entry" + (i+1));

        entries1.add(new Entry((float) (Math.random() * 60) + 40, i));
    }
    
    PieDataSet ds1 = new PieDataSet(entries1, "Quarterly Revenues 2015");
    ds1.setColors(ColorTemplate.VORDIPLOM_COLORS);
    ds1.setSliceSpace(2f);
    ds1.setValueTextColor(Color.WHITE);
    ds1.setValueTextSize(12f);
    
    PieData d = new PieData(xVals, ds1);
    d.setValueTypeface(tf);

    return d;
}
 
Example #30
Source File: RadarChartRenderer.java    From android-kline with Apache License 2.0 5 votes vote down vote up
public void drawHighlightCircle(Canvas c,
                                MPPointF point,
                                float innerRadius,
                                float outerRadius,
                                int fillColor,
                                int strokeColor,
                                float strokeWidth) {
    c.save();

    outerRadius = Utils.convertDpToPixel(outerRadius);
    innerRadius = Utils.convertDpToPixel(innerRadius);

    if (fillColor != ColorTemplate.COLOR_NONE) {
        Path p = mDrawHighlightCirclePathBuffer;
        p.reset();
        p.addCircle(point.x, point.y, outerRadius, Path.Direction.CW);
        if (innerRadius > 0.f) {
            p.addCircle(point.x, point.y, innerRadius, Path.Direction.CCW);
        }
        mHighlightCirclePaint.setColor(fillColor);
        mHighlightCirclePaint.setStyle(Paint.Style.FILL);
        c.drawPath(p, mHighlightCirclePaint);
    }

    if (strokeColor != ColorTemplate.COLOR_NONE) {
        mHighlightCirclePaint.setColor(strokeColor);
        mHighlightCirclePaint.setStyle(Paint.Style.STROKE);
        mHighlightCirclePaint.setStrokeWidth(Utils.convertDpToPixel(strokeWidth));
        c.drawCircle(point.x, point.y, outerRadius, mHighlightCirclePaint);
    }

    c.restore();
}