Search in sources :

Example 26 with Legend

use of com.github.mikephil.charting.components.Legend in project MPAndroidChart by PhilJay.

the class ScatterChartActivity 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_scatterchart);
    tvX = (TextView) findViewById(R.id.tvXMax);
    tvY = (TextView) findViewById(R.id.tvYMax);
    mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
    mSeekBarX.setOnSeekBarChangeListener(this);
    mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
    mSeekBarY.setOnSeekBarChangeListener(this);
    mChart = (ScatterChart) findViewById(R.id.chart1);
    mChart.getDescription().setEnabled(false);
    mChart.setOnChartValueSelectedListener(this);
    mChart.setDrawGridBackground(false);
    mChart.setTouchEnabled(true);
    mChart.setMaxHighlightDistance(50f);
    // enable scaling and dragging
    mChart.setDragEnabled(true);
    mChart.setScaleEnabled(true);
    mChart.setMaxVisibleValueCount(200);
    mChart.setPinchZoom(true);
    mSeekBarX.setProgress(45);
    mSeekBarY.setProgress(100);
    Legend l = mChart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
    l.setOrientation(Legend.LegendOrientation.VERTICAL);
    l.setDrawInside(false);
    l.setTypeface(mTfLight);
    l.setXOffset(5f);
    YAxis yl = mChart.getAxisLeft();
    yl.setTypeface(mTfLight);
    // this replaces setStartAtZero(true)
    yl.setAxisMinimum(0f);
    mChart.getAxisRight().setEnabled(false);
    XAxis xl = mChart.getXAxis();
    xl.setTypeface(mTfLight);
    xl.setDrawGridLines(false);
}
Also used : Legend(com.github.mikephil.charting.components.Legend) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Example 27 with Legend

use of com.github.mikephil.charting.components.Legend in project MPAndroidChart by PhilJay.

the class StackedBarActivity 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_barchart);
    tvX = (TextView) findViewById(R.id.tvXMax);
    tvY = (TextView) findViewById(R.id.tvYMax);
    mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
    mSeekBarX.setOnSeekBarChangeListener(this);
    mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
    mSeekBarY.setOnSeekBarChangeListener(this);
    mChart = (BarChart) findViewById(R.id.chart1);
    mChart.setOnChartValueSelectedListener(this);
    mChart.getDescription().setEnabled(false);
    // if more than 60 entries are displayed in the chart, no values will be
    // drawn
    mChart.setMaxVisibleValueCount(40);
    // scaling can now only be done on x- and y-axis separately
    mChart.setPinchZoom(false);
    mChart.setDrawGridBackground(false);
    mChart.setDrawBarShadow(false);
    mChart.setDrawValueAboveBar(false);
    mChart.setHighlightFullBarEnabled(false);
    // change the position of the y-labels
    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setValueFormatter(new MyAxisValueFormatter());
    // this replaces setStartAtZero(true)
    leftAxis.setAxisMinimum(0f);
    mChart.getAxisRight().setEnabled(false);
    XAxis xLabels = mChart.getXAxis();
    xLabels.setPosition(XAxisPosition.TOP);
    // mChart.setDrawXLabels(false);
    // mChart.setDrawYLabels(false);
    // setting data
    mSeekBarX.setProgress(12);
    mSeekBarY.setProgress(100);
    Legend l = mChart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
    l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    l.setDrawInside(false);
    l.setFormSize(8f);
    l.setFormToTextSpace(4f);
    l.setXEntrySpace(6f);
// mChart.setDrawLegend(false);
}
Also used : Legend(com.github.mikephil.charting.components.Legend) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis) MyAxisValueFormatter(com.xxmassdeveloper.mpchartexample.custom.MyAxisValueFormatter)

Example 28 with Legend

use of com.github.mikephil.charting.components.Legend in project MPAndroidChart by PhilJay.

the class BarChartFrag method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.frag_simple_bar, container, false);
    // create a new chart object
    mChart = new BarChart(getActivity());
    mChart.getDescription().setEnabled(false);
    mChart.setOnChartGestureListener(this);
    MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.custom_marker_view);
    // For bounds control
    mv.setChartView(mChart);
    mChart.setMarker(mv);
    mChart.setDrawGridBackground(false);
    mChart.setDrawBarShadow(false);
    Typeface tf = Typeface.createFromAsset(getActivity().getAssets(), "OpenSans-Light.ttf");
    mChart.setData(generateBarData(1, 20000, 12));
    Legend l = mChart.getLegend();
    l.setTypeface(tf);
    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setTypeface(tf);
    // this replaces setStartAtZero(true)
    leftAxis.setAxisMinimum(0f);
    mChart.getAxisRight().setEnabled(false);
    XAxis xAxis = mChart.getXAxis();
    xAxis.setEnabled(false);
    // programatically add the chart
    FrameLayout parent = (FrameLayout) v.findViewById(R.id.parentLayout);
    parent.addView(mChart);
    return v;
}
Also used : Legend(com.github.mikephil.charting.components.Legend) Typeface(android.graphics.Typeface) FrameLayout(android.widget.FrameLayout) BarChart(com.github.mikephil.charting.charts.BarChart) View(android.view.View) MyMarkerView(com.xxmassdeveloper.mpchartexample.custom.MyMarkerView) MyMarkerView(com.xxmassdeveloper.mpchartexample.custom.MyMarkerView) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Example 29 with Legend

use of com.github.mikephil.charting.components.Legend in project MPAndroidChart by PhilJay.

the class ComplexityFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.frag_simple_line, container, false);
    mChart = (LineChart) v.findViewById(R.id.lineChart1);
    mChart.getDescription().setEnabled(false);
    mChart.setDrawGridBackground(false);
    mChart.setData(getComplexity());
    mChart.animateX(3000);
    Typeface tf = Typeface.createFromAsset(getActivity().getAssets(), "OpenSans-Light.ttf");
    Legend l = mChart.getLegend();
    l.setTypeface(tf);
    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setTypeface(tf);
    mChart.getAxisRight().setEnabled(false);
    XAxis xAxis = mChart.getXAxis();
    xAxis.setEnabled(false);
    return v;
}
Also used : Legend(com.github.mikephil.charting.components.Legend) Typeface(android.graphics.Typeface) View(android.view.View) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Example 30 with Legend

use of com.github.mikephil.charting.components.Legend in project MPAndroidChart by PhilJay.

the class LineChartActivityColored method setupChart.

private void setupChart(LineChart chart, LineData data, int color) {
    ((LineDataSet) data.getDataSetByIndex(0)).setCircleColorHole(color);
    // no description text
    chart.getDescription().setEnabled(false);
    // mChart.setDrawHorizontalGrid(false);
    //
    // enable / disable grid background
    chart.setDrawGridBackground(false);
    //        chart.getRenderer().getGridPaint().setGridColor(Color.WHITE & 0x70FFFFFF);
    // enable touch gestures
    chart.setTouchEnabled(true);
    // enable scaling and dragging
    chart.setDragEnabled(true);
    chart.setScaleEnabled(true);
    // if disabled, scaling can be done on x- and y-axis separately
    chart.setPinchZoom(false);
    chart.setBackgroundColor(color);
    // set custom chart offsets (automatic offset calculation is hereby disabled)
    chart.setViewPortOffsets(10, 0, 10, 0);
    // add data
    chart.setData(data);
    // get the legend (only possible after setting data)
    Legend l = chart.getLegend();
    l.setEnabled(false);
    chart.getAxisLeft().setEnabled(false);
    chart.getAxisLeft().setSpaceTop(40);
    chart.getAxisLeft().setSpaceBottom(40);
    chart.getAxisRight().setEnabled(false);
    chart.getXAxis().setEnabled(false);
    // animate calls invalidate()...
    chart.animateX(2500);
}
Also used : Legend(com.github.mikephil.charting.components.Legend) LineDataSet(com.github.mikephil.charting.data.LineDataSet)

Aggregations

Legend (com.github.mikephil.charting.components.Legend)31 XAxis (com.github.mikephil.charting.components.XAxis)21 YAxis (com.github.mikephil.charting.components.YAxis)19 Typeface (android.graphics.Typeface)7 IAxisValueFormatter (com.github.mikephil.charting.formatter.IAxisValueFormatter)6 View (android.view.View)5 AxisBase (com.github.mikephil.charting.components.AxisBase)5 MyMarkerView (com.xxmassdeveloper.mpchartexample.custom.MyMarkerView)5 ArrayList (java.util.ArrayList)3 Paint (android.graphics.Paint)2 LineData (com.github.mikephil.charting.data.LineData)2 LineDataSet (com.github.mikephil.charting.data.LineDataSet)2 MyAxisValueFormatter (com.xxmassdeveloper.mpchartexample.custom.MyAxisValueFormatter)2 ValueAnimator (android.animation.ValueAnimator)1 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)1 DashPathEffect (android.graphics.DashPathEffect)1 FrameLayout (android.widget.FrameLayout)1 TextView (android.widget.TextView)1 ChartAnimator (com.github.mikephil.charting.animation.ChartAnimator)1 BarChart (com.github.mikephil.charting.charts.BarChart)1