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

The following examples show how to use com.github.mikephil.charting.data.LineDataSet#setAxisDependency() . 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: KlineFragment.java    From shinny-futures-android with GNU General Public License v3.0 6 votes vote down vote up
private LineDataSet generateMALineDataSet(int para, int color, String label) {
    List<Entry> entries = new ArrayList<>();
    for (int i = mLeftIndex + para - 1; i <= mLastIndex; i++) {
        Entry entry = generateMALineDataEntry(i, para - 1);
        entries.add(entry);
    }
    LineDataSet set = new LineDataSet(entries, label);
    set.setColor(color);
    set.setLineWidth(0.7f);
    set.setDrawCircles(false);
    set.setDrawCircleHole(false);
    set.setDrawValues(false);
    set.setHighlightEnabled(false);
    set.setAxisDependency(YAxis.AxisDependency.LEFT);
    return set;
}
 
Example 2
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 3
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 4
Source File: CombinedChartActivity.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
private LineData generateLineData() {

        LineData d = new LineData();

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

        for (int index = 0; index < count; index++)
            entries.add(new Entry(index + 0.5f, getRandom(15, 5)));

        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.setMode(LineDataSet.Mode.CUBIC_BEZIER);
        set.setDrawValues(true);
        set.setValueTextSize(10f);
        set.setValueTextColor(Color.rgb(240, 238, 70));

        set.setAxisDependency(YAxis.AxisDependency.LEFT);
        d.addDataSet(set);

        return d;
    }
 
Example 5
Source File: TrainedModelViewBinder.java    From Synapse with Apache License 2.0 6 votes vote down vote up
private LineDataSet prepareInitData(@NonNull LineChart chart, @NonNull List<Entry> entries) {
    final LineDataSet set = new LineDataSet(entries, "Accuracy");

    set.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
    set.setAxisDependency(YAxis.AxisDependency.LEFT);
    set.setLineWidth(2F);
    set.setDrawCircleHole(false);
    set.setDrawCircles(false);
    set.setHighlightEnabled(false);
    set.setDrawFilled(true);

    final LineData group = new LineData(set);
    group.setDrawValues(false);

    chart.setData(group);

    return set;
}
 
Example 6
Source File: RealtimeLineChartActivity.java    From StockChart-MPAndroidChart with MIT License 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 7
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 8
Source File: DynamicalAddingActivity.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
private LineDataSet createSet() {

        LineDataSet set = new LineDataSet(null, "DataSet 1");
        set.setLineWidth(2.5f);
        set.setCircleRadius(4.5f);
        set.setColor(Color.rgb(240, 99, 99));
        set.setCircleColor(Color.rgb(240, 99, 99));
        set.setHighLightColor(Color.rgb(190, 190, 190));
        set.setAxisDependency(AxisDependency.LEFT);
        set.setValueTextSize(10f);

        return set;
    }
 
Example 9
Source File: ReportAdapter.java    From privacy-friendly-pedometer with GNU General Public License v3.0 5 votes vote down vote up
private LineDataSet getNewChartLineDataSet(Context context, String label){
    LineDataSet chartLineDataSet = new LineDataSet(new ArrayList<Entry>(), label);
    chartLineDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
    chartLineDataSet.setLineWidth(3);
    chartLineDataSet.setCircleRadius(3.5f);
    chartLineDataSet.setDrawCircleHole(false);
    chartLineDataSet.setColor(ContextCompat.getColor(context, R.color.colorPrimary), 200);
    chartLineDataSet.setCircleColor(ContextCompat.getColor(context, R.color.colorPrimary));
    chartLineDataSet.setDrawValues(false);

    return chartLineDataSet;
}
 
