Search in sources :

Example 16 with ILineDataSet

use of com.github.mikephil.charting.interfaces.datasets.ILineDataSet in project MPAndroidChart by PhilJay.

the class LineChartRenderer method drawData.

@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);
}
Also used : Bitmap(android.graphics.Bitmap) LineData(com.github.mikephil.charting.data.LineData) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint)

Example 17 with ILineDataSet

use of com.github.mikephil.charting.interfaces.datasets.ILineDataSet in project run-wallet-android by runplay.

the class ChooseSeedFragment method drawChart.

private void drawChart() {
    long displayBalance = 0L;
    if (Store.getCurrentWallet() != null) {
        seedName.setText(Store.getCurrentSeed().name);
        displayBalance = Store.getCurrentWallet().getBalanceDisplay();
    }
    Currency cur = Store.getDefaultCurrency(getActivity());
    seedValue.setText(IotaToText.convertRawIotaAmountToDisplayText(displayBalance, true));
    Ticker ticker = Store.getTicker("IOTA:" + cur.getCurrencyCode());
    if (ticker != null) {
        seedCurrency.setText(ticker.getIotaValString(displayBalance) + "\n" + cur.getSymbol());
        DecimalFormat udf = df;
        if (ticker.getLast() < 0.01)
            udf = dfs;
        xchangeLast.setText(udf.format(ticker.getLast()));
        xchangeHigh.setText(udf.format(ticker.getHigh()));
        xchangeLow.setText(udf.format(ticker.getLow()));
    }
    // Log.e("THIST","go 3");
    chart.setNoDataText(getString(R.string.messages_no_chart_data));
    chart.setNoDataTextColor(ContextCompat.getColor(getActivity(), R.color.white));
    chart.setGridBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorLight));
    Paint p = chart.getPaint(Chart.PAINT_INFO);
    p.setColor(ContextCompat.getColor(getActivity(), AppTheme.getPrimaryDark()));
    chart.getDescription().setEnabled(false);
    chart.setDragDecelerationFrictionCoef(0.95f);
    // chart.setExtraOffsets(15.f, 15.f, 15.f, 15.f);
    chart.setHighlightPerTapEnabled(false);
    chart.setEnabled(false);
    chart.setTouchEnabled(false);
    chart.animateX(1000);
    chart.setPadding(0, 0, 0, 0);
    chart.getAxisLeft().setEnabled(false);
    chart.getAxisRight().setEnabled(false);
    chart.getXAxis().setEnabled(false);
    // chart.setZ(0.5f);
    chart.zoomOut();
    chart.setPinchZoom(false);
    chart.setPinchZoom(false);
    chart.setFocusable(false);
    Legend leg = chart.getLegend();
    leg.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
    leg.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
    leg.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    leg.setDrawInside(false);
    leg.setEnabled(false);
    List<Entry> entries = new ArrayList<Entry>();
    List<Entry> entriesvol = new ArrayList<Entry>();
    // Log
    history = Store.getTickerHist(getActivity(), Store.getDefaultCurrency(getActivity()).getCurrencyCode(), currentStep);
    double avg = 0D;
    if (history != null) {
        // Log.e("THIST","go 4");
        List<Tick> tickers = history.getTicks();
        Collections.reverse(tickers);
        // double min=tickers.get(0).getLast();
        double max = tickers.get(0).getLast();
        double lastvol = 0;
        double maxvol = 0;
        double minvol = 0D;
        for (int i = 0; i < tickers.size(); i++) {
            double last = tickers.get(i).getLast();
            double tmpvol = tickers.get(i).getVol();
            if (avg == 0D) {
                avg = last;
            } else {
                avg = (avg + last) / 2;
            }
            if (last > max)
                max = last;
            if (tmpvol > maxvol)
                maxvol = tmpvol;
            if (minvol == 0)
                minvol = tmpvol;
            else if (tmpvol < minvol)
                minvol = tmpvol;
            Entry e = new Entry(i * 10, Double.valueOf(last).floatValue());
            entries.add(e);
        }
        max = Math.abs(max);
        double voldivide = (100 / maxvol) / 70;
        for (int i = tickers.size() - 1; i >= 0; i--) {
            double tmpvol = tickers.get(i).getVol() * voldivide;
            // Log.e("YUP", "vol: "+tickers.get(i).getVol()+" = " + tmpvol);
            Entry ev = new Entry(i * 10, Double.valueOf(tmpvol + (0.015 * history.getStep())).floatValue());
            entriesvol.add(ev);
        }
        Collections.reverse(entriesvol);
        // add entries to dataset
        LineDataSet dataSet = new LineDataSet(entries, "IOTA:" + Store.getDefaultCurrency(getActivity()).getCurrencyCode());
        dataSet.setDrawCircleHole(false);
        dataSet.setDrawCircles(false);
        dataSet.setDrawFilled(true);
        dataSet.setFillColor(getResources().getColor(AppTheme.getPrimaryDark()));
        dataSet.setFillAlpha(100);
        dataSet.setColor(B.getColor(getActivity(), AppTheme.getPrimary()));
        // add entries to dataset
        LineDataSet idataSet = new LineDataSet(entriesvol, "Vol");
        idataSet.setDrawCircleHole(false);
        idataSet.setDrawCircles(false);
        idataSet.setDrawFilled(true);
        idataSet.setFillColor(getResources().getColor(R.color.colorMiddle));
        idataSet.setColor(B.getColor(getActivity(), AppTheme.getPrimaryDark()));
        idataSet.setFillAlpha(100);
        ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
        dataSets.add(dataSet);
        dataSets.add(idataSet);
        LineData lineData = new LineData(dataSets);
        chart.setData(lineData);
        float gomin = Double.valueOf(0).floatValue();
        float gomax = +Double.valueOf(max * 1.4).floatValue();
        chart.getAxisLeft().setAxisMinimum(gomin);
        chart.getAxisLeft().setAxisMaximum(gomax);
        chart.getAxisRight().setAxisMinimum(gomin);
        chart.getAxisRight().setAxisMaximum(gomax);
    }
    // refresh
    chart.invalidate();
}
Also used : Legend(com.github.mikephil.charting.components.Legend) LineDataSet(com.github.mikephil.charting.data.LineDataSet) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) Ticker(run.wallet.iota.model.Ticker) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) Paint(android.graphics.Paint) Paint(android.graphics.Paint) Entry(com.github.mikephil.charting.data.Entry) LineData(com.github.mikephil.charting.data.LineData) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) Currency(run.wallet.common.Currency) Tick(run.wallet.iota.model.Tick)

Aggregations

ILineDataSet (com.github.mikephil.charting.interfaces.datasets.ILineDataSet)17 LineData (com.github.mikephil.charting.data.LineData)15 Entry (com.github.mikephil.charting.data.Entry)12 ArrayList (java.util.ArrayList)10 LineDataSet (com.github.mikephil.charting.data.LineDataSet)8 Paint (android.graphics.Paint)4 Bitmap (android.graphics.Bitmap)2 Drawable (android.graphics.drawable.Drawable)2 RealmLineDataSet (com.github.mikephil.charting.data.realm.implementation.RealmLineDataSet)2 IFillFormatter (com.github.mikephil.charting.formatter.IFillFormatter)2 LineDataProvider (com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider)2 Transformer (com.github.mikephil.charting.utils.Transformer)2 Canvas (android.graphics.Canvas)1 DashPathEffect (android.graphics.DashPathEffect)1 AxisBase (com.github.mikephil.charting.components.AxisBase)1 Legend (com.github.mikephil.charting.components.Legend)1 BarData (com.github.mikephil.charting.data.BarData)1 BarEntry (com.github.mikephil.charting.data.BarEntry)1 PieEntry (com.github.mikephil.charting.data.PieEntry)1 RealmBarDataSet (com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet)1