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

The following examples show how to use com.github.mikephil.charting.data.LineDataSet#setCubicIntensity() . 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: RangeTestFragmentView.java    From EFRConnect-android with Apache License 2.0 6 votes vote down vote up
private LineData createChartData(int color) {
    List<Entry> entries = new ArrayList<>(1024);
    entries.add(new Entry(-2, 0));
    entries.add(new Entry(-1, 0));

    chartDataSet = new LineDataSet(entries, null);

    chartDataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);
    chartDataSet.setCubicIntensity(0.1f);
    chartDataSet.setDrawCircles(false);
    chartDataSet.setDrawFilled(true);
    chartDataSet.setLineWidth(0f);
    chartDataSet.setColor(color);
    chartDataSet.setFillColor(color);
    chartDataSet.setFillAlpha(255);
    chartDataSet.setDrawHorizontalHighlightIndicator(false);
    chartDataSet.setDrawVerticalHighlightIndicator(false);
    chartDataSet.setFillFormatter(new CubicLineSampleFillFormatter());

    chartData = new LineData(chartDataSet);

    chartData.setDrawValues(false);

    return chartData;
}
 
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: DataPlotFragment.java    From OpenLibre with GNU General Public License v3.0 4 votes vote down vote up
private LineDataSet makeLineData(List<GlucoseData> glucoseDataList) {
    String title = "History";
    if (glucoseDataList.get(0).isTrendData()) title = "Trend";

    LineDataSet lineDataSet = new LineDataSet(new ArrayList<Entry>(), title);
    for (GlucoseData gd : glucoseDataList) {
        float x = convertDateToXAxisValue(gd.getDate());
        float y = gd.glucose();
        lineDataSet.addEntryOrdered(new Entry(x, y));
        /*
        Log.d(LOG_ID, String.format("%s: %s -> %s: %f -> %f",
                title,
                mFormatDateTime.format(new Date(gd.date)),
                mFormatDateTime.format(new Date(convertXAxisValueToDate(x))),
                x,
                y)
        );
        */
    }

    lineDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
    lineDataSet.setDrawCircles(true);
    lineDataSet.setCircleRadius(2f);

    lineDataSet.setDrawCircleHole(false);
    lineDataSet.setDrawValues(false);

    lineDataSet.setDrawHighlightIndicators(true);

    int baseColor = PLOT_COLORS[mPlotColorIndex % NUM_PLOT_COLORS][0];
    int softColor = Color.argb(150, Color.red(baseColor), Color.green(baseColor), Color.blue(baseColor));
    int hardColor = PLOT_COLORS[mPlotColorIndex % NUM_PLOT_COLORS][1];
    if (glucoseDataList.get(0).isTrendData()) {
        lineDataSet.setColor(hardColor);
        lineDataSet.setLineWidth(2f);

        lineDataSet.setCircleColor(softColor);

        lineDataSet.setMode(LineDataSet.Mode.LINEAR);
    } else {
        lineDataSet.setColor(softColor);
        lineDataSet.setLineWidth(4f);

        lineDataSet.setCircleColor(hardColor);

        lineDataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);
        lineDataSet.setCubicIntensity(0.1f);
    }

    return lineDataSet;
}
 
Example 5
Source File: CubicLineChartActivity.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((1990 +i) + "");
        }

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

        for (int i = 0; i < count; i++) {
            float mult = (range + 1);
            float val = (float) (Math.random() * mult) + 20;// + (float)
                                                           // ((mult *
                                                           // 0.1) / 10);
            vals1.add(new Entry(val, i));
        }
        
        // create a dataset and give it a type
        LineDataSet set1 = new LineDataSet(vals1, "DataSet 1");
        set1.setDrawCubic(true);
        set1.setCubicIntensity(0.2f);
        //set1.setDrawFilled(true);
        set1.setDrawCircles(false); 
        set1.setLineWidth(1.8f);
        set1.setCircleRadius(4f);
        set1.setCircleColor(Color.WHITE);
        set1.setHighLightColor(Color.rgb(244, 117, 117));
        set1.setColor(Color.WHITE);
        set1.setFillColor(Color.WHITE);
        set1.setFillAlpha(100);
        set1.setDrawHorizontalHighlightIndicator(false);
        set1.setFillFormatter(new FillFormatter() {
            @Override
            public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
                return -10;
            }
        });
        
        // create a data object with the datasets
        LineData data = new LineData(xVals, set1);
        data.setValueTypeface(tf);
        data.setValueTextSize(9f);
        data.setDrawValues(false);

        // set data
        mChart.setData(data);
    }
 
