Search in sources :

Example 26 with LineData

use of com.github.mikephil.charting.data.LineData in project MPAndroidChart by PhilJay.

the class RealtimeLineChartActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_realtime_linechart);
    mChart = (LineChart) findViewById(R.id.chart1);
    mChart.setOnChartValueSelectedListener(this);
    // enable description text
    mChart.getDescription().setEnabled(true);
    // enable touch gestures
    mChart.setTouchEnabled(true);
    // enable scaling and dragging
    mChart.setDragEnabled(true);
    mChart.setScaleEnabled(true);
    mChart.setDrawGridBackground(false);
    // if disabled, scaling can be done on x- and y-axis separately
    mChart.setPinchZoom(true);
    // set an alternative background color
    mChart.setBackgroundColor(Color.LTGRAY);
    LineData data = new LineData();
    data.setValueTextColor(Color.WHITE);
    // add empty data
    mChart.setData(data);
    // get the legend (only possible after setting data)
    Legend l = mChart.getLegend();
    // modify the legend ...
    l.setForm(LegendForm.LINE);
    l.setTypeface(mTfLight);
    l.setTextColor(Color.WHITE);
    XAxis xl = mChart.getXAxis();
    xl.setTypeface(mTfLight);
    xl.setTextColor(Color.WHITE);
    xl.setDrawGridLines(false);
    xl.setAvoidFirstLastClipping(true);
    xl.setEnabled(true);
    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setTypeface(mTfLight);
    leftAxis.setTextColor(Color.WHITE);
    leftAxis.setAxisMaximum(100f);
    leftAxis.setAxisMinimum(0f);
    leftAxis.setDrawGridLines(true);
    YAxis rightAxis = mChart.getAxisRight();
    rightAxis.setEnabled(false);
}
Also used : LineData(com.github.mikephil.charting.data.LineData) Legend(com.github.mikephil.charting.components.Legend) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Example 27 with LineData

use of com.github.mikephil.charting.data.LineData in project MPAndroidChart by PhilJay.

the class RealmDatabaseActivityLine method setData.

private void setData() {
    RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
    RealmLineDataSet<RealmDemoData> set = new RealmLineDataSet<RealmDemoData>(result, "xValue", "yValue");
    set.setMode(LineDataSet.Mode.CUBIC_BEZIER);
    set.setLabel("Realm LineDataSet");
    set.setDrawCircleHole(false);
    set.setColor(ColorTemplate.rgb("#FF5722"));
    set.setCircleColor(ColorTemplate.rgb("#FF5722"));
    set.setLineWidth(1.8f);
    set.setCircleRadius(3.6f);
    ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
    // add the dataset
    dataSets.add(set);
    // create a data object with the dataset list
    LineData data = new LineData(dataSets);
    styleData(data);
    // set data
    mChart.setData(data);
    mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
}
Also used : LineData(com.github.mikephil.charting.data.LineData) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) ArrayList(java.util.ArrayList) RealmDemoData(com.xxmassdeveloper.mpchartexample.custom.RealmDemoData) RealmLineDataSet(com.github.mikephil.charting.data.realm.implementation.RealmLineDataSet)

Example 28 with LineData

use of com.github.mikephil.charting.data.LineData in project MPAndroidChart by PhilJay.

the class SimpleFragment method generateLineData.

protected LineData generateLineData() {
    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);
    LineData d = new LineData(sets);
    d.setValueTypeface(tf);
    return d;
}
Also used : LineData(com.github.mikephil.charting.data.LineData) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) LineDataSet(com.github.mikephil.charting.data.LineDataSet) ArrayList(java.util.ArrayList)

Example 29 with LineData

use of com.github.mikephil.charting.data.LineData in project MPAndroidChart by PhilJay.

the class LineChartActivity1 method setData.

private void setData(int count, float range) {
    ArrayList<Entry> values = new ArrayList<Entry>();
    for (int i = 0; i < count; i++) {
        float val = (float) (Math.random() * range) + 3;
        values.add(new Entry(i, val, getResources().getDrawable(R.drawable.star)));
    }
    LineDataSet set1;
    if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) {
        set1 = (LineDataSet) mChart.getData().getDataSetByIndex(0);
        set1.setValues(values);
        mChart.getData().notifyDataChanged();
        mChart.notifyDataSetChanged();
    } else {
        // create a dataset and give it a type
        set1 = new LineDataSet(values, "DataSet 1");
        set1.setDrawIcons(false);
        // set the line to be drawn like this "- - - - - -"
        set1.enableDashedLine(10f, 5f, 0f);
        set1.enableDashedHighlightLine(10f, 5f, 0f);
        set1.setColor(Color.BLACK);
        set1.setCircleColor(Color.BLACK);
        set1.setLineWidth(1f);
        set1.setCircleRadius(3f);
        set1.setDrawCircleHole(false);
        set1.setValueTextSize(9f);
        set1.setDrawFilled(true);
        set1.setFormLineWidth(1f);
        set1.setFormLineDashEffect(new DashPathEffect(new float[] { 10f, 5f }, 0f));
        set1.setFormSize(15.f);
        if (Utils.getSDKInt() >= 18) {
            // fill drawable only supported on api level 18 and above
            Drawable drawable = ContextCompat.getDrawable(this, R.drawable.fade_red);
            set1.setFillDrawable(drawable);
        } else {
            set1.setFillColor(Color.BLACK);
        }
        ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
        // add the datasets
        dataSets.add(set1);
        // create a data object with the datasets
        LineData data = new LineData(dataSets);
        // set data
        mChart.setData(data);
    }
}
Also used : Entry(com.github.mikephil.charting.data.Entry) LineData(com.github.mikephil.charting.data.LineData) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) LineDataSet(com.github.mikephil.charting.data.LineDataSet) ArrayList(java.util.ArrayList) Drawable(android.graphics.drawable.Drawable) DashPathEffect(android.graphics.DashPathEffect)

Example 30 with LineData

use of com.github.mikephil.charting.data.LineData in project MPAndroidChart by PhilJay.

the class LineChartActivity2 method setData.

private void setData(int count, float range) {
    ArrayList<Entry> yVals1 = new ArrayList<Entry>();
    for (int i = 0; i < count; i++) {
        float mult = range / 2f;
        float val = (float) (Math.random() * mult) + 50;
        yVals1.add(new Entry(i, val));
    }
    ArrayList<Entry> yVals2 = new ArrayList<Entry>();
    for (int i = 0; i < count - 1; i++) {
        float mult = range;
        float val = (float) (Math.random() * mult) + 450;
        yVals2.add(new Entry(i, val));
    //            if(i == 10) {
    //                yVals2.add(new Entry(i, val + 50));
    //            }
    }
    ArrayList<Entry> yVals3 = new ArrayList<Entry>();
    for (int i = 0; i < count; i++) {
        float mult = range;
        float val = (float) (Math.random() * mult) + 500;
        yVals3.add(new Entry(i, val));
    }
    LineDataSet set1, set2, set3;
    if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) {
        set1 = (LineDataSet) mChart.getData().getDataSetByIndex(0);
        set2 = (LineDataSet) mChart.getData().getDataSetByIndex(1);
        set3 = (LineDataSet) mChart.getData().getDataSetByIndex(2);
        set1.setValues(yVals1);
        set2.setValues(yVals2);
        set3.setValues(yVals3);
        mChart.getData().notifyDataChanged();
        mChart.notifyDataSetChanged();
    } else {
        // create a dataset and give it a type
        set1 = new LineDataSet(yVals1, "DataSet 1");
        set1.setAxisDependency(AxisDependency.LEFT);
        set1.setColor(ColorTemplate.getHoloBlue());
        set1.setCircleColor(Color.WHITE);
        set1.setLineWidth(2f);
        set1.setCircleRadius(3f);
        set1.setFillAlpha(65);
        set1.setFillColor(ColorTemplate.getHoloBlue());
        set1.setHighLightColor(Color.rgb(244, 117, 117));
        set1.setDrawCircleHole(false);
        //set1.setFillFormatter(new MyFillFormatter(0f));
        //set1.setDrawHorizontalHighlightIndicator(false);
        //set1.setVisible(false);
        //set1.setCircleHoleColor(Color.WHITE);
        // create a dataset and give it a type
        set2 = new LineDataSet(yVals2, "DataSet 2");
        set2.setAxisDependency(AxisDependency.RIGHT);
        set2.setColor(Color.RED);
        set2.setCircleColor(Color.WHITE);
        set2.setLineWidth(2f);
        set2.setCircleRadius(3f);
        set2.setFillAlpha(65);
        set2.setFillColor(Color.RED);
        set2.setDrawCircleHole(false);
        set2.setHighLightColor(Color.rgb(244, 117, 117));
        //set2.setFillFormatter(new MyFillFormatter(900f));
        set3 = new LineDataSet(yVals3, "DataSet 3");
        set3.setAxisDependency(AxisDependency.RIGHT);
        set3.setColor(Color.YELLOW);
        set3.setCircleColor(Color.WHITE);
        set3.setLineWidth(2f);
        set3.setCircleRadius(3f);
        set3.setFillAlpha(65);
        set3.setFillColor(ColorTemplate.colorWithAlpha(Color.YELLOW, 200));
        set3.setDrawCircleHole(false);
        set3.setHighLightColor(Color.rgb(244, 117, 117));
        // create a data object with the datasets
        LineData data = new LineData(set1, set2, set3);
        data.setValueTextColor(Color.WHITE);
        data.setValueTextSize(9f);
        // set data
        mChart.setData(data);
    }
}
Also used : Entry(com.github.mikephil.charting.data.Entry) LineData(com.github.mikephil.charting.data.LineData) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) LineDataSet(com.github.mikephil.charting.data.LineDataSet) ArrayList(java.util.ArrayList)

Aggregations

LineData (com.github.mikephil.charting.data.LineData)37 LineDataSet (com.github.mikephil.charting.data.LineDataSet)22 Entry (com.github.mikephil.charting.data.Entry)19 ILineDataSet (com.github.mikephil.charting.interfaces.datasets.ILineDataSet)19 ArrayList (java.util.ArrayList)19 XAxis (com.github.mikephil.charting.components.XAxis)6 YAxis (com.github.mikephil.charting.components.YAxis)6 XFormatter (com.a5corp.weather.utils.XFormatter)5 BarEntry (com.github.mikephil.charting.data.BarEntry)3 Legend (com.github.mikephil.charting.components.Legend)2 BarData (com.github.mikephil.charting.data.BarData)2 RealmLineDataSet (com.github.mikephil.charting.data.realm.implementation.RealmLineDataSet)2 IAxisValueFormatter (com.github.mikephil.charting.formatter.IAxisValueFormatter)2 IFillFormatter (com.github.mikephil.charting.formatter.IFillFormatter)2 LineDataProvider (com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider)2 IBarDataSet (com.github.mikephil.charting.interfaces.datasets.IBarDataSet)2 Bitmap (android.graphics.Bitmap)1 Canvas (android.graphics.Canvas)1 DashPathEffect (android.graphics.DashPathEffect)1 Paint (android.graphics.Paint)1