blob: 8a0a75e605eaaf964a5d536ff2812f7c8503d3d1 [file] [log] [blame]
package com.xxmassdeveloper.mpchartexample;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.WindowManager;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.realm.RealmLineDataSet;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.util.ArrayList;
/**
* Created by Philipp Jahoda on 21/10/15.
*/
public class RealmDatabaseActivity extends DemoBase {
private LineChart mChart;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_linechart_noseekbar);
mChart = (LineChart) findViewById(R.id.chart1);
mChart.setDrawGridBackground(false);
// no description text
mChart.setDescription("");
mChart.setNoDataTextDescription("You need to provide data for the chart.");
// enable touch gestures
mChart.setTouchEnabled(true);
// enable scaling and dragging
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);
// if disabled, scaling can be done on x- and y-axis separately
mChart.setPinchZoom(true);
Typeface tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.removeAllLimitLines(); // reset all limit lines to avoid overlapping lines
leftAxis.setAxisMaxValue(220f);
leftAxis.setAxisMinValue(-50f);
leftAxis.setStartAtZero(false);
leftAxis.enableGridDashedLine(10f, 10f, 0f);
mChart.getAxisRight().setEnabled(false);
// add data
setData(45, 100);
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
}
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
RealmLineDataSet set1 = new RealmLineDataSet();
// 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.setCircleSize(3f);
// set1.setDrawCircleHole(false);
// set1.setValueTextSize(9f);
// set1.setFillAlpha(65);
// set1.setFillColor(Color.BLACK);
// set1.setDrawFilled(true);
// set1.setShader(new LinearGradient(0, 0, 0, mChart.getHeight(),
// Color.BLACK, Color.WHITE, Shader.TileMode.MIRROR));
ArrayList<RealmLineDataSet> dataSets = new ArrayList<RealmLineDataSet>();
dataSets.add(set1); // add the datasets
// create a data object with the datasets
LineData data = new LineData(null, dataSets);
// set data
mChart.setData(data);
}
}