Example 6
Source File: LineChartManager.java    From react-native-mp-android-chart with MIT License 4 votes vote down vote up
@Override
void dataSetConfig(IDataSet<Entry> dataSet, ReadableMap config) {
    LineDataSet lineDataSet = (LineDataSet) dataSet;

    ChartDataSetConfigUtils.commonConfig(lineDataSet, config);
    ChartDataSetConfigUtils.commonBarLineScatterCandleBubbleConfig(lineDataSet, config);
    ChartDataSetConfigUtils.commonLineScatterCandleRadarConfig(lineDataSet, config);
    ChartDataSetConfigUtils.commonLineRadarConfig(lineDataSet, config);

    // LineDataSet only config
    if (BridgeUtils.validate(config, ReadableType.Number, "circleRadius")) {
        lineDataSet.setCircleRadius((float) config.getDouble("circleRadius"));
    }
    if (BridgeUtils.validate(config, ReadableType.Boolean, "drawCircles")) {
        lineDataSet.setDrawCircles(config.getBoolean("drawCircles"));
    }
    if (BridgeUtils.validate(config, ReadableType.Boolean, "drawCubic")) {
        lineDataSet.setDrawCubic(config.getBoolean("drawCubic"));
    }
    if (BridgeUtils.validate(config, ReadableType.Number, "drawCubicIntensity")) {
        lineDataSet.setCubicIntensity((float) config.getDouble("drawCubicIntensity"));
    }
    if (BridgeUtils.validate(config, ReadableType.String, "circleColor")) {
        lineDataSet.setCircleColor(Color.parseColor(config.getString("circleColor")));
    }
    if (BridgeUtils.validate(config, ReadableType.Array, "circleColors")) {
        lineDataSet.setCircleColors(BridgeUtils.parseColors(config.getArray("circleColors")));
    }
    if (BridgeUtils.validate(config, ReadableType.String, "circleColorHole")) {
        lineDataSet.setCircleColorHole(Color.parseColor(config.getString("circleColorHole")));
    }
    if (BridgeUtils.validate(config, ReadableType.Boolean, "drawCircleHole")) {
        lineDataSet.setDrawCircleHole(config.getBoolean("drawCircleHole"));
    }
    if (BridgeUtils.validate(config, ReadableType.Map, "dashedLine")) {
        ReadableMap dashedLine = config.getMap("dashedLine");
        float lineLength = 0;
        float spaceLength = 0;
        float phase = 0;

        if (BridgeUtils.validate(dashedLine, ReadableType.Number, "lineLength")) {
            lineLength = (float) dashedLine.getDouble("lineLength");
        }
        if (BridgeUtils.validate(dashedLine, ReadableType.Number, "spaceLength")) {
            spaceLength = (float) dashedLine.getDouble("spaceLength");
        }
        if (BridgeUtils.validate(dashedLine, ReadableType.Number, "phase")) {
            phase = (float) dashedLine.getDouble("phase");
        }

        lineDataSet.enableDashedLine(lineLength, spaceLength, phase);
    }
}
 
Example 7
Source File: RecordingFragment.java    From go-bees with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Configure bees chart and the data.
 *
 * @param recordsList list of records.
 */
private void setupBeesChart(List<Record> recordsList) {
    // Setup data
    referenceTimestamp = recordsList.get(0).getTimestamp().getTime() / 1000;
    Record[] records = recordsList.toArray(new Record[recordsList.size()]);
    List<Entry> entries = new ArrayList<>();
    int maxNumBees = 0;
    for (Record record : records) {
        // Convert timestamp to seconds and relative to first timestamp
        long timestamp = record.getTimestamp().getTime() / 1000 - referenceTimestamp;
        int numBees = record.getNumBees();
        entries.add(new Entry(timestamp, numBees));
        // Get max num of bees
        if (numBees > maxNumBees) {
            maxNumBees = numBees;
        }
    }
    lastTimestamp = (long) entries.get(entries.size() - 1).getX();
    // Style char lines (type, color, etc.)
    LineDataSet lineDataSet = new LineDataSet(entries, getString(R.string.num_bees));
    lineDataSet.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
    lineDataSet.setCubicIntensity(0.2f);
    lineDataSet.setDrawValues(false);
    lineDataSet.setDrawCircles(false);
    lineDataSet.setLineWidth(1.8f);
    lineDataSet.setColor(ContextCompat.getColor(getContext(), R.color.colorAccent));
    // General setup
    beesChart.setDrawGridBackground(false);
    beesChart.setDrawBorders(false);
    beesChart.setViewPortOffsets(80, 40, 80, 50);
    beesChart.getDescription().setEnabled(false);
    beesChart.getLegend().setEnabled(false);
    beesChart.setTouchEnabled(true);
    beesChart.setDragEnabled(false);
    beesChart.setScaleEnabled(false);
    beesChart.setPinchZoom(false);
    BeesMarkerView mv = new BeesMarkerView(getContext(), R.layout.recording_bees_marker_vew);
    mv.setChartView(beesChart);
    beesChart.setMarker(mv);
    beesChart.setNoDataText(getString(R.string.no_flight_act_data_available));
    // X axis setup
    IAxisValueFormatter xAxisFormatter = new HourAxisValueFormatter(referenceTimestamp);
    XAxis xAxis = beesChart.getXAxis();
    xAxis.setValueFormatter(xAxisFormatter);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawAxisLine(false);
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setTextColor(Color.BLACK);
    // Y axis setup
    YAxis leftAxis = beesChart.getAxisLeft();
    leftAxis.setAxisMaximum(maxNumBees > 40 ? maxNumBees + 2 : 40);
    leftAxis.setAxisMinimum(0);
    leftAxis.setDrawGridLines(true);
    leftAxis.setDrawAxisLine(false);
    YAxis rightAxis = beesChart.getAxisRight();
    rightAxis.setAxisMaximum(maxNumBees > 40 ? maxNumBees + 2 : 40);
    rightAxis.setAxisMinimum(0);
    rightAxis.setDrawGridLines(true);
    rightAxis.setDrawAxisLine(false);
    // Add data
    beesChart.setData(new LineData(lineDataSet));
}
 
