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

The following examples show how to use com.github.mikephil.charting.data.LineData. 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: LineChartExtensions.java    From exchange-rates-mvvm with Apache License 2.0 6 votes vote down vote up
@BindingAdapter({"bind:items"})
public static void populateDiagram(LineChart view, List<SingleValue> items) {

    if (null == items || items.size() == 0) {
        return;
    }
    List<Entry> entries = new ArrayList<>();
    for (int i = 0; i < items.size(); i++) {
        final SingleValue item = items.get(i);
        final Entry entry = new Entry(i, (float) item.getValue(), item);
        entries.add(entry);
    }
    LineDataSet dataSet = new LineDataSet(entries, view.getContext().getString(R.string.currency_value));
    LineData lineData = new LineData(dataSet);

    formatXAxisLabels(view, items);
    view.setData(lineData);
    view.invalidate();
}
 
Example #2
Source File: FragmentPrice.java    From bcm-android 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: ChartStatistics.java    From TwistyTimer with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Resets all chart data and statistics to their initial, empty state.
 */
public void reset() {
    mStatistics.reset();
    mXIndex = 0;
    mBestTime = Long.MAX_VALUE;
    mPrevEntryDay = null;
    mPrevEntryXValue = null;

    // There does not seem to be an easy way to clear existing Y-values *and* X-values from
    // each data set in the chart data. Just create a new one instead.
    mChartData = new LineData();

    // The order in which the data sets are added is important to ensure that "DS_ALL", etc.
    // remain meaningful.
    addMainDataSets(mChartData, mChartStyle.getAllTimesLabel(), mChartStyle.getAllTimesColor(),
            mChartStyle.getBestTimesLabel(), mChartStyle.getBestTimesColor());

    for (int nIndex = 0; nIndex < mNsOfAverages.length; nIndex++) {
        addAoNDataSets(mChartData,
                mChartStyle.getAverageOfNLabelPrefix() + mNsOfAverages[nIndex],
                mChartStyle.getExtraColor(nIndex));
    }
}
 
Example #4
Source File: OneDayChart.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
/**
 * 动态增加一个点数据
 * @param timeDatamodel
 * @param length
 */
public void dynamicsAddOne(TimeDataModel timeDatamodel, int length) {
    int index = length - 1;
    LineData lineData = lineChart.getData();
    ILineDataSet d1 = lineData.getDataSetByIndex(0);
    d1.addEntry(new Entry(index, (float) timeDatamodel.getNowPrice()));
    ILineDataSet d2 = lineData.getDataSetByIndex(1);
    d2.addEntry(new Entry(index, (float) timeDatamodel.getAveragePrice()));

    BarData barData = barChart.getData();
    IBarDataSet barDataSet = barData.getDataSetByIndex(0);
    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();
    barData.notifyDataChanged();
    barChart.notifyDataSetChanged();
    lineChart.setVisibleXRange(maxCount, maxCount);
    barChart.setVisibleXRange(maxCount, maxCount);
    //动态添加或移除数据后, 调用invalidate()刷新图表之前 必须调用 notifyDataSetChanged() .
    lineChart.moveViewToX(index);
    barChart.moveViewToX(index);
}
 
Example #5
Source File: KLineDataManage.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
public void setOneMaValue(LineData lineData, int i) {
    for (int k = 0; k < lineData.getDataSets().size(); k++) {
        ILineDataSet lineDataSet = lineData.getDataSetByIndex(k);
        lineDataSet.removeEntryByXValue(i);
        if (k == 0) {
            if (i >= N1) {
                sum = 0;
                float all5 = getSum(i - (N1 - 1), i) / N1;
                lineDataSet.addEntry(new Entry(i + offSet, all5));
            }
        } else if (k == 1) {
            if (i >= N2) {
                sum = 0;
                float all10 = getSum(i - (N2 - 1), i) / N2;
                lineDataSet.addEntry(new Entry(i + offSet, all10));
            }
        } else if (k == 2) {
            if (i >= N3) {
                sum = 0;
                float all20 = getSum(i - (N3 - 1), i) / N3;
                lineDataSet.addEntry(new Entry(i + offSet, all20));
            }
        }
    }
}
 
Example #6
Source File: FiveDayChart.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
/**
 * 动态增加一个点数据
 * @param timeDatamodel
 * @param length
 */
public void dynamicsAddOne(TimeDataModel timeDatamodel, int length) {
    int index = length - 1;
    LineData lineData = lineChart.getData();
    ILineDataSet d1 = lineData.getDataSetByIndex(0);
    d1.addEntry(new Entry( index, (float) timeDatamodel.getNowPrice()));
    ILineDataSet d2 = lineData.getDataSetByIndex(1);
    d2.addEntry(new Entry( index, (float) timeDatamodel.getAveragePrice()));

    BarData barData = barChart.getData();
    IBarDataSet barDataSet = barData.getDataSetByIndex(0);
    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();
    barData.notifyDataChanged();
    barChart.notifyDataSetChanged();
    lineChart.setVisibleXRange(maxCount, maxCount);
    barChart.setVisibleXRange(maxCount, maxCount);
    //动态添加或移除数据后, 调用invalidate()刷新图表之前 必须调用 notifyDataSetChanged() .
    lineChart.moveViewToX(index);
    barChart.moveViewToX(index);
}
 
Example #7
Source File: KLineChart.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
/**
 * 副图指标成交量
 */
public void setVolumeToChart() {
    if (barChart != null) {
        if (barChart.getBarData() != null) {
            barChart.getBarData().clearValues();
        }
        if (barChart.getLineData() != null) {
            barChart.getLineData().clearValues();
        }
        if (barChart.getCandleData() != null) {
            barChart.getCandleData().clearValues();
        }
        axisLeftBar.resetAxisMaximum();
        axisLeftBar.resetAxisMinimum();
        axisLeftBar.setAxisMinimum(0);
        axisLeftBar.setValueFormatter(new VolFormatter(mContext, kLineData.getAssetId()));

        CombinedData combinedData = barChart.getData();
        combinedData.setData(new BarData(kLineData.getVolumeDataSet()));
        combinedData.setData(new LineData());
        barChart.notifyDataSetChanged();
        barChart.animateY(1000);
    }
}
 
Example #8
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 #9
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 #10
Source File: LineChartActivityColored.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_colored_lines);

    setTitle("LineChartActivityColored");

    charts[0] = findViewById(R.id.chart1);
    charts[1] = findViewById(R.id.chart2);
    charts[2] = findViewById(R.id.chart3);
    charts[3] = findViewById(R.id.chart4);

    Typeface mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Bold.ttf");

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

        LineData data = getData(36, 100);
        data.setValueTypeface(mTf);

        // add some transparency to the color with "& 0x90FFFFFF"
        setupChart(charts[i], data, colors[i % colors.length]);
    }
}
 
Example #11
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 #12
Source File: InvertedLineChartActivity.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
private void setData(int count, float range) {

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

        for (int i = 0; i < count; i++) {
            float xVal = (float) (Math.random() * range);
            float yVal = (float) (Math.random() * range);
            entries.add(new Entry(xVal, yVal));
        }

        // sort by x-value
        Collections.sort(entries, new EntryXComparator());

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

        set1.setLineWidth(1.5f);
        set1.setCircleRadius(4f);

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

        // set data
        chart.setData(data);
    }
 
Example #13
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 #14
Source File: LineChartActivityColored.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_colored_lines);

    mCharts[0] = (LineChart) findViewById(R.id.chart1);
    mCharts[1] = (LineChart) findViewById(R.id.chart2);
    mCharts[2] = (LineChart) findViewById(R.id.chart3);
    mCharts[3] = (LineChart) findViewById(R.id.chart4);

    mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Bold.ttf");

    LineData data = getData(36, 100);
    data.setValueTypeface(mTf);

    for (int i = 0; i < mCharts.length; i++)
        // add some transparency to the color with "& 0x90FFFFFF"
        setupChart(mCharts[i], data, mColors[i % mColors.length]);
}
 
Example #15
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 #16
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 #17
Source File: LineChartRenderer.java    From android-kline 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.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 #18
Source File: PlotterFragment.java    From Bluefruit_LE_Connect_Android_V2 with MIT License 5 votes vote down vote up
private void addEntry(@NonNull String peripheralIdentifier, int index, float value, float timestamp) {
    Entry entry = new Entry(timestamp, value);

    boolean dataSetExists = false;
    List<LineDataSet> dataSets = mDataSetsForPeripheral.get(peripheralIdentifier);
    if (dataSets != null) {
        if (index < dataSets.size()) {
            // Add entry to existing dataset
            LineDataSet dataSet = dataSets.get(index);
            dataSet.addEntry(entry);
            dataSetExists = true;
        }
    }

    if (!dataSetExists) {
        appendDataset(peripheralIdentifier, entry, index);

        List<ILineDataSet> allDataSets = new ArrayList<>();
        for (List<LineDataSet> dataSetLists : mDataSetsForPeripheral.values()) {
            allDataSets.addAll(dataSetLists);
        }
        final LineData lineData = new LineData(allDataSets);
        mChart.setData(lineData);
    }

    List<LineDataSet> dataSets2 = mDataSetsForPeripheral.get(peripheralIdentifier);
    if (dataSets2 != null && index < dataSets2.size()) {
        mLastDataSetModified = dataSets2.get(index);
    }
}
 
Example #19
Source File: RecordingsAdapter.java    From go-bees with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Setup chart (axis, grid, etc.).
 *
 * @param lineChart      chart to setup.
 * @param data           chart with the data.
 * @param firstTimestamp seconds timestamp of the first record (used as initial reference).
 */
private void setupChart(LineChart lineChart, LineData data, long firstTimestamp) {
    // General setup
    lineChart.setDrawGridBackground(false);
    lineChart.setDrawBorders(false);
    lineChart.setViewPortOffsets(50, 0, 50, 50);
    lineChart.getDescription().setEnabled(false);
    lineChart.getLegend().setEnabled(false);
    lineChart.setTouchEnabled(false);
    lineChart.setNoDataText(context.getString(R.string.no_flight_act_data_available));
    // X axis setup
    IAxisValueFormatter xAxisFormatter = new HourAxisValueFormatter(firstTimestamp);
    XAxis xAxis = lineChart.getXAxis();
    xAxis.setValueFormatter(xAxisFormatter);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawAxisLine(false);
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setCenterAxisLabels(false);
    xAxis.setTextColor(ContextCompat.getColor(context, R.color.colorIcons));
    // Y axis setup
    YAxis yAxis = lineChart.getAxisLeft();
    yAxis.setAxisMaximum(40);
    yAxis.setAxisMinimum(0);
    yAxis.setDrawLabels(false);
    yAxis.setDrawAxisLine(false);
    yAxis.setDrawGridLines(true);
    lineChart.getAxisRight().setEnabled(false);
    // Add data
    lineChart.setData(data);
}
 
Example #20
Source File: RecordingsAdapter.java    From go-bees with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void bind(@NonNull final Recording recording) {
    // Title
    String date = formatter.format(recording.getDate());
    recordingDate.setText(StringUtils.capitalize(date));

    // Chart
    if (recording.getRecords() != null && !recording.getRecords().isEmpty()) {
        long firstTimestamp = recording.getRecords().get(0).getTimestamp().getTime() / 1000;
        List<Entry> entries = getChartData(recording.getRecords(), firstTimestamp);
        LineData data = styleChartLines(entries);
        setupChart(chart, data, firstTimestamp);
    }
}
 
Example #21
Source File: LineChartRenderer.java    From android-kline 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.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 #22
Source File: DefaultFillFormatter.java    From Stayfit with Apache License 2.0 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 #23
Source File: MyLineChartRenderer.java    From shinny-futures-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    LineData lineData = mChart.getLineData();

    for (Highlight high : indices) {
        ILineDataSet set = lineData.getDataSetByIndex(high.getDataSetIndex());
        if (set == null || !set.isHighlightEnabled())
            continue;

        Entry e = set.getEntryForXValue(high.getX(), high.getY());
        if (!isInBoundsX(e, set))
            continue;

        MPPointD pix = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(e.getX(),
                e.getY() * mAnimator.getPhaseY());
        float xp = (float) pix.x;

        mHighlightPaint.setColor(set.getHighLightColor());
        mHighlightPaint.setStrokeWidth(set.getHighlightLineWidth());

        float xMax = mViewPortHandler.contentRight();
        //绘制竖线
        c.drawLine(xp, 1, xp, mChart.getHeight(), mHighlightPaint);

        //判断是否画横线
        float y = high.getDrawY();
        if (y >= 0 && y <= mViewPortHandler.contentBottom()) {//在区域内即绘制横线
            //绘制横线
            c.drawLine(0, y, xMax, y, mHighlightPaint);
        }
    }
}
 
Example #24
Source File: KlineFragment.java    From shinny-futures-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 #25
Source File: LineChartRenderer.java    From Stayfit 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.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() && set.getEntryCount() > 0)
            drawDataSet(c, set);
    }

    c.drawBitmap(mDrawBitmap.get(), 0, 0, mRenderPaint);
}
 
Example #26
Source File: LineChartRenderer.java    From Stayfit 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++) {
        ILineDataSet set = lineData.getDataSetByIndex(i);
        mLineBuffers[i] = new LineBuffer(set.getEntryCount() * 4 - 4);
        mCircleBuffers[i] = new CircleBuffer(set.getEntryCount() * 2);
    }
}
 
Example #27
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 #28
Source File: TempChart.java    From octoandroid with GNU General Public License v3.0 5 votes vote down vote up
/**
 * By calling setData initializes the rest of the view
 * @param data the chart data
 */
@Override
public void setData(LineData data) {
    super.setData(data);
    setOnChartValueSelectedListener(this);
    setDescription("");
    setNoDataTextDescription("No chart data");
    setTouchEnabled(true);
    setScaleEnabled(true);
    setDragEnabled(true);
    setDrawGridBackground(true);
    setPinchZoom(true);

    Legend legend = getLegend();
    legend.setForm(Legend.LegendForm.CIRCLE);
    legend.setWordWrapEnabled(true);

    XAxis xAxis = getXAxis();
    xAxis.setAvoidFirstLastClipping(true);
    xAxis.setPosition(XAxis.XAxisPosition.TOP);

    YAxis yAxisLeft = getAxisLeft();
    yAxisLeft.setAxisMinValue(0);

    YAxis yAxisRight = getAxisRight();
    yAxisRight.setEnabled(false);
}
 
Example #29
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 #30
Source File: PerformanceLineChart.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
private void setData(int count, float range) {

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

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

        for (int i = 0; i < count; i++) {
            float mult = (range + 1);
            float val = (float) (Math.random() * mult) + 3;// + (float)
                                                           // ((mult *
                                                           // 0.1) / 10);
            yVals.add(new Entry(val, i));
        }

        // create a dataset and give it a type
        LineDataSet set1 = new LineDataSet(yVals, "DataSet 1");
        
        set1.setColor(Color.BLACK);
        set1.setLineWidth(0.5f);
        set1.setDrawValues(false);
        set1.setDrawCircles(false);
        set1.setDrawCubic(false);
        set1.setDrawFilled(false);

        // create a data object with the datasets
        LineData data = new LineData(xVals, set1);

        // set data
        mChart.setData(data);
        
        // get the legend (only possible after setting data)
        Legend l = mChart.getLegend();
        l.setEnabled(false);
    }