Search in sources :

Example 11 with XAxis

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

the class RadarChartActivitry 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_radarchart_noseekbar);
    TextView tv = (TextView) findViewById(R.id.textView);
    tv.setTypeface(mTfLight);
    tv.setTextColor(Color.WHITE);
    tv.setBackgroundColor(Color.rgb(60, 65, 82));
    mChart = (RadarChart) findViewById(R.id.chart1);
    mChart.setBackgroundColor(Color.rgb(60, 65, 82));
    mChart.getDescription().setEnabled(false);
    mChart.setWebLineWidth(1f);
    mChart.setWebColor(Color.LTGRAY);
    mChart.setWebLineWidthInner(1f);
    mChart.setWebColorInner(Color.LTGRAY);
    mChart.setWebAlpha(100);
    // create a custom MarkerView (extend MarkerView) and specify the layout
    // to use for it
    MarkerView mv = new RadarMarkerView(this, R.layout.radar_markerview);
    // For bounds control
    mv.setChartView(mChart);
    // Set the marker to the chart
    mChart.setMarker(mv);
    setData();
    mChart.animateXY(1400, 1400, Easing.EasingOption.EaseInOutQuad, Easing.EasingOption.EaseInOutQuad);
    XAxis xAxis = mChart.getXAxis();
    xAxis.setTypeface(mTfLight);
    xAxis.setTextSize(9f);
    xAxis.setYOffset(0f);
    xAxis.setXOffset(0f);
    xAxis.setValueFormatter(new IAxisValueFormatter() {

        private String[] mActivities = new String[] { "Burger", "Steak", "Salad", "Pasta", "Pizza" };

        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            return mActivities[(int) value % mActivities.length];
        }
    });
    xAxis.setTextColor(Color.WHITE);
    YAxis yAxis = mChart.getYAxis();
    yAxis.setTypeface(mTfLight);
    yAxis.setLabelCount(5, false);
    yAxis.setTextSize(9f);
    yAxis.setAxisMinimum(0f);
    yAxis.setAxisMaximum(80f);
    yAxis.setDrawLabels(false);
    Legend l = mChart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
    l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    l.setDrawInside(false);
    l.setTypeface(mTfLight);
    l.setXEntrySpace(7f);
    l.setYEntrySpace(5f);
    l.setTextColor(Color.WHITE);
}
Also used : RadarMarkerView(com.xxmassdeveloper.mpchartexample.custom.RadarMarkerView) MarkerView(com.github.mikephil.charting.components.MarkerView) RadarMarkerView(com.xxmassdeveloper.mpchartexample.custom.RadarMarkerView) Legend(com.github.mikephil.charting.components.Legend) IAxisValueFormatter(com.github.mikephil.charting.formatter.IAxisValueFormatter) TextView(android.widget.TextView) AxisBase(com.github.mikephil.charting.components.AxisBase) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Example 12 with XAxis

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