Example 8
Source File: ProgressFragment.java    From voice-pitch-analyzer with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
    public void onViewCreated(View view, Bundle savedInstanceState)
    {
        CombinedChart chart = (CombinedChart) view.findViewById(R.id.progress_chart);
        this.recordings = new RecordingList(this.getContext());

        if (this.recordings != null)
        {
            List<String> dates = this.recordings.getDates();

            CombinedData data = new CombinedData(dates);

            LineDataSet dataSet = new LineDataSet(this.recordings.getGraphEntries(), getResources().getString(R.string.progress));
            LineData lineData = new LineData(dates, dataSet);
            BarData barData = new BarData(dates, GraphLayout.getOverallRange(this.getContext(), dates.size()));

            dataSet.setDrawCubic(true);
            dataSet.enableDashedLine(10, 10, 0);
            dataSet.setLineWidth(3f);
            dataSet.setDrawValues(false);

            dataSet.setCircleColor(getResources().getColor(R.color.canvas_dark));
            dataSet.setColor(getResources().getColor(R.color.canvas_dark));
            dataSet.setCircleSize(5f);

            dataSet.setCubicIntensity(0.05f);
            dataSet.setAxisDependency(YAxis.AxisDependency.LEFT);

            data.setData(lineData);
            data.setData(barData);
            chart.setData(data);
            GraphLayout.FormatChart(chart);

            chart.setTouchEnabled(true);
//            chart.setScaleEnabled(true);
            chart.setPinchZoom(true);
//            chart.setDoubleTapToZoomEnabled(true);

            chart.setDrawValueAboveBar(false);
            chart.setDrawOrder(new DrawOrder[]{
                    DrawOrder.BAR,
                    DrawOrder.BUBBLE,
                    DrawOrder.CANDLE,
                    DrawOrder.LINE,
                    DrawOrder.SCATTER
            });
        }

        super.onViewCreated(view, savedInstanceState);
    }
 
Example 9
Source File: DataUsageActivity.java    From utexas-utilities with Apache License 2.0 4 votes vote down vote up
private void setupChart(List<String> labels, List<Entry> downData, List<Entry> totalData) {
    LineDataSet totalLineDataSet = new LineDataSet(totalData, "Uploaded");
    totalLineDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
    totalLineDataSet.setDrawCircles(false);
    totalLineDataSet.setCubicIntensity(0.1f);
    totalLineDataSet.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
    totalLineDataSet.setDrawFilled(true);
    totalLineDataSet.setDrawValues(false);
    totalLineDataSet.setColor(ContextCompat.getColor(this, R.color.data_usage_chart_upload));
    totalLineDataSet.setFillColor(ContextCompat.getColor(this, R.color.data_usage_chart_upload));
    totalLineDataSet.setFillAlpha(255);

    LineDataSet downLineDataSet = new LineDataSet(downData, "Downloaded");
    downLineDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
    downLineDataSet.setDrawCircles(false);
    downLineDataSet.setCubicIntensity(0.1f);
    downLineDataSet.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
    downLineDataSet.setDrawFilled(true);
    downLineDataSet.setDrawValues(false);
    downLineDataSet.setColor(ContextCompat.getColor(this, R.color.data_usage_chart_download));
    downLineDataSet.setFillColor(ContextCompat.getColor(this, R.color.data_usage_chart_download));
    downLineDataSet.setFillAlpha(255);

    List<ILineDataSet> downAndUp = new ArrayList<>();
    downAndUp.add(totalLineDataSet);
    downAndUp.add(downLineDataSet);

    LineData dataUsageLineData = new LineData(labels, downAndUp);
    chart.getAxisRight().setEnabled(true);
    chart.getAxisRight().setDrawAxisLine(true);
    chart.getAxisRight().setDrawGridLines(false);
    chart.getAxisRight().setDrawLabels(false);
    chart.getAxisLeft().setStartAtZero(true);
    chart.setData(dataUsageLineData);
    chart.setDescription("");
    chart.setScaleXEnabled(true);
    chart.setScaleYEnabled(false);
    chart.setPinchZoom(true);
    chart.setDoubleTapToZoomEnabled(true);
    chart.getData().setHighlightEnabled(false);
    chart.getAxisLeft().setValueFormatter((value, axis) -> value + " MB");
    // maximum viewable area is one day
    chart.setScaleMinima(downData.size() / 288f, 1f);
    // initially show the most recent 24 hours
    chart.centerViewTo(Math.max(downData.size() - 144, 0), chart.getYChartMax() / 2, YAxis.AxisDependency.LEFT);
    chart.setVisibility(View.VISIBLE);
    progressLayout.setVisibility(View.GONE);
}