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

The following examples show how to use com.github.mikephil.charting.data.LineDataSet#setColor() . 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: FragmentPrice.java    From Lunary-Ethereum-Wallet with GNU General Public License v3.0 6 votes vote down vote up
private LineData getData(ArrayList<Entry> yVals) {
    LineDataSet set1 = new LineDataSet(yVals, "");
    set1.setLineWidth(1.45f);
    set1.setColor(Color.argb(240, 255, 255, 255));
    set1.setCircleColor(Color.WHITE);
    set1.setHighLightColor(Color.WHITE);
    set1.setFillColor(getResources().getColor(R.color.chartFilled));
    set1.setDrawCircles(false);
    set1.setDrawValues(false);
    set1.setDrawFilled(true);
    set1.setFillFormatter(new IFillFormatter() {
        @Override
        public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
            return priceChart.getAxisLeft().getAxisMinimum();
        }
    });

    LineData data = new LineData(set1);
    return data;
}
 
Example 3
Source File: KlineFragment.java    From shinny-futures-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * date: 2019/2/22
 * author: chenli
 * description: 产生持仓量数据集
 */
private LineDataSet generateLineDataSet(List<Entry> entries, int color, String label, boolean isHighlight, YAxis.AxisDependency axisDependency) {
    LineDataSet set = new LineDataSet(entries, label);
    set.setColor(color);
    set.setLineWidth(0.7f);
    set.setDrawCircles(false);
    set.setDrawCircleHole(false);
    set.setDrawValues(false);
    set.setAxisDependency(axisDependency);
    if (isHighlight) {
        set.setHighlightLineWidth(0.7f);
        set.setHighLightColor(color);
    } else {
        set.setHighlightEnabled(false);
    }
    return set;
}
 
Example 4
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 5
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 6
Source File: CombinedChartActivity.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
private LineData generateLineData() {

        LineData d = new LineData();

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

        for (int index = 0; index < itemcount; index++)
            entries.add(new Entry(getRandom(15, 10), index));

        LineDataSet set = new LineDataSet(entries, "Line DataSet");
        set.setColor(Color.rgb(240, 238, 70));
        set.setLineWidth(2.5f);
        set.setCircleColor(Color.rgb(240, 238, 70));
        set.setCircleRadius(5f);
        set.setFillColor(Color.rgb(240, 238, 70));
        set.setDrawCubic(true);
        set.setDrawValues(true);
        set.setValueTextSize(10f);
        set.setValueTextColor(Color.rgb(240, 238, 70));

        set.setAxisDependency(YAxis.AxisDependency.LEFT);

        d.addDataSet(set);

        return d;
    }
 
Example 7
Source File: KLineDataManage.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
private LineDataSet setALine(ColorType colorType, ArrayList<Entry> lineEntries, String label, boolean highlightEnable) {
    LineDataSet lineDataSetMa = new LineDataSet(lineEntries, label);
    lineDataSetMa.setDrawHorizontalHighlightIndicator(false);
    lineDataSetMa.setHighlightEnabled(highlightEnable);//是否画高亮十字线
    lineDataSetMa.setHighLightColor(ContextCompat.getColor(mContext, R.color.highLight_Color));//高亮十字线颜色
    lineDataSetMa.setDrawValues(false);//是否画出每个蜡烛线的数值
    if (colorType == ColorType.blue) {
        lineDataSetMa.setColor(ContextCompat.getColor(mContext, R.color.ma5));
    } else if (colorType == ColorType.yellow) {
        lineDataSetMa.setColor(ContextCompat.getColor(mContext, R.color.ma10));
    } else if (colorType == ColorType.purple) {
        lineDataSetMa.setColor(ContextCompat.getColor(mContext, R.color.ma20));
    }
    lineDataSetMa.setLineWidth(0.6f);
    lineDataSetMa.setDrawCircles(false);
    lineDataSetMa.setAxisDependency(YAxis.AxisDependency.LEFT);
    return lineDataSetMa;
}
 