the class StackedBarActivityNegative 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_age_distribution);
    setTitle("Age Distribution Austria");
    mChart = (HorizontalBarChart) findViewById(R.id.chart1);
    mChart.setOnChartValueSelectedListener(this);
    mChart.setDrawGridBackground(false);
    mChart.getDescription().setEnabled(false);
    // scaling can now only be done on x- and y-axis separately
    mChart.setPinchZoom(false);
    mChart.setDrawBarShadow(false);
    mChart.setDrawValueAboveBar(true);
    mChart.setHighlightFullBarEnabled(false);
    mChart.getAxisLeft().setEnabled(false);
    mChart.getAxisRight().setAxisMaximum(25f);
    mChart.getAxisRight().setAxisMinimum(-25f);
    mChart.getAxisRight().setDrawGridLines(false);
    mChart.getAxisRight().setDrawZeroLine(true);
    mChart.getAxisRight().setLabelCount(7, false);
    mChart.getAxisRight().setValueFormatter(new CustomFormatter());
    mChart.getAxisRight().setTextSize(9f);
    XAxis xAxis = mChart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTH_SIDED);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawAxisLine(false);
    xAxis.setTextSize(9f);
    xAxis.setAxisMinimum(0f);
    xAxis.setAxisMaximum(110f);
    xAxis.setCenterAxisLabels(true);
    xAxis.setLabelCount(12);
    xAxis.setGranularity(10f);
    xAxis.setValueFormatter(new IAxisValueFormatter() {

        private DecimalFormat format = new DecimalFormat("###");

        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            return format.format(value) + "-" + format.format(value + 10);
        }
    });
    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);
    // IMPORTANT: When using negative values in stacked bars, always make sure the negative values are in the array first
    ArrayList<BarEntry> yValues = new ArrayList<BarEntry>();
    yValues.add(new BarEntry(5, new float[] { -10, 10 }));
    yValues.add(new BarEntry(15, new float[] { -12, 13 }));
    yValues.add(new BarEntry(25, new float[] { -15, 15 }));
    yValues.add(new BarEntry(35, new float[] { -17, 17 }));
    yValues.add(new BarEntry(45, new float[] { -19, 20 }));
    yValues.add(new BarEntry(45, new float[] { -19, 20 }, getResources().getDrawable(R.drawable.star)));
    yValues.add(new BarEntry(55, new float[] { -19, 19 }));
    yValues.add(new BarEntry(65, new float[] { -16, 16 }));
    yValues.add(new BarEntry(75, new float[] { -13, 14 }));
    yValues.add(new BarEntry(85, new float[] { -10, 11 }));
    yValues.add(new BarEntry(95, new float[] { -5, 6 }));
    yValues.add(new BarEntry(105, new float[] { -1, 2 }));
    BarDataSet set = new BarDataSet(yValues, "Age Distribution");
    set.setDrawIcons(false);
    set.setValueFormatter(new CustomFormatter());
    set.setValueTextSize(7f);
    set.setAxisDependency(YAxis.AxisDependency.RIGHT);
    set.setColors(new int[] { Color.rgb(67, 67, 72), Color.rgb(124, 181, 236) });
    set.setStackLabels(new String[] { "Men", "Women" });
    String[] xLabels = new String[] { "0-10", "10-20", "20-30", "30-40", "40-50", "50-60", "60-70", "70-80", "80-90", "90-100", "100+" };
    BarData data = new BarData(set);
    data.setBarWidth(8.5f);
    mChart.setData(data);
    mChart.invalidate();
}
Also used : Legend(com.github.mikephil.charting.components.Legend) BarDataSet(com.github.mikephil.charting.data.BarDataSet) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) IAxisValueFormatter(com.github.mikephil.charting.formatter.IAxisValueFormatter) AxisBase(com.github.mikephil.charting.components.AxisBase) BarEntry(com.github.mikephil.charting.data.BarEntry) XAxis(com.github.mikephil.charting.components.XAxis) BarData(com.github.mikephil.charting.data.BarData)

Example 13 with XAxis

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

the class FilledLineActivity 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_linechart_noseekbar);
    mChart = (LineChart) findViewById(R.id.chart1);
    mChart.setBackgroundColor(Color.WHITE);
    mChart.setGridBackgroundColor(mFillColor);
    mChart.setDrawGridBackground(true);
    mChart.setDrawBorders(true);
    // no description text
    mChart.getDescription().setEnabled(false);
    // if disabled, scaling can be done on x- and y-axis separately
    mChart.setPinchZoom(false);
    Legend l = mChart.getLegend();
    l.setEnabled(false);
    XAxis xAxis = mChart.getXAxis();
    xAxis.setEnabled(false);
    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setAxisMaximum(900f);
    leftAxis.setAxisMinimum(-250f);
    leftAxis.setDrawAxisLine(false);
    leftAxis.setDrawZeroLine(false);
    leftAxis.setDrawGridLines(false);
    mChart.getAxisRight().setEnabled(false);
    // add data
    setData(100, 60);
    mChart.invalidate();
}
Also used : Legend(com.github.mikephil.charting.components.Legend) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Example 14 with XAxis

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

the class InvertedLineChartActivity 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_linechart);
    tvX = (TextView) findViewById(R.id.tvXMax);
    tvY = (TextView) findViewById(R.id.tvYMax);
    mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
    mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
    mSeekBarX.setProgress(45);
    mSeekBarY.setProgress(100);
    mSeekBarY.setOnSeekBarChangeListener(this);
    mSeekBarX.setOnSeekBarChangeListener(this);
    mChart = (LineChart) findViewById(R.id.chart1);
    mChart.setOnChartValueSelectedListener(this);
    mChart.setDrawGridBackground(false);
    // no description text
    mChart.getDescription().setEnabled(false);
    // 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);
    // set an alternative background color
    // mChart.setBackgroundColor(Color.GRAY);
    // create a custom MarkerView (extend MarkerView) and specify the layout
    // to use for it
    MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
    // For bounds control
    mv.setChartView(mChart);
    // Set the marker to the chart
    mChart.setMarker(mv);
    XAxis xl = mChart.getXAxis();
    xl.setAvoidFirstLastClipping(true);
    xl.setAxisMinimum(0f);
    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setInverted(true);
    // this replaces setStartAtZero(true)
    leftAxis.setAxisMinimum(0f);
    YAxis rightAxis = mChart.getAxisRight();
    rightAxis.setEnabled(false);
    // add data
    setData(25, 50);
    // // restrain the maximum scale-out factor
    // mChart.setScaleMinima(3f, 3f);
    //
    // // center the view to a specific position inside the chart
    // mChart.centerViewPort(10, 50);
    // get the legend (only possible after setting data)
    Legend l = mChart.getLegend();
    // modify the legend ...
    l.setForm(LegendForm.LINE);
    // dont forget to refresh the drawing
    mChart.invalidate();
}
Also used : Legend(com.github.mikephil.charting.components.Legend) MyMarkerView(com.xxmassdeveloper.mpchartexample.custom.MyMarkerView) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Example 15 with XAxis

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

the class LineChartActivity1 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_linechart);
    tvX = (TextView) findViewById(R.id.tvXMax);
    tvY = (TextView) findViewById(R.id.tvYMax);
    mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
    mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
    mSeekBarX.setProgress(45);
    mSeekBarY.setProgress(100);
    mSeekBarY.setOnSeekBarChangeListener(this);
    mSeekBarX.setOnSeekBarChangeListener(this);
    mChart = (LineChart) findViewById(R.id.chart1);
    mChart.setOnChartGestureListener(this);
    mChart.setOnChartValueSelectedListener(this);
    mChart.setDrawGridBackground(false);
    // no description text
    mChart.getDescription().setEnabled(false);
    // enable touch gestures
    mChart.setTouchEnabled(true);
    // enable scaling and dragging
    mChart.setDragEnabled(true);
    mChart.setScaleEnabled(true);
    // mChart.setScaleXEnabled(true);
    // mChart.setScaleYEnabled(true);
    // if disabled, scaling can be done on x- and y-axis separately
    mChart.setPinchZoom(true);
    // set an alternative background color
    // mChart.setBackgroundColor(Color.GRAY);
    // create a custom MarkerView (extend MarkerView) and specify the layout
    // to use for it
    MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
    // For bounds control
    mv.setChartView(mChart);
    // Set the marker to the chart
    mChart.setMarker(mv);
    // x-axis limit line
    LimitLine llXAxis = new LimitLine(10f, "Index 10");
    llXAxis.setLineWidth(4f);
    llXAxis.enableDashedLine(10f, 10f, 0f);
    llXAxis.setLabelPosition(LimitLabelPosition.RIGHT_BOTTOM);
    llXAxis.setTextSize(10f);
    XAxis xAxis = mChart.getXAxis();
    xAxis.enableGridDashedLine(10f, 10f, 0f);
    //xAxis.setValueFormatter(new MyCustomXAxisValueFormatter());
    //xAxis.addLimitLine(llXAxis); // add x-axis limit line
    Typeface tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
    LimitLine ll1 = new LimitLine(150f, "Upper Limit");
    ll1.setLineWidth(4f);
    ll1.enableDashedLine(10f, 10f, 0f);
    ll1.setLabelPosition(LimitLabelPosition.RIGHT_TOP);
    ll1.setTextSize(10f);
    ll1.setTypeface(tf);
    LimitLine ll2 = new LimitLine(-30f, "Lower Limit");
    ll2.setLineWidth(4f);
    ll2.enableDashedLine(10f, 10f, 0f);
    ll2.setLabelPosition(LimitLabelPosition.RIGHT_BOTTOM);
    ll2.setTextSize(10f);
    ll2.setTypeface(tf);
    YAxis leftAxis = mChart.getAxisLeft();
    // reset all limit lines to avoid overlapping lines
    leftAxis.removeAllLimitLines();
    leftAxis.addLimitLine(ll1);
    leftAxis.addLimitLine(ll2);
    leftAxis.setAxisMaximum(200f);
    leftAxis.setAxisMinimum(-50f);
    //leftAxis.setYOffset(20f);
    leftAxis.enableGridDashedLine(10f, 10f, 0f);
    leftAxis.setDrawZeroLine(false);
    // limit lines are drawn behind data (and not on top)
    leftAxis.setDrawLimitLinesBehindData(true);
    mChart.getAxisRight().setEnabled(false);
    //mChart.getViewPortHandler().setMaximumScaleY(2f);
    //mChart.getViewPortHandler().setMaximumScaleX(2f);
    // add data
    setData(45, 100);
    //        mChart.setVisibleXRange(20);
    //        mChart.setVisibleYRange(20f, AxisDependency.LEFT);
    //        mChart.centerViewTo(20, 50, AxisDependency.LEFT);
    mChart.animateX(2500);
    //mChart.invalidate();
    // get the legend (only possible after setting data)
    Legend l = mChart.getLegend();
    // modify the legend ...
    l.setForm(LegendForm.LINE);
// // dont forget to refresh the drawing
// mChart.invalidate();
}
Also used : Legend(com.github.mikephil.charting.components.Legend) Typeface(android.graphics.Typeface) LimitLine(com.github.mikephil.charting.components.LimitLine) MyMarkerView(com.xxmassdeveloper.mpchartexample.custom.MyMarkerView) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Aggregations

XAxis (com.github.mikephil.charting.components.XAxis)40 YAxis (com.github.mikephil.charting.components.YAxis)35 Legend (com.github.mikephil.charting.components.Legend)21 IAxisValueFormatter (com.github.mikephil.charting.formatter.IAxisValueFormatter)7 Typeface (android.graphics.Typeface)6 AxisBase (com.github.mikephil.charting.components.AxisBase)6 LineData (com.github.mikephil.charting.data.LineData)6 LineDataSet (com.github.mikephil.charting.data.LineDataSet)6 XFormatter (com.a5corp.weather.utils.XFormatter)5 MyMarkerView (com.xxmassdeveloper.mpchartexample.custom.MyMarkerView)5 View (android.view.View)4 ArrayList (java.util.ArrayList)3 Paint (android.graphics.Paint)2 BarData (com.github.mikephil.charting.data.BarData)2 MyAxisValueFormatter (com.xxmassdeveloper.mpchartexample.custom.MyAxisValueFormatter)2 ValueAnimator (android.animation.ValueAnimator)1 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)1 FrameLayout (android.widget.FrameLayout)1 TextView (android.widget.TextView)1 ChartAnimator (com.github.mikephil.charting.animation.ChartAnimator)1