Example 10
Source File: ModelDetailActivity.java    From Synapse with Apache License 2.0 5 votes vote down vote up
private boolean setUpChart(@NonNull Model model) {
    final double[] accuracies = model.getAccuracies();

    if (accuracies == null
            || accuracies.length == 0
            || model.getStepEpoch() < 1) {
        return false;
    }

    mAccuracyData.clear();

    for (int i = 0, len = model.getStepEpoch(); i < len; ++i) {
        mAccuracyData.add(new Entry(i + 1, (float) accuracies[i]));
    }

    final LineDataSet set = new LineDataSet(mAccuracyData, getString(R.string.text_chart_left_axis));

    set.setMode(LineDataSet.Mode.LINEAR);
    set.setAxisDependency(YAxis.AxisDependency.LEFT);
    set.setColor(ContextCompat.getColor(this, R.color.chart_left_axis));
    set.setCircleColor(ContextCompat.getColor(this, R.color.chart_left_axis));
    set.setHighLightColor(ContextCompat.getColor(this, R.color.chart_highlight));
    set.setCircleColorHole(Color.WHITE);
    set.setDrawCircleHole(true);
    set.setHighlightEnabled(true);
    set.setLineWidth(2F);
    set.setCircleRadius(3F);
    set.setDrawFilled(false);

    final LineData group = new LineData(set);
    group.setDrawValues(false);

    setXAxis(model.getEpochs());

    mChart.setData(group);
    mChart.invalidate();
    startChartAnimate();

    return true;
}
 
Example 11
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 12
Source File: LineChartTime.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
private void setData(int count, float range) {

        // now in hours
        long now = TimeUnit.MILLISECONDS.toHours(System.currentTimeMillis());

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

        // count = hours
        float to = now + count;

        // increment by 1 hour
        for (float x = now; x < to; x++) {

            float y = getRandom(range, 50);
            values.add(new Entry(x, y)); // add one entry per hour
        }

        // create a dataset and give it a type
        LineDataSet set1 = new LineDataSet(values, "DataSet 1");
        set1.setAxisDependency(AxisDependency.LEFT);
        set1.setColor(ColorTemplate.getHoloBlue());
        set1.setValueTextColor(ColorTemplate.getHoloBlue());
        set1.setLineWidth(1.5f);
        set1.setDrawCircles(false);
        set1.setDrawValues(false);
        set1.setFillAlpha(65);
        set1.setFillColor(ColorTemplate.getHoloBlue());
        set1.setHighLightColor(Color.rgb(244, 117, 117));
        set1.setDrawCircleHole(false);

        // create a data object with the data sets
        LineData data = new LineData(set1);
        data.setValueTextColor(Color.WHITE);
        data.setValueTextSize(9f);

        // set data
        chart.setData(data);
    }
 
Example 13
Source File: StatisticsFragment.java    From HeartBeat with Apache License 2.0 5 votes vote down vote up
private LineData getWeekThoughtData() {
    LineData d = new LineData();

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

    for (int i=0; i<WEEK_COUNT; i++) {
        entries.add(
                new BarEntry(
                        new GetCountSpecDayApi(getActivity()).exec(
                                TimeUtils.calendarDaysBefore(WEEK_COUNT-i),
                                GetCountSpecDayApi.THOUGHT
                        ),i
                )
        );
    }

    LineDataSet set = new LineDataSet(entries, getString(R.string.thought_count_text));
    set.setColor(mAccentColor);
    set.setLineWidth(2.5f);
    set.setAxisDependency(YAxis.AxisDependency.LEFT);
    set.setCircleColor(mPrimaryColorDark);
    set.setCircleSize(5f);
    set.setFillColor(mPrimaryColor);
    set.setDrawValues(true);
    set.setValueFormatter(new IntValueFormatter());
    d.addDataSet(set);
    return d;
}
 
Example 14
Source File: Utils.java    From Aria2App with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
private static LineDataSet initUploadSet(Context context) {
    LineDataSet set = new LineDataSet(null, context.getString(R.string.uploadSpeed));
    set.setAxisDependency(YAxis.AxisDependency.LEFT);
    set.setLineWidth(2f);
    set.setColor(ContextCompat.getColor(context, R.color.uploadColor));
    set.setDrawCircles(false);
    set.setDrawValues(false);
    set.setMode(LineDataSet.Mode.CUBIC_BEZIER);
    set.setDrawFilled(false);
    return set;
}
 