Example 8
Source File: ChartRVAdapter.java    From batteryhub with Apache License 2.0 5 votes vote down vote up
private LineData loadData(ChartCard card) {
    // add entries to dataset
    LineDataSet lineDataSet = new LineDataSet(card.entries, null);
    lineDataSet.setMode(LineDataSet.Mode.LINEAR);
    lineDataSet.setDrawValues(false);
    lineDataSet.setDrawCircleHole(false);
    lineDataSet.setColor(card.color);
    lineDataSet.setCircleColor(card.color);
    lineDataSet.setLineWidth(1.8f);
    lineDataSet.setDrawFilled(true);
    lineDataSet.setFillColor(card.color);

    return new LineData(lineDataSet);
}
 
Example 9
Source File: TimeLineView.java    From android-kline with Apache License 2.0 5 votes vote down vote up
@android.support.annotation.NonNull
private LineDataSet setLine(int type, ArrayList<Entry> lineEntries) {
    LineDataSet lineDataSetMa = new LineDataSet(lineEntries, "ma" + type);
    lineDataSetMa.setDrawValues(false);
    if (type == NORMAL_LINE) {
        lineDataSetMa.setColor(getResources().getColor(R.color.normal_line_color));
        lineDataSetMa.setCircleColor(ContextCompat.getColor(mContext, R.color.normal_line_color));
    } else if (type == NORMAL_LINE_5DAY) {
        lineDataSetMa.setColor(getResources().getColor(R.color.normal_line_color));
        lineDataSetMa.setCircleColor(mTransparentColor);
    } else if (type == AVE_LINE) {
        lineDataSetMa.setColor(getResources().getColor(R.color.ave_color));
        lineDataSetMa.setCircleColor(mTransparentColor);
        lineDataSetMa.setHighlightEnabled(false);
    } else {
        lineDataSetMa.setVisible(false);
        lineDataSetMa.setHighlightEnabled(false);
    }
    lineDataSetMa.setAxisDependency(YAxis.AxisDependency.LEFT);
    lineDataSetMa.setLineWidth(1f);
    lineDataSetMa.setCircleRadius(1f);

    lineDataSetMa.setDrawCircles(false);
    lineDataSetMa.setDrawCircleHole(false);

    return lineDataSetMa;
}
 
Example 10
Source File: DynamicalAddingActivity.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
private void addDataSet() {

        LineData data = mChart.getData();
        
        if(data != null) {

            int count = (data.getDataSetCount() + 1);

            // create 10 y-vals
            ArrayList<Entry> yVals = new ArrayList<Entry>();
            
            if(data.getXValCount() == 0) {
                // add 10 x-entries
                for (int i = 0; i < 10; i++) {
                    data.addXValue("" + (i+1));
                }
            }

            for (int i = 0; i < data.getXValCount(); i++) {
                yVals.add(new Entry((float) (Math.random() * 50f) + 50f * count, i));
            }

            LineDataSet set = new LineDataSet(yVals, "DataSet " + count);
            set.setLineWidth(2.5f);
            set.setCircleRadius(4.5f);

            int color = mColors[count % mColors.length];

            set.setColor(color);
            set.setCircleColor(color);
            set.setHighLightColor(color);
            set.setValueTextSize(10f);
            set.setValueTextColor(color);

            data.addDataSet(set);
            mChart.notifyDataSetChanged();
            mChart.invalidate();   
        }
    }
 
Example 11
Source File: PerformanceLineChart.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
private void setData(int count, float range) {

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

        for (int i = 0; i < count; i++) {
            float val = (float) (Math.random() * (range + 1)) + 3;
            values.add(new Entry(i * 0.001f, val));
        }

        // create a dataset and give it a type
        LineDataSet set1 = new LineDataSet(values, "DataSet 1");

        set1.setColor(Color.BLACK);
        set1.setLineWidth(0.5f);
        set1.setDrawValues(false);
        set1.setDrawCircles(false);
        set1.setMode(LineDataSet.Mode.LINEAR);
        set1.setDrawFilled(false);

        // create a data object with the data sets
        LineData data = new LineData(set1);

        // set data
        chart.setData(data);

        // get the legend (only possible after setting data)
        Legend l = chart.getLegend();
        l.setEnabled(false);
    }
 
