Java Code Examples for com.github.mikephil.charting.data.LineDataSet#setFillDrawable()

The following examples show how to use com.github.mikephil.charting.data.LineDataSet#setFillDrawable() . 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: TickChart.java    From android-kline with Apache License 2.0 7 votes vote down vote up
private ILineDataSet createSet(int type) {
        LineDataSet set = new LineDataSet(null, String.valueOf(type));
//        set.setAxisDependency(YAxis.AxisDependency.LEFT);
        if (type == TYPE_FULL) {
            set.setHighLightColor(mLineColor);
            set.setDrawHighlightIndicators(true);
//            set.setDrawVerticalHighlightIndicator(false);
            set.setHighlightLineWidth(0.5f);
            set.setCircleColor(mLineColor);
            set.setCircleRadius(1.5f);
            set.setDrawCircleHole(false);
            set.setDrawFilled(true);
            set.setColor(mLineColor);
            set.setLineWidth(1f);
            set.setFillDrawable(new ColorDrawable(transparentColor));
        } else if (type == TYPE_AVE) {
            set.setHighlightEnabled(true);
            set.setColor(ContextCompat.getColor(mContext, R.color.ave_color));
            set.setLineWidth(1f);
            set.setCircleRadius(1.5f);
            set.setDrawCircleHole(false);
            set.setCircleColor(transparentColor);
            set.setLineWidth(0.5f);
        } else {
            set.setHighlightEnabled(true);
            set.setDrawVerticalHighlightIndicator(false);
            set.setHighLightColor(transparentColor);
            set.setColor(mLineColor);
            set.enableDashedLine(3, 40, 0);
            set.setDrawCircleHole(false);
            set.setCircleColor(transparentColor);
            set.setLineWidth(1f);
            set.setVisible(true);
        }
        set.setDrawCircles(false);
        set.setDrawValues(false);
        return set;
    }
 
Example 2
Source File: RecordingsAdapter.java    From go-bees with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Style char lines (type, color, etc.).
 *
 * @param entries list of entries.
 * @return line data chart.
 */
private LineData styleChartLines(List<Entry> entries) {
    // Set styles
    LineDataSet lineDataSet = new LineDataSet(entries, "Recording");
    lineDataSet.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
    lineDataSet.setCubicIntensity(0.2f);
    lineDataSet.setDrawValues(false);
    lineDataSet.setDrawCircles(false);
    lineDataSet.setLineWidth(1.8f);
    lineDataSet.setColor(ContextCompat.getColor(context, R.color.colorAccent));
    if (((int) lineDataSet.getYMax()) != 0) {
        lineDataSet.setDrawFilled(true);
        lineDataSet.setFillAlpha(255);
        // Fix bug with vectors in API < 21
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT){
            Drawable drawable = ResourcesCompat.getDrawable(context.getResources(),
                    R.drawable.chart_fade, null);
            lineDataSet.setFillDrawable(drawable);
        } else{
            lineDataSet.setFillColor(ContextCompat.getColor(context, R.color.colorPrimary));
        }
    }
    return new LineData(lineDataSet);
}
 
Example 3
Source File: ChartUtil.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 曲线赋值与设置
 *
 * @param context   上下文
 * @param yDataList y轴数据
 * @return LineData
 */