Example 15
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 16
Source File: KLineView.java    From android-kline with Apache License 2.0 4 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 == K) {
        lineDataSetMa.setColor(getResources().getColor(R.color.k));
        lineDataSetMa.setCircleColor(mTransparentColor);
    } else if (type == D) {
        lineDataSetMa.setColor(getResources().getColor(R.color.d));
        lineDataSetMa.setCircleColor(mTransparentColor);
        lineDataSetMa.setHighlightEnabled(false);
    } else if (type == J) {
        lineDataSetMa.setColor(getResources().getColor(R.color.j));
        lineDataSetMa.setCircleColor(mTransparentColor);
        lineDataSetMa.setHighlightEnabled(false);
    } else if (type == DIF) {
        lineDataSetMa.setColor(getResources().getColor(R.color.dif));
        lineDataSetMa.setCircleColor(mTransparentColor);
        lineDataSetMa.setHighlightEnabled(false);
    } else if (type == DEA) {
        lineDataSetMa.setColor(getResources().getColor(R.color.dea));
        lineDataSetMa.setCircleColor(mTransparentColor);
        lineDataSetMa.setHighlightEnabled(false);
    } else if (type == AVE_LINE) {
        lineDataSetMa.setColor(getResources().getColor(R.color.ave_color));
        lineDataSetMa.setCircleColor(mTransparentColor);
        lineDataSetMa.setHighlightEnabled(false);
    } else if (type == MA5) {
        lineDataSetMa.setColor(getResources().getColor(R.color.ma5));
        lineDataSetMa.setCircleColor(mTransparentColor);
        lineDataSetMa.setHighlightEnabled(false);
    } else if (type == MA10) {
        lineDataSetMa.setColor(getResources().getColor(R.color.ma10));
        lineDataSetMa.setCircleColor(mTransparentColor);
        lineDataSetMa.setHighlightEnabled(false);
    } else if (type == MA20) {
        lineDataSetMa.setColor(getResources().getColor(R.color.ma20));
        lineDataSetMa.setCircleColor(mTransparentColor);
        lineDataSetMa.setHighlightEnabled(false);
    } else if (type == MA30) {
        lineDataSetMa.setColor(getResources().getColor(R.color.ma30));
        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 17
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 18
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 19
Source File: RecordGraphFragment.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, @Nullable Bundle savedInstanceState)
{
    CombinedChart chart = (CombinedChart) view.findViewById(R.id.recording_chart);

    pitchDataSet = new LineDataSet(mListener.startingPitchEntries(), getResources().getString(R.string.progress));
    // generate x value strings
    // [1, 2, 3,... basically random numbers as the recorded pitch is based on processor speed]
    List<String> xVals = ChartData.generateXVals(0, pitchDataSet.getEntryCount());
    chartData = new CombinedData(xVals);

    pitchDataSet.setColor(getResources().getColor(R.color.canvas_dark));
    pitchDataSet.setDrawCircles(false);
    pitchDataSet.setLineWidth(2f);
    pitchDataSet.setDrawValues(false);
    pitchDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);

    pitchData = new LineData(xVals, pitchDataSet);
    chartData.setData(pitchData);

    genderBarData = new BarData(xVals, GraphLayout.getOverallRange(this.getContext(), xVals.size()));
    // Bug with chart lib that throws exception for empty bar charts so must skip adding it on init
    // if were coming from the live pitch graph.
    if (!xVals.isEmpty())
        chartData.setData(genderBarData);

    chart.setData(chartData);

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

    GraphLayout.FormatChart(chart);

    super.onViewCreated(view, savedInstanceState);
}
 
Example 20
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);
    }