Java Code Examples for com.github.mikephil.charting.interfaces.datasets.ILineDataSet

The following examples show how to use com.github.mikephil.charting.interfaces.datasets.ILineDataSet. These examples are extracted from open source projects. 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 Project: android-kline   Source File: TickChart.java    License: 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 Project: bcm-android   Source File: FragmentPrice.java    License: 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 Project: android-kline   Source File: LineChartRenderer.java    License: Apache License 2.0 6 votes vote down vote up
protected void drawCubicFill(Canvas c, ILineDataSet dataSet, Path spline, Transformer trans, XBounds bounds) {

        float fillMin = dataSet.getFillFormatter()
                .getFillLinePosition(dataSet, mChart);

        spline.lineTo(dataSet.getEntryForIndex(bounds.min + bounds.range).getX(), fillMin);
        spline.lineTo(dataSet.getEntryForIndex(bounds.min).getX(), fillMin);
        spline.close();

        trans.pathValueToPixel(spline);

        final Drawable drawable = dataSet.getFillDrawable();
        if (drawable != null) {

            drawFilledPath(c, spline, drawable);
        } else {

            drawFilledPath(c, spline, dataSet.getFillColor(), dataSet.getFillAlpha());
        }
    }
 
Example 4
private void addGoalLine(List<ILineDataSet> lineDataSets) {
    if (prefs.getBoolean("goalLine", true)) {
        List<Entry> valuesGoalLine = new Stack<>();

        ScaleUser user = OpenScale.getInstance().getSelectedScaleUser();
        float goalWeight = Converters.fromKilogram(user.getGoalWeight(), user.getScaleUnit());

        valuesGoalLine.add(new Entry(minXValue, goalWeight));
        valuesGoalLine.add(new Entry(maxXValue, goalWeight));

        LineDataSet goalLine = new LineDataSet(valuesGoalLine, getContext().getString(R.string.label_goal_line));
        goalLine.setLineWidth(1.5f);
        goalLine.setColor(ColorUtil.COLOR_GREEN);
        goalLine.setAxisDependency(prefs.getBoolean("weightOnRightAxis", true) ? YAxis.AxisDependency.RIGHT : YAxis.AxisDependency.LEFT);
        goalLine.setDrawValues(false);
        goalLine.setDrawCircles(false);
        goalLine.setHighlightEnabled(false);
        goalLine.enableDashedLine(10, 30, 0);

        lineDataSets.add(goalLine);
    }
}
 
Example 5
Source Project: StockChart-MPAndroidChart   Source File: LineChartRenderer.java    License: MIT License 6 votes vote down vote up
protected void drawCubicFill(Canvas c, ILineDataSet dataSet, Path spline, Transformer trans, XBounds bounds) {

        float fillMin = dataSet.getFillFormatter()
                .getFillLinePosition(dataSet, mChart);

        spline.lineTo(dataSet.getEntryForIndex(bounds.min + bounds.range).getX(), fillMin);
        spline.lineTo(dataSet.getEntryForIndex(bounds.min).getX(), fillMin);
        spline.close();

        trans.pathValueToPixel(spline);

        final Drawable drawable = dataSet.getFillDrawable();
        if (drawable != null) {

            drawFilledPath(c, spline, drawable);
        } else {

            drawFilledPath(c, spline, dataSet.getFillColor(), dataSet.getFillAlpha());
        }
    }
 
Example 6
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_temp_graph, container, false);
    setUnbinder(ButterKnife.bind(this, view));

    ArrayList<ILineDataSet> dataSets = new ArrayList<>();
    addLineDataSet(createModel(ACTUAL_TEMP_BED_LABEL), dataSets);
    addLineDataSet(createModel(TARGET_TEMP_BED_LABEL), dataSets);
    addLineDataSet(createModel(ACTUAL_TEMP_TOOL0_LABEL), dataSets);
    addLineDataSet(createModel(TARGET_TEMP_TOOL0_LABEL), dataSets);
    addLineDataSet(createModel(ACTUAL_TEMP_TOOL1_LABEL), dataSets);
    addLineDataSet(createModel(TARGET_TEMP_TOOL1_LABEL), dataSets);

    TempLineData lineData = new TempLineData(new ArrayList<String>(), dataSets);
    mLineChart.setData(lineData);
    mLineChart.invalidate();
    if (savedInstanceState != null) restoreSavedInstanceState(savedInstanceState);
    return view;
}
 