private static LineData setLineData(Context context, List<Entry> yDataList,
                                    String curveLable) {
    // y轴的数据集合
    LineDataSet lineDataSet = new LineDataSet(yDataList, curveLable);
    // 用y轴的集合来设置参数
    lineDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
    // 不显示坐标点的数据
    lineDataSet.setDrawValues(false);
    // 显示坐标点的小圆点
    lineDataSet.setDrawCircles(false);
    // 定位线
    lineDataSet.setHighlightEnabled(false);
    // 线宽
    lineDataSet.setLineWidth(1f);
    // 显示的圆形大小
    lineDataSet.setCircleSize(2f);
    // 显示颜色
    lineDataSet.setColor(context.getApplicationContext().getResources().getColor(R.color.chart_color));
    // 圆形的颜色
    lineDataSet.setCircleColor(context.getApplicationContext().getResources().getColor(R.color.chart_color));
    // 高亮的线的颜色
    lineDataSet.setHighLightColor(context.getApplicationContext().getResources()
            .getColor(R.color.chart_color));
    // 设置填充的颜色

    Drawable drawable = ContextCompat.getDrawable(context, R.drawable.fade_color);
    lineDataSet.setFillDrawable(drawable);

    // 设置坐标点为空心环状
    lineDataSet.setDrawCircleHole(false);
    // lineDataSet.setValueTextSize(9f);
    lineDataSet.setFillAlpha(30);
    // 设置显示曲线和X轴围成的区域阴影
    lineDataSet.setDrawFilled(true);
    // 坐标轴在左侧
    lineDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
    // 设置每条曲线图例标签名
    // lineDataSet.setLabel("标签");
    lineDataSet.setValueTextSize(14f);
    // 曲线弧度(区间0.05f-1f,默认0.2f)
    lineDataSet.setCubicIntensity(0.2f);
    // 设置为曲线显示,false为折线
    lineDataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);
    lineDataSet.setValues(yDataList);
    // y轴的数据
    LineData lineData = new LineData(lineDataSet);
    return lineData;
}
 
Example 4
Source File: LineChartActivity1.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
private void setData(int count, float range) {

        ArrayList<String> xVals = new ArrayList<String>();
        for (int i = 0; i < count; i++) {
            xVals.add((i) + "");
        }

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

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

            float mult = (range + 1);
            float val = (float) (Math.random() * mult) + 3;// + (float)
            // ((mult *
            // 0.1) / 10);
            yVals.add(new Entry(val, i));
        }

        // create a dataset and give it a type
        LineDataSet set1 = new LineDataSet(yVals, "DataSet 1");
        // set1.setFillAlpha(110);
        // set1.setFillColor(Color.RED);

        // set the line to be drawn like this "- - - - - -"
        set1.enableDashedLine(10f, 5f, 0f);
        set1.enableDashedHighlightLine(10f, 5f, 0f);
        set1.setColor(Color.BLACK);
        set1.setCircleColor(Color.BLACK);
        set1.setLineWidth(1f);
        set1.setCircleRadius(3f);
        set1.setDrawCircleHole(false);
        set1.setValueTextSize(9f);
        Drawable drawable = ContextCompat.getDrawable(this, R.drawable.fade_red);
        set1.setFillDrawable(drawable);
        set1.setDrawFilled(true);

        ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
        dataSets.add(set1); // add the datasets

        // create a data object with the datasets
        LineData data = new LineData(xVals, dataSets);

        // set data
        mChart.setData(data);
    }
 
Example 5
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 6
Source File: MiniDateGraph.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(0f);
    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.setDrawValues(false);

    /*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 7
Source File: CurrencyActivity.java    From Travel-Mate with MIT License 4 votes vote down vote up
void setGraphData(JSONArray currencyRateTrends) {
    ArrayList<Entry> values = new ArrayList<>();

    for (int i = 0; i < currencyRateTrends.length(); i++) {
        try {
            values.add(new Entry(i, (float) currencyRateTrends.getDouble(i)));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    LineDataSet lineDataSet = new LineDataSet(values, GRAPH_LABEL_NAME);
    lineDataSet.setDrawIcons(false);
    lineDataSet.setColor(Color.RED);
    lineDataSet.setCircleColor(Color.BLUE);
    lineDataSet.setCircleRadius(1f);
    lineDataSet.setLineWidth(1f);
    lineDataSet.setCircleRadius(3f);
    lineDataSet.setDrawCircleHole(true);
    lineDataSet.setValueTextSize(10f);
    lineDataSet.setValueTextColor(Color.BLACK);
    lineDataSet.setDrawFilled(true);
    lineDataSet.setFormSize(10.f);
    if (Utils.getSDKInt() >= 18) {
        // fill drawable only supported on api level 18 and above
        Drawable drawable = ContextCompat.getDrawable(this, R.drawable.fade_green);
        lineDataSet.setFillDrawable(drawable);
    } else {
        lineDataSet.setFillColor(Color.BLACK);
    }

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

    // create a data object with the datasets
    LineData data = new LineData(dataSets);

    // set data
    graph.setData(data);

}