com.github.mikephil.charting.data.LineDataSet Java Examples

The following examples show how to use com.github.mikephil.charting.data.LineDataSet. 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: 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 #3
Source File: ChartStatistics.java    From TwistyTimer with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a data set with the given label and color. Highlights and drawing of values and
 * circles are disabled, as that is common for many cases.
 *
 * @param label The label to assign to the new data set.
 * @param color The line color to set for the new data set.
 */
private LineDataSet createDataSet(String label, int color) {
    // A legend is enabled on the chart view in the graph fragment. The legend is created
    // automatically, but requires a unique labels and colors on each data set.
    final LineDataSet dataSet = new LineDataSet(null, label);

    // A dashed line can make peaks inaccurate. It also makes the graph look too "busy". It
    // is OK for some uses, such as progressions of best times, but that is left to the caller
    // to change once this new data set is returned.
    //
    // If graphing only times for a session, there will be fewer, and a thicker line will look
    // well. However, if all times are graphed, a thinner line will probably look better, as
    // the finer details will be more visible.
    //
    // Also, the library specifies that a thicker line has increased performance use compared
    // thinner lines, so don't make lines too thick if the dataset is large!
    dataSet.setLineWidth(getLineWidth());
    dataSet.setColor(color);
    dataSet.setHighlightEnabled(false);

    dataSet.setDrawCircles(false);
    dataSet.setDrawValues(false);

    return dataSet;
}
 
Example #4
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 #5
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 #6
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 #7
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 #8
Source File: LineChartActivityColored.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
private LineData getData(int count, float range) {

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

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

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

        set1.setLineWidth(1.75f);
        set1.setCircleRadius(5f);
        set1.setCircleHoleRadius(2.5f);
        set1.setColor(Color.WHITE);
        set1.setCircleColor(Color.WHITE);
        set1.setHighLightColor(Color.WHITE);
        set1.setDrawValues(false);

        // create a data object with the data sets
        return new LineData(set1);
    }
 
Example #9
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 #10
Source File: CurrentDayFragment.java    From shinny-futures-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * date: 6/1/18
 * 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) {
        refreshYAxisRange(set);
        set.setHighlightLineWidth(0.7f);
        set.setHighLightColor(mHighlightColor);
    } else {
        set.setHighlightEnabled(false);
    }
    return set;
}
 
Example #11
Source File: DrawChartActivity.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
private void initWithDummyData() {
    ArrayList<String> xVals = new ArrayList<String>();
    for (int i = 0; i < 24; i++) {
        xVals.add((i) + ":00");
    }

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

    // create a dataset and give it a type (0)
    LineDataSet set1 = new LineDataSet(yVals, "DataSet");
    set1.setLineWidth(3f);
    set1.setCircleRadius(5f);

    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);

    mChart.setData(data);
}
 
Example #12
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 #13
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 #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: SimpleFragment.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
protected LineData generateLineData() {
        
//        DataSet ds1 = new DataSet(n, "O(n)");  
//        DataSet ds2 = new DataSet(nlogn, "O(nlogn)"); 
//        DataSet ds3 = new DataSet(nsquare, "O(n\u00B2)");
//        DataSet ds4 = new DataSet(nthree, "O(n\u00B3)");
        
        ArrayList<ILineDataSet> sets = new ArrayList<ILineDataSet>();
        
        LineDataSet ds1 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "sine.txt"), "Sine function");
        LineDataSet ds2 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().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 textfiles in assets folders
        sets.add(ds1);
        sets.add(ds2);
        
//        sets.add(FileUtils.dataSetFromAssets(getActivity().getAssets(), "n.txt"));
//        sets.add(FileUtils.dataSetFromAssets(getActivity().getAssets(), "nlogn.txt"));
//        sets.add(FileUtils.dataSetFromAssets(getActivity().getAssets(), "square.txt"));
//        sets.add(FileUtils.dataSetFromAssets(getActivity().getAssets(), "three.txt"));
        
        int max = Math.max(sets.get(0).getEntryCount(), sets.get(1).getEntryCount());
        
        LineData d = new LineData(ChartData.generateXVals(0, max),  sets);
        d.setValueTypeface(tf);
        return d;
    }
 
Example #16
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 #17
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 #18
Source File: TrafficFragment.java    From gito-github-client with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private void chartDataSetStyling(LineDataSet dataSet) {
    dataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
    dataSet.setColor(SettingsActivity.ThemePreferenceFragment.isLight(getContext()) ?
            getResources().getColor(R.color.traffic_chart_line_color_light) :
            getResources().getColor(R.color.traffic_chart_line_color_dark));
    dataSet.setLineWidth(2f);
    dataSet.setCircleRadius(4f);
    dataSet.setDrawValues(false);
    dataSet.setDrawCircleHole(false);
    dataSet.setCircleColor(SettingsActivity.ThemePreferenceFragment.isLight(getContext()) ?
            getResources().getColor(R.color.traffic_chart_line_color_light) :
            getResources().getColor(R.color.traffic_chart_line_color_dark));
}
 
Example #19
Source File: LineChartRenderer.java    From iMoney with Apache License 2.0 5 votes vote down vote up
@Override
public void drawData(Canvas c) {

    int width = (int) mViewPortHandler.getChartWidth();
    int height = (int) mViewPortHandler.getChartHeight();

    if (mDrawBitmap == null
            || (mDrawBitmap.getWidth() != width)
            || (mDrawBitmap.getHeight() != height)) {

        if (width > 0 && height > 0) {

            mDrawBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);
            mBitmapCanvas = new Canvas(mDrawBitmap);
        } else
            return;
    }

    mDrawBitmap.eraseColor(Color.TRANSPARENT);

    LineData lineData = mChart.getLineData();

    for (LineDataSet set : lineData.getDataSets()) {

        if (set.isVisible() && set.getEntryCount() > 0)
            drawDataSet(c, set);
    }

    c.drawBitmap(mDrawBitmap, 0, 0, mRenderPaint);
}
 
Example #20
Source File: ScreenResponseFragment.java    From walt with Apache License 2.0 5 votes vote down vote up
private void drawBrightnessChart() {
    final String brightnessCurveString = brightnessCurveData.toString();
    List<Entry> entries = new ArrayList<>();

    // "u" marks the start of the brightness curve data
    int startIndex = brightnessCurveString.indexOf("u") + 1;
    int endIndex = brightnessCurveString.indexOf("end");
    if (endIndex == -1) endIndex = brightnessCurveString.length();

    String[] brightnessStrings =
            brightnessCurveString.substring(startIndex, endIndex).trim().split("\n");
    for (String str : brightnessStrings) {
        String[] arr = str.split(" ");
        final float timestampMs = Integer.parseInt(arr[0]) / 1000f;
        final float brightness = Integer.parseInt(arr[1]);
        entries.add(new Entry(timestampMs, brightness));
    }
    LineDataSet dataSet = new LineDataSet(entries, "Brightness");
    dataSet.setColor(Color.BLACK);
    dataSet.setValueTextColor(Color.BLACK);
    dataSet.setCircleColor(Color.BLACK);
    dataSet.setCircleRadius(1.5f);
    dataSet.setCircleColorHole(Color.DKGRAY);
    LineData lineData = new LineData(dataSet);
    brightnessChart.setData(lineData);
    final Description desc = new Description();
    desc.setText("Screen Brightness [digital level 0-1023] vs. Time [ms]");
    desc.setTextSize(12f);
    brightnessChart.setDescription(desc);
    brightnessChart.getLegend().setEnabled(false);
    brightnessChart.invalidate();
    brightnessChartLayout.setVisibility(View.VISIBLE);
}
 
Example #21
Source File: LineChartRenderer.java    From iMoney with Apache License 2.0 5 votes vote down vote up
@Override
public void initBuffers() {

    LineData lineData = mChart.getLineData();
    mLineBuffers = new LineBuffer[lineData.getDataSetCount()];
    mCircleBuffers = new CircleBuffer[lineData.getDataSetCount()];

    for (int i = 0; i < mLineBuffers.length; i++) {
        LineDataSet set = lineData.getDataSetByIndex(i);
        mLineBuffers[i] = new LineBuffer(set.getEntryCount() * 4 - 4);
        mCircleBuffers[i] = new CircleBuffer(set.getEntryCount() * 2);
    }
}
 
Example #22
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 #23
Source File: LineChart.java    From Notification-Analyser with MIT License 5 votes vote down vote up
@Override
protected void drawHighlights() {

    for (int i = 0; i < mIndicesToHightlight.length; i++) {

        LineDataSet set = mOriginalData.getDataSetByIndex(mIndicesToHightlight[i]
                .getDataSetIndex());

        if (set == null)
            continue;

        mHighlightPaint.setColor(set.getHighLightColor());

        int xIndex = mIndicesToHightlight[i].getXIndex(); // get the
                                                          // x-position

        if (xIndex > mDeltaX * mPhaseX)
            continue;

        float y = set.getYValForXIndex(xIndex) * mPhaseY; // get the
                                                          // y-position

        float[] pts = new float[] {
                xIndex, mYChartMax, xIndex, mYChartMin, 0, y, mDeltaX, y
        };

        transformPointArray(pts);
        // draw the highlight lines
        mDrawCanvas.drawLines(pts, mHighlightPaint);
    }
}
 
Example #24
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 #25
Source File: LineChartRenderer.java    From iMoney with Apache License 2.0 5 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    for (int i = 0; i < indices.length; i++) {

        LineDataSet set = mChart.getLineData().getDataSetByIndex(indices[i]
                .getDataSetIndex());

        if (set == null || !set.isHighlightEnabled())
            continue;

        int xIndex = indices[i].getXIndex(); // get the
                                             // x-position

        if (xIndex > mChart.getXChartMax() * mAnimator.getPhaseX())
            continue;

        final float yVal = set.getYValForXIndex(xIndex);
        if (yVal == Float.NaN)
            continue;

        float y = yVal * mAnimator.getPhaseY(); // get
                                                                        // the
        // y-position

        float[] pts = new float[] {
                xIndex, y
        };

        mChart.getTransformer(set.getAxisDependency()).pointValuesToPixel(pts);

        // draw the lines
        drawHighlightLines(c, pts, set);
    }
}
 
Example #26
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 #27
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 #28
Source File: TrainedModelViewBinder.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);

    chart.setGridBackgroundColor(ContextCompat.getColor(context, BG[index]));
}
 
Example #29
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 #30
Source File: RecordingFragment.java    From go-bees with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Configure styles of weather charts.
 *
 * @param entries   chart data.
 * @param formatter value formatter.
 * @param minVal    min value to show.
 * @param maxVal    max value to show.
 * @return chart formatted.
 */
private LineDataSet configureWeatherChart(
        LineChart chart, int chartName, int colorLineTempChart, int colorFillTempChart,
        List<Entry> entries, IAxisValueFormatter formatter, double minVal, double maxVal) {
    LineDataSet lineDataSet = new LineDataSet(entries, getString(chartName));
    lineDataSet.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
    lineDataSet.setDrawValues(false);
    lineDataSet.setValueTextSize(10f);
    lineDataSet.setDrawCircles(false);
    lineDataSet.setLineWidth(1.8f);
    lineDataSet.setColor(ContextCompat.getColor(getContext(), colorLineTempChart));
    lineDataSet.setLineWidth(2f);
    lineDataSet.setDrawFilled(true);
    lineDataSet.setFillColor(ContextCompat.getColor(getContext(), colorFillTempChart));
    lineDataSet.setFillAlpha(255);
    // General setup
    chart.setDrawGridBackground(false);
    chart.setDrawBorders(false);
    chart.setViewPortOffsets(0, 0, 0, 0);
    chart.getDescription().setEnabled(false);
    chart.getLegend().setEnabled(false);
    chart.setTouchEnabled(false);
    // X axis setup
    XAxis xAxis = chart.getXAxis();
    xAxis.setEnabled(false);
    xAxis.setAxisMinimum(0);
    xAxis.setAxisMaximum(lastTimestamp);
    // Y axis setup
    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.setEnabled(false);
    leftAxis.setAxisMaximum((float) (maxVal));
    leftAxis.setAxisMinimum((float) (minVal));
    YAxis rightAxis = chart.getAxisRight();
    rightAxis.setAxisMaximum((float) (maxVal));
    rightAxis.setAxisMinimum((float) (minVal));
    rightAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
    rightAxis.setValueFormatter(formatter);
    return lineDataSet;
}