Example 12
Source File: SimpleFragment.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
protected LineData getComplexity() {
    
    ArrayList<ILineDataSet> sets = new ArrayList<ILineDataSet>();
    
    LineDataSet ds1 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "n.txt"), "O(n)");
    LineDataSet ds2 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "nlogn.txt"), "O(nlogn)");
    LineDataSet ds3 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "square.txt"), "O(n\u00B2)");
    LineDataSet ds4 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "three.txt"), "O(n\u00B3)");
    
    ds1.setColor(ColorTemplate.VORDIPLOM_COLORS[0]);
    ds2.setColor(ColorTemplate.VORDIPLOM_COLORS[1]);
    ds3.setColor(ColorTemplate.VORDIPLOM_COLORS[2]);
    ds4.setColor(ColorTemplate.VORDIPLOM_COLORS[3]);
    
    ds1.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[0]);
    ds2.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[1]);
    ds3.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[2]);
    ds4.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[3]);
    
    ds1.setLineWidth(2.5f);
    ds1.setCircleRadius(3f);
    ds2.setLineWidth(2.5f);
    ds2.setCircleRadius(3f);
    ds3.setLineWidth(2.5f);
    ds3.setCircleRadius(3f);
    ds4.setLineWidth(2.5f);
    ds4.setCircleRadius(3f);
    
    
    // load DataSets from textfiles in assets folders
    sets.add(ds1);        
    sets.add(ds2);
    sets.add(ds3);
    sets.add(ds4);
    
    LineData d = new LineData(ChartData.generateXVals(0, ds1.getEntryCount()), sets);
    d.setValueTypeface(tf);
    return d;
}
 
Example 13
Source File: RideDetailActivity.java    From android-ponewheel with MIT License 5 votes vote down vote up
private void setupDatasetWithDefaultValues(LineDataSet dataSet) {
    dataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
    dataSet.setColor(ColorTemplate.getHoloBlue());
    dataSet.setValueTextColor(ColorTemplate.getHoloBlue());
    dataSet.setLineWidth(1.5f);
    dataSet.setDrawCircles(false);
    dataSet.setDrawValues(false);
    dataSet.setFillAlpha(65);
    dataSet.setFillColor(ColorTemplate.getHoloBlue());
    dataSet.setHighLightColor(Color.rgb(244, 117, 117));
    dataSet.setDrawCircleHole(false);
}
 
Example 14
Source File: ChartStatistics.java    From TwistyTimer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Adds the main data set for all times and the data set for the progression of record best
 * times among all times. The progression of best times are marked in a different color to the
 * main line of all time using circles lined with a dashed line. This will appear to connect
 * the lowest troughs along the main line of all times.
 *
 * @param chartData The chart data to which to add the new data sets.
 * @param allLabel  The label of the all-times line.
 * @param allColor  The color of the all-times line.
 * @param bestLabel The label of the best-times line.
 * @param bestColor The color of the best-times line.
 */
private void addMainDataSets(LineData chartData, String allLabel, int allColor,
                             String bestLabel, int bestColor) {
    // Main data set for all solve times.
    final LineDataSet mainDataSet = createDataSet(allLabel, allColor);

    mainDataSet.setDrawCircles(getDrawCircle());
    mainDataSet.setCircleRadius(getCircleRadius());
    mainDataSet.setCircleColor(allColor);
    mainDataSet.setColor(getLineColor(allColor));

    chartData.addDataSet(mainDataSet);

    // Data set to show the progression of best times along the main line of all times.
    final LineDataSet bestDataSet = createDataSet(bestLabel, bestColor);

    bestDataSet.enableDashedLine(3f, 6f, 0f);

    bestDataSet.setDrawCircles(true);
    bestDataSet.setCircleRadius(BEST_TIME_CIRCLE_RADIUS_DP);
    bestDataSet.setCircleColor(bestColor);

    bestDataSet.setDrawValues(false);
    bestDataSet.setValueTextColor(bestColor);
    bestDataSet.setValueTextSize(BEST_TIME_VALUES_TEXT_SIZE_DP);
    bestDataSet.setValueFormatter(new TimeChartValueFormatter());

    chartData.addDataSet(bestDataSet);
}
 
Example 15
Source File: PlayActivity.java    From Synapse with Apache License 2.0 5 votes vote down vote up
private void changeStyle(long id, LineChart chart, LineDataSet set) {
    final int index = (int) (id % FG.length);
    final Context context = chart.getContext();

    final int fg = ContextCompat.getColor(context, FG[index]);
    set.setColor(fg);
    set.setFillColor(fg);
    mLowerBg.setBackgroundColor(fg);

    getWindow().setBackgroundDrawableResource(BG[index]);
}
 
Example 16
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);
}
 
Example 17
Source File: ReportAdapter.java    From privacy-friendly-interval-timer with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    switch (getItemViewType(position)) {
        case TYPE_CHART:
            ActivityChart barChartData = (ActivityChart) mItems.get(position);
            CombinedChartViewHolder barChartViewHolder = (CombinedChartViewHolder) holder;
            barChartViewHolder.mTitleTextView.setText(barChartData.getTitle());
            int barChartI = 0;
            ArrayList<String> barChartXValues = new ArrayList<>();
            Map<String, Double> barChartDataMap;
            String barChartLabel;
            if (barChartData.getDisplayedDataType() == null) {
                barChartDataMap = barChartData.getTime();
                barChartLabel = barChartViewHolder.context.getString(R.string.report_workout_time);
            } else {
                switch (barChartData.getDisplayedDataType()) {
                    case CALORIES:
                        barChartDataMap = barChartData.getCalories();
                        barChartLabel = barChartViewHolder.context.getString(R.string.report_calories);
                        break;
                    case TIME:
                    default:
                        barChartDataMap = barChartData.getTime();
                        barChartLabel = barChartViewHolder.context.getString(R.string.report_workout_time);
                        break;
                }
            }
            List<BarEntry> dataEntries = new ArrayList<>();
            for (Map.Entry<String, Double> dataEntry : barChartDataMap.entrySet()) {
                barChartXValues.add(barChartI, dataEntry.getKey());
                if (dataEntry.getValue() != null) {
                    float val = dataEntry.getValue().floatValue();
                    dataEntries.add(new BarEntry(barChartI, val));
                }
                barChartI++;
            }
            BarDataSet barDataSet = new BarDataSet(dataEntries, barChartLabel);
            String formatPattern = "###,###,##0.0";
            barDataSet.setValueFormatter(new DoubleValueFormatter(formatPattern));

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

            // make sure, that the first and last entry are fully displayed
            Entry start = new Entry(0, 0);
            Entry end = new Entry(barChartI - 1, 0);
            LineDataSet chartLineDataSet = new LineDataSet(Arrays.asList(start, end), "");
            chartLineDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
            chartLineDataSet.setDrawCircles(false);
            chartLineDataSet.setColor(ContextCompat.getColor(barChartViewHolder.context, R.color.transparent), 0);
            chartLineDataSet.setDrawValues(false);
            lineDataSets.add(chartLineDataSet);

            CombinedData combinedData = new CombinedData();
            BarData barData = new BarData(barDataSet);
            barData.setBarWidth(0.5f);
            combinedData.setData(barData);
            combinedData.setData(new LineData(lineDataSets));
            barDataSet.setColor(ContextCompat.getColor(barChartViewHolder.context, R.color.colorPrimary));
            barChartViewHolder.mChart.setData(combinedData);
            barChartViewHolder.mChart.getXAxis().setValueFormatter(new ArrayListAxisValueFormatter(barChartXValues));
            barChartViewHolder.mChart.invalidate();
            break;
        case TYPE_SUMMARY:
            ActivitySummary summaryData = (ActivitySummary) mItems.get(position);
            SummaryViewHolder summaryViewHolder = (SummaryViewHolder) holder;
            summaryViewHolder.mTitleTextView.setText(summaryData.getTitle());
            summaryViewHolder.mTimeTextView.setText(formatTime(summaryData.getTime()));
            summaryViewHolder.mCaloriesTextView.setText(String.valueOf(summaryData.getCalories()));
            break;
    }
}
 
Example 18
Source File: MultiLineChartActivity.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    
    mChart.resetTracking();

    tvX.setText("" + (mSeekBarX.getProgress()));
    tvY.setText("" + (mSeekBarY.getProgress()));

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

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

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

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

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

        int color = mColors[z % mColors.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(xVals, dataSets);
    mChart.setData(data);
    mChart.invalidate();
}
 
Example 19
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 20
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);

}