Example 7
private void removeLastEntry() {

        LineData data = chart.getData();

        if (data != null) {

            ILineDataSet set = data.getDataSetByIndex(0);

            if (set != null) {

                Entry e = set.getEntryForXValue(set.getEntryCount() - 1, Float.NaN);

                data.removeEntry(e, 0);
                // or remove by index
                // mData.removeEntryByXValue(xIndex, dataSetIndex);
                data.notifyDataChanged();
                chart.notifyDataSetChanged();
                chart.invalidate();
            }
        }
    }
 
Example 8
Source Project: Stayfit   Source File: LineChartRenderer.java    License: Apache License 2.0 6 votes vote down vote up
protected void drawDataSet(Canvas c, ILineDataSet dataSet) {

        if (dataSet.getEntryCount() < 1)
            return;

        mRenderPaint.setStrokeWidth(dataSet.getLineWidth());
        mRenderPaint.setPathEffect(dataSet.getDashPathEffect());

        // if drawing cubic lines is enabled
        if (dataSet.isDrawCubicEnabled()) {

            drawCubic(c, dataSet);

            // draw normal (straight) lines
        } else {
            drawLinear(c, dataSet);
        }

        mRenderPaint.setPathEffect(null);
    }
 
Example 9
Source Project: Ticket-Analysis   Source File: LineChartRenderer.java    License: MIT License 6 votes vote down vote up
/**
 * Sets up the cache, returns true if a change of cache was required.
 *
 * @param set
 * @return
 */
protected boolean init(ILineDataSet set) {

    int size = set.getCircleColorCount();
    boolean changeRequired = false;

    if (circleBitmaps == null) {
        circleBitmaps = new Bitmap[size];
        changeRequired = true;
    } else if (circleBitmaps.length != size) {
        circleBitmaps = new Bitmap[size];
        changeRequired = true;
    }

    return changeRequired;
}
 
Example 10
Source Project: Ticket-Analysis   Source File: LineChartHelper.java    License: MIT License 6 votes vote down vote up
public ILineDataSet generateLineDataSet(List<Entry> yEntrys, int color, String label) {
        LineDataSet dataSet = new LineDataSet(yEntrys, label);
        dataSet.setLineWidth(2.0f);
        dataSet.setCircleRadius(3.5f);
        dataSet.setDrawCircleHole(true);//填充圆
//        dataSet.setDrawValues(true);
//        dataSet.setValueTextColor(color);
        dataSet.setValueTextSize(9f);
        dataSet.setHighlightLineWidth(2.0f);
//        dataSet.setDrawFilled(true);//区域颜色
        dataSet.setFillAlpha(51);
//        dataSet.setFillColor(color); //填充色
        dataSet.setHighLightColor(color); //选中十字线色
        dataSet.setColor(color); //线条颜色
        dataSet.setCircleColor(color); //圆点颜色
        dataSet.setCircleColorHole(Color.WHITE);
        dataSet.setCircleHoleRadius(2.0f);
        dataSet.setDrawValues(false);
        return dataSet;
    }
 
Example 11
Source Project: android-kline   Source File: LineChartRenderer.java    License: Apache License 2.0 6 votes vote down vote up
protected void drawDataSet(Canvas c, ILineDataSet dataSet) {

        if (dataSet.getEntryCount() < 1)
            return;

        mRenderPaint.setStrokeWidth(dataSet.getLineWidth());
        mRenderPaint.setPathEffect(dataSet.getDashPathEffect());

        switch (dataSet.getMode()) {
            default:
            case LINEAR:
            case STEPPED:
                drawLinear(c, dataSet);
                break;

            case CUBIC_BEZIER:
                drawCubicBezier(dataSet);
                break;

            case HORIZONTAL_BEZIER:
                drawHorizontalBezier(dataSet);
                break;
        }

        mRenderPaint.setPathEffect(null);
    }
 
Example 12
public void setChartDataVisibility(View v, int k) {
    int interval_value = interval[position];
    int y_count = 7;
    LineChart chart = v.findViewById(R.id.reslog_chart);
    if (chart != null && chart.getLineData() != null) {
        ILineDataSet data = chart.getLineData().getDataSetByIndex(k);
        data.setVisible(is_draw_enabled[k]);
        int max_value = 0;
        int min_value = maximum[position];
        for (int i = 0; i < 4; i++) {
            if (is_draw_enabled[i]) {
                max_value = Math.max((int) chart.getLineData().getDataSetByIndex(i).getYMax(), max_value);
                min_value = Math.min((int) chart.getLineData().getDataSetByIndex(i).getYMin(), min_value);
            }
        }
        max_value = (int) (Math.ceil(max_value / (float) interval_value) * interval_value);
        min_value = (int) (Math.floor(min_value / (float) interval_value) * interval_value);
        int range = max_value - min_value;
        while (range % (y_count - 1) != 0) y_count -= 1;
        setChartYRange(chart, max_value, min_value, y_count, interval_value);
        chart.notifyDataSetChanged();
        chart.invalidate();
    }
}
 
Example 13
Source Project: android-kline   Source File: LineChartRenderer.java    License: Apache License 2.0 6 votes vote down vote up
protected void drawCubicFill(Canvas c, ILineDataSet dataSet, Path spline, Transformer trans, XBounds bounds) {

        float fillMin = dataSet.getFillFormatter()
                .getFillLinePosition(dataSet, mChart);

        spline.lineTo(dataSet.getEntryForIndex(bounds.min + bounds.range).getX(), fillMin);
        spline.lineTo(dataSet.getEntryForIndex(bounds.min).getX(), fillMin);
        spline.close();

        trans.pathValueToPixel(spline);

        final Drawable drawable = dataSet.getFillDrawable();
        if (drawable != null) {

            drawFilledPath(c, spline, drawable);
        } else {

            drawFilledPath(c, spline, dataSet.getFillColor(), dataSet.getFillAlpha());
        }
    }
 
Example 14
Source Project: android-kline   Source File: LineChartRenderer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Sets up the cache, returns true if a change of cache was required.
 *
 * @param set
 * @return
 */
protected boolean init(ILineDataSet set) {

    int size = set.getCircleColorCount();
    boolean changeRequired = false;

    if (circleBitmaps == null) {
        circleBitmaps = new Bitmap[size];
        changeRequired = true;
    } else if (circleBitmaps.length != size) {
        circleBitmaps = new Bitmap[size];
        changeRequired = true;
    }

    return changeRequired;
}
 
Example 15
/**
 * date: 7/9/17
 * author: chenli
 * description: 生成均线数据
 */
private LineData generateMALineData() {
    List<ILineDataSet> dataSets = new ArrayList<>();
    for (int i = 0; i < mas.size(); i++) {
        int ma = mas.get(i);
        int color = mColorMas[i];
        LineDataSet set = generateMALineDataSet(ma, color, "MA" + ma);
        dataSets.add(set);
    }
    return new LineData(dataSets);
}
 
Example 16
Source Project: android-kline   Source File: KLineView.java    License: Apache License 2.0 5 votes vote down vote up
private void initChartKdjData() {
    ArrayList<Entry> kEntries = new ArrayList<>(INIT_COUNT);
    ArrayList<Entry> dEntries = new ArrayList<>(INIT_COUNT);
    ArrayList<Entry> jEntries = new ArrayList<>(INIT_COUNT);
    ArrayList<Entry> paddingEntries = new ArrayList<>(INIT_COUNT);

    for (int i = 0; i < mData.size(); i++) {
        kEntries.add(new Entry(i, (float) mData.get(i).getK()));
        dEntries.add(new Entry(i, (float) mData.get(i).getD()));
        jEntries.add(new Entry(i, (float) mData.get(i).getJ()));
    }
    if (!mData.isEmpty() && mData.size() < MAX_COUNT) {
        for (int i = mData.size(); i < MAX_COUNT; i++) {
            paddingEntries.add(new Entry(i, (float) mData.get(mData.size() - 1).getK()));
        }
    }
    ArrayList<ILineDataSet> sets = new ArrayList<>();
    sets.add(setLine(K, kEntries));
    sets.add(setLine(D, dEntries));
    sets.add(setLine(J, jEntries));
    sets.add(setLine(INVISIABLE_LINE, paddingEntries));
    LineData lineData = new LineData(sets);

    CombinedData combinedData = new CombinedData();
    combinedData.setData(lineData);
    mChartKdj.setData(combinedData);

    mChartMacd.setVisibleXRange(MAX_COUNT, MIN_COUNT);

    mChartKdj.notifyDataSetChanged();
    moveToLast(mChartKdj);
}
 
Example 17
Source Project: Stayfit   Source File: DynamicalAddingActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void addEntry() {

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

            ILineDataSet set = data.getDataSetByIndex(0);
            // set.addEntry(...); // can be called as well

            if (set == null) {
                set = createSet();
                data.addDataSet(set);
            }

            // add a new x-value first
            data.addXValue(set.getEntryCount() + "");
            
            // choose a random dataSet
            int randomDataSetIndex = (int) (Math.random() * data.getDataSetCount());
            
            data.addEntry(new Entry((float) (Math.random() * 10) + 50f, set.getEntryCount()), randomDataSetIndex);

            // let the chart know it's data has changed
            mChart.notifyDataSetChanged();
            
            mChart.setVisibleXRangeMaximum(6);
            mChart.setVisibleYRangeMaximum(15, AxisDependency.LEFT);
//            
//            // this automatically refreshes the chart (calls invalidate())
            mChart.moveViewTo(data.getXValCount()-7, 50f, AxisDependency.LEFT);
        }
    }
 
Example 18
Source Project: StockChart-MPAndroidChart   Source File: DefaultFillFormatter.java    License: MIT License 5 votes vote down vote up
@Override
public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {

    float fillMin = 0f;
    float chartMaxY = dataProvider.getYChartMax();
    float chartMinY = dataProvider.getYChartMin();

    LineData data = dataProvider.getLineData();

    if (dataSet.getYMax() > 0 && dataSet.getYMin() < 0) {
        fillMin = 0f;
    } else {

        float max, min;

        if (data.getYMax() > 0) {
            max = 0f;
        } else {
            max = chartMaxY;
        }
        if (data.getYMin() < 0) {
            min = 0f;
        } else {
            min = chartMinY;
        }

        fillMin = dataSet.getYMin() >= 0 ? min : max;
    }

    return fillMin;
}
 
Example 19
Source Project: StockChart-MPAndroidChart   Source File: LineChartRenderer.java    License: MIT License 5 votes vote down vote up
@Override
public void drawData(Canvas c) {

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

    Bitmap drawBitmap = mDrawBitmap == null ? null : mDrawBitmap.get();

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

        if (width > 0 && height > 0) {
            drawBitmap = Bitmap.createBitmap(width, height, mBitmapConfig);
            mDrawBitmap = new WeakReference<>(drawBitmap);
            mBitmapCanvas = new Canvas(drawBitmap);
        } else
            return;
    }

    drawBitmap.eraseColor(Color.TRANSPARENT);

    LineData lineData = mChart.getLineData();

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

        if (set.isVisible()) {
            drawDataSet(c, set);
        }
    }

    c.drawBitmap(drawBitmap, 0, 0, mRenderPaint);
}
 
Example 20
Source Project: StockChart-MPAndroidChart   Source File: LineChartRenderer.java    License: MIT License 5 votes vote down vote up
/**
 * Draws a filled linear path on the canvas.
 *
 * @param c
 * @param dataSet
 * @param trans
 * @param bounds
 */
protected void drawLinearFill(Canvas c, ILineDataSet dataSet, Transformer trans, XBounds bounds) {

    final Path filled = mGenerateFilledPathBuffer;

    final int startingIndex = bounds.min;
    final int endingIndex = bounds.range + bounds.min;
    final int indexInterval = 128;

    int currentStartIndex = 0;
    int currentEndIndex = indexInterval;
    int iterations = 0;

    // Doing this iteratively in order to avoid OutOfMemory errors that can happen on large bounds sets.
    do {
        currentStartIndex = startingIndex + (iterations * indexInterval);
        currentEndIndex = currentStartIndex + indexInterval;
        currentEndIndex = currentEndIndex > endingIndex ? endingIndex : currentEndIndex;

        if (currentStartIndex <= currentEndIndex) {
            generateFilledPath(dataSet, currentStartIndex, currentEndIndex, filled);

            trans.pathValueToPixel(filled);

            final Drawable drawable = dataSet.getFillDrawable();
            if (drawable != null) {

                drawFilledPath(c, filled, drawable);
            } else {

                drawFilledPath(c, filled, dataSet.getFillColor(), dataSet.getFillAlpha());
            }
        }

        iterations++;

    } while (currentStartIndex <= currentEndIndex);

}
 
Example 21
Source Project: StockChart-MPAndroidChart   Source File: LineChartRenderer.java    License: MIT License 5 votes vote down vote up
/**
 * Generates a path that is used for filled drawing.
 *
 * @param dataSet    The dataset from which to read the entries.
 * @param startIndex The index from which to start reading the dataset
 * @param endIndex   The index from which to stop reading the dataset
 * @param outputPath The path object that will be assigned the chart data.
 * @return
 */
private void generateFilledPath(final ILineDataSet dataSet, final int startIndex, final int endIndex, final Path outputPath) {

    final float fillMin = dataSet.getFillFormatter().getFillLinePosition(dataSet, mChart);
    final float phaseY = mAnimator.getPhaseY();
    final boolean isDrawSteppedEnabled = dataSet.getMode() == LineDataSet.Mode.STEPPED;

    final Path filled = outputPath;
    filled.reset();

    final Entry entry = dataSet.getEntryForIndex(startIndex);

    filled.moveTo(entry.getX(), fillMin);
    filled.lineTo(entry.getX(), entry.getY() * phaseY);

    // create a new path
    Entry currentEntry = null;
    Entry previousEntry = entry;
    for (int x = startIndex + 1; x <= endIndex; x++) {

        currentEntry = dataSet.getEntryForIndex(x);

        if (isDrawSteppedEnabled) {
            filled.lineTo(currentEntry.getX(), previousEntry.getY() * phaseY);
        }

        filled.lineTo(currentEntry.getX(), currentEntry.getY() * phaseY);

        previousEntry = currentEntry;
    }

    // close up
    if (currentEntry != null) {
        filled.lineTo(currentEntry.getX(), fillMin);
    }

    filled.close();
}
 
Example 22
Source Project: Stayfit   Source File: RealmWikiExample.java    License: Apache License 2.0 5 votes vote down vote up
private void setData() {

        // LINE-CHART
        RealmResults<Score> results = mRealm.allObjects(Score.class);

        RealmLineDataSet<Score> lineDataSet = new RealmLineDataSet<Score>(results, "totalScore", "scoreNr");
        lineDataSet.setDrawCubic(false);
        lineDataSet.setLabel("Realm LineDataSet");
        lineDataSet.setDrawCircleHole(false);
        lineDataSet.setColor(ColorTemplate.rgb("#FF5722"));
        lineDataSet.setCircleColor(ColorTemplate.rgb("#FF5722"));
        lineDataSet.setLineWidth(1.8f);
        lineDataSet.setCircleSize(3.6f);

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

        RealmLineData lineData = new RealmLineData(results, "playerName", dataSets);
        styleData(lineData);

        // set data
        lineChart.setData(lineData);
        lineChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);


        // BAR-CHART
        RealmBarDataSet<Score> barDataSet = new RealmBarDataSet<Score>(results, "totalScore", "scoreNr");
        barDataSet.setColors(new int[]{ColorTemplate.rgb("#FF5722"), ColorTemplate.rgb("#03A9F4")});
        barDataSet.setLabel("Realm BarDataSet");

        ArrayList<IBarDataSet> barDataSets = new ArrayList<IBarDataSet>();
        barDataSets.add(barDataSet);

        RealmBarData barData = new RealmBarData(results, "playerName", barDataSets);
        styleData(barData);

        barChart.setData(barData);
        barChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
    }
 
Example 23
Source Project: StockChart-MPAndroidChart   Source File: OneDayChart.java    License: MIT License 5 votes vote down vote up
/**
 * 动态更新最后一点数据
 * @param timeDatamodel
 * @param length
 */
public void dynamicsUpdateOne(TimeDataModel timeDatamodel, int length) {
    int index = length - 1;
    LineData lineData = lineChart.getData();
    ILineDataSet d1 = lineData.getDataSetByIndex(0);
    Entry e = d1.getEntryForIndex(index);
    d1.removeEntry(e);
    d1.addEntry(new Entry(index, (float) timeDatamodel.getNowPrice()));

    ILineDataSet d2 = lineData.getDataSetByIndex(1);
    Entry e2 = d2.getEntryForIndex(index);
    d2.removeEntry(e2);
    d2.addEntry(new Entry(index, (float) timeDatamodel.getAveragePrice()));

    BarData barData = barChart.getData();
    IBarDataSet barDataSet = barData.getDataSetByIndex(0);
    barDataSet.removeEntry(index);
    float color = timeDatamodel.getNowPrice() == d1.getEntryForIndex(index - 1).getY() ? 0f : timeDatamodel.getNowPrice() > d1.getEntryForIndex(index - 1).getY() ? 1f : -1f;
    barDataSet.addEntry(new BarEntry(index, timeDatamodel.getVolume(),color));

    lineData.notifyDataChanged();
    lineChart.notifyDataSetChanged();
    lineChart.moveViewToX(index);

    barData.notifyDataChanged();
    barChart.notifyDataSetChanged();
    barChart.moveViewToX(index);
}
 
Example 24
Source Project: StockChart-MPAndroidChart   Source File: SimpleFragment.java    License: MIT License 5 votes vote down vote up
protected LineData getComplexity() {

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

        LineDataSet ds1 = new LineDataSet(FileUtils.loadEntriesFromAssets(context.getAssets(), "n.txt"), "O(n)");
        LineDataSet ds2 = new LineDataSet(FileUtils.loadEntriesFromAssets(context.getAssets(), "nlogn.txt"), "O(nlogn)");
        LineDataSet ds3 = new LineDataSet(FileUtils.loadEntriesFromAssets(context.getAssets(), "square.txt"), "O(n\u00B2)");
        LineDataSet ds4 = new LineDataSet(FileUtils.loadEntriesFromAssets(context.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 files in assets folder
        sets.add(ds1);
        sets.add(ds2);
        sets.add(ds3);
        sets.add(ds4);

        LineData d = new LineData(sets);
        d.setValueTypeface(tf);
        return d;
    }
 
Example 25
Source Project: Stayfit   Source File: RealtimeLineChartActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void addEntry() {

        LineData data = mChart.getData();

        if (data != null) {

            ILineDataSet set = data.getDataSetByIndex(0);
            // set.addEntry(...); // can be called as well

            if (set == null) {
                set = createSet();
                data.addDataSet(set);
            }

            // add a new x-value first
            data.addXValue(mMonths[data.getXValCount() % 12] + " "
                    + (year + data.getXValCount() / 12));
            data.addEntry(new Entry((float) (Math.random() * 40) + 30f, set.getEntryCount()), 0);


            // let the chart know it's data has changed
            mChart.notifyDataSetChanged();

            // limit the number of visible entries
            mChart.setVisibleXRangeMaximum(120);
            // mChart.setVisibleYRange(30, AxisDependency.LEFT);

            // move to the latest entry
            mChart.moveViewToX(data.getXValCount() - 121);

            // this automatically refreshes the chart (calls invalidate())
            // mChart.moveViewTo(data.getXValCount()-7, 55f,
            // AxisDependency.LEFT);
        }
    }
 
Example 26
/**
 * generates a random ChartData object with just one DataSet
 *
 * @return Line data
 */
private LineData generateDataLine(int cnt) {

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

    for (int i = 0; i < 12; i++) {
        values1.add(new Entry(i, (int) (Math.random() * 65) + 40));
    }

    LineDataSet d1 = new LineDataSet(values1, "New DataSet " + cnt + ", (1)");
    d1.setLineWidth(2.5f);
    d1.setCircleRadius(4.5f);
    d1.setHighLightColor(Color.rgb(244, 117, 117));
    d1.setDrawValues(false);

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

    for (int i = 0; i < 12; i++) {
        values2.add(new Entry(i, values1.get(i).getY() - 30));
    }

    LineDataSet d2 = new LineDataSet(values2, "New DataSet " + cnt + ", (2)");
    d2.setLineWidth(2.5f);
    d2.setCircleRadius(4.5f);
    d2.setHighLightColor(Color.rgb(244, 117, 117));
    d2.setColor(ColorTemplate.VORDIPLOM_COLORS[0]);
    d2.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[0]);
    d2.setDrawValues(false);

    ArrayList<ILineDataSet> sets = new ArrayList<>();
    sets.add(d1);
    sets.add(d2);

    return new LineData(sets);
}
 
Example 27
Source Project: StockChart-MPAndroidChart   Source File: MultiLineChartActivity.java    License: MIT License 5 votes vote down vote up
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

    chart.resetTracking();

    progress = seekBarX.getProgress();

    tvX.setText(String.valueOf(seekBarX.getProgress()));
    tvY.setText(String.valueOf(seekBarY.getProgress()));

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

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

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

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

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

        int color = colors[z % colors.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(dataSets);
    chart.setData(data);
    chart.invalidate();
}
 
Example 28
Source Project: Ticket-Analysis   Source File: DefaultFillFormatter.java    License: MIT License 5 votes vote down vote up
@Override
public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {

    float fillMin = 0f;
    float chartMaxY = dataProvider.getYChartMax();
    float chartMinY = dataProvider.getYChartMin();

    LineData data = dataProvider.getLineData();

    if (dataSet.getYMax() > 0 && dataSet.getYMin() < 0) {
        fillMin = 0f;
    } else {

        float max, min;

        if (data.getYMax() > 0)
            max = 0f;
        else
            max = chartMaxY;
        if (data.getYMin() < 0)
            min = 0f;
        else
            min = chartMinY;

        fillMin = dataSet.getYMin() >= 0 ? min : max;
    }

    return fillMin;
}
 
Example 29
Source Project: Ticket-Analysis   Source File: LineChartRenderer.java    License: MIT License 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.get().getWidth() != width)
            || (mDrawBitmap.get().getHeight() != height)) {

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

            mDrawBitmap = new WeakReference<Bitmap>(Bitmap.createBitmap(width, height, mBitmapConfig));
            mBitmapCanvas = new Canvas(mDrawBitmap.get());
        } else
            return;
    }

    mDrawBitmap.get().eraseColor(Color.TRANSPARENT);

    LineData lineData = mChart.getLineData();

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

        if (set.isVisible())
            drawDataSet(c, set);
    }

    c.drawBitmap(mDrawBitmap.get(), 0, 0, mRenderPaint);
}
 
Example 30
Source Project: NetKnight   Source File: LineChartRenderer.java    License: Apache License 2.0 5 votes vote down vote up
protected void drawCubicFill(Canvas c, ILineDataSet dataSet, Path spline, Transformer trans,
                             int from, int to) {

    if (to - from <= 1)
        return;

    float fillMin = dataSet.getFillFormatter()
            .getFillLinePosition(dataSet, mChart);
    
    // Take the from/to xIndex from the entries themselves,
    // so missing entries won't screw up the filling.
    // What we need to draw is line from points of the xIndexes - not arbitrary entry indexes!

    final Entry toEntry = dataSet.getEntryForIndex(to - 1);
    final Entry fromEntry = dataSet.getEntryForIndex(from);
    final float xTo = toEntry == null ? 0 : toEntry.getXIndex();
    final float xFrom = fromEntry == null ? 0 : fromEntry.getXIndex();

    spline.lineTo(xTo, fillMin);
    spline.lineTo(xFrom, fillMin);
    spline.close();

    trans.pathValueToPixel(spline);

    final Drawable drawable = dataSet.getFillDrawable();
    if (drawable != null) {

        drawFilledPath(c, spline, drawable);
    } else {

        drawFilledPath(c, spline, dataSet.getFillColor(), dataSet.getFillAlpha());
    }
}