Search in sources :

Example 1 with XAxis

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

the class AnotherBarActivity 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.getDescription().setEnabled(false);
    // if more than 60 entries are displayed in the chart, no values will be
    // drawn
    mChart.setMaxVisibleValueCount(60);
    // scaling can now only be done on x- and y-axis separately
    mChart.setPinchZoom(false);
    mChart.setDrawBarShadow(false);
    mChart.setDrawGridBackground(false);
    XAxis xAxis = mChart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTTOM);
    xAxis.setDrawGridLines(false);
    mChart.getAxisLeft().setDrawGridLines(false);
    // setting data
    mSeekBarX.setProgress(10);
    mSeekBarY.setProgress(100);
    // add a nice and smooth animation
    mChart.animateY(2500);
    mChart.getLegend().setEnabled(false);
}
Also used : XAxis(com.github.mikephil.charting.components.XAxis)

Example 2 with XAxis

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

the class BarChartActivity 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);
    mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
    mChart = (BarChart) findViewById(R.id.chart1);
    mChart.setOnChartValueSelectedListener(this);
    mChart.setDrawBarShadow(false);
    mChart.setDrawValueAboveBar(true);
    mChart.getDescription().setEnabled(false);
    // if more than 60 entries are displayed in the chart, no values will be
    // drawn
    mChart.setMaxVisibleValueCount(60);
    // scaling can now only be done on x- and y-axis separately
    mChart.setPinchZoom(false);
    mChart.setDrawGridBackground(false);
    // mChart.setDrawYLabels(false);
    IAxisValueFormatter xAxisFormatter = new DayAxisValueFormatter(mChart);
    XAxis xAxis = mChart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTTOM);
    xAxis.setTypeface(mTfLight);
    xAxis.setDrawGridLines(false);
    // only intervals of 1 day
    xAxis.setGranularity(1f);
    xAxis.setLabelCount(7);
    xAxis.setValueFormatter(xAxisFormatter);
    IAxisValueFormatter custom = new MyAxisValueFormatter();
    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setTypeface(mTfLight);
    leftAxis.setLabelCount(8, false);
    leftAxis.setValueFormatter(custom);
    leftAxis.setPosition(YAxisLabelPosition.OUTSIDE_CHART);
    leftAxis.setSpaceTop(15f);
    // this replaces setStartAtZero(true)
    leftAxis.setAxisMinimum(0f);
    YAxis rightAxis = mChart.getAxisRight();
    rightAxis.setDrawGridLines(false);
    rightAxis.setTypeface(mTfLight);
    rightAxis.setLabelCount(8, false);
    rightAxis.setValueFormatter(custom);
    rightAxis.setSpaceTop(15f);
    // this replaces setStartAtZero(true)
    rightAxis.setAxisMinimum(0f);
    Legend l = mChart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
    l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    l.setDrawInside(false);
    l.setForm(LegendForm.SQUARE);
    l.setFormSize(9f);
    l.setTextSize(11f);
    l.setXEntrySpace(4f);
    // l.setExtra(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc",
    // "def", "ghj", "ikl", "mno" });
    // l.setCustom(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc",
    // "def", "ghj", "ikl", "mno" });
    XYMarkerView mv = new XYMarkerView(this, xAxisFormatter);
    // For bounds control
    mv.setChartView(mChart);
    // Set the marker to the chart
    mChart.setMarker(mv);
    setData(12, 50);
    // setting data
    mSeekBarY.setProgress(50);
    mSeekBarX.setProgress(12);
    mSeekBarY.setOnSeekBarChangeListener(this);
    mSeekBarX.setOnSeekBarChangeListener(this);
// mChart.setDrawLegend(false);
}
Also used : XYMarkerView(com.xxmassdeveloper.mpchartexample.custom.XYMarkerView) Legend(com.github.mikephil.charting.components.Legend) IAxisValueFormatter(com.github.mikephil.charting.formatter.IAxisValueFormatter) DayAxisValueFormatter(com.xxmassdeveloper.mpchartexample.custom.DayAxisValueFormatter) XAxis(com.github.mikephil.charting.components.XAxis) MyAxisValueFormatter(com.xxmassdeveloper.mpchartexample.custom.MyAxisValueFormatter) YAxis(com.github.mikephil.charting.components.YAxis)

Example 3 with XAxis

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

the class BarChartActivityMultiDataset 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);
    tvX.setTextSize(10);
    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);
    //        mChart.setDrawBorders(true);
    // scaling can now only be done on x- and y-axis separately
    mChart.setPinchZoom(false);
    mChart.setDrawBarShadow(false);
    mChart.setDrawGridBackground(false);
    // 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);
    mSeekBarX.setProgress(10);
    mSeekBarY.setProgress(100);
    Legend l = mChart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
    l.setOrientation(Legend.LegendOrientation.VERTICAL);
    l.setDrawInside(true);
    l.setTypeface(mTfLight);
    l.setYOffset(0f);
    l.setXOffset(10f);
    l.setYEntrySpace(0f);
    l.setTextSize(8f);
    XAxis xAxis = mChart.getXAxis();
    xAxis.setTypeface(mTfLight);
    xAxis.setGranularity(1f);
    xAxis.setCenterAxisLabels(true);
    xAxis.setValueFormatter(new IAxisValueFormatter() {

        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            return String.valueOf((int) value);
        }
    });
    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setTypeface(mTfLight);
    leftAxis.setValueFormatter(new LargeValueFormatter());
    leftAxis.setDrawGridLines(false);
    leftAxis.setSpaceTop(35f);
    // this replaces setStartAtZero(true)
    leftAxis.setAxisMinimum(0f);
    mChart.getAxisRight().setEnabled(false);
}
Also used : Legend(com.github.mikephil.charting.components.Legend) LargeValueFormatter(com.github.mikephil.charting.formatter.LargeValueFormatter) IAxisValueFormatter(com.github.mikephil.charting.formatter.IAxisValueFormatter) AxisBase(com.github.mikephil.charting.components.AxisBase) MyMarkerView(com.xxmassdeveloper.mpchartexample.custom.MyMarkerView) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Example 4 with XAxis

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

the class BarChartActivitySinus 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_sinus);
    mSinusData = FileUtils.loadBarEntriesFromAssets(getAssets(), "othersine.txt");
    tvX = (TextView) findViewById(R.id.tvValueCount);
    mSeekBarX = (SeekBar) findViewById(R.id.seekbarValues);
    mChart = (BarChart) findViewById(R.id.chart1);
    mChart.setDrawBarShadow(false);
    mChart.setDrawValueAboveBar(true);
    mChart.getDescription().setEnabled(false);
    // if more than 60 entries are displayed in the chart, no values will be
    // drawn
    mChart.setMaxVisibleValueCount(60);
    // scaling can now only be done on x- and y-axis separately
    mChart.setPinchZoom(false);
    // draw shadows for each bar that show the maximum value
    // mChart.setDrawBarShadow(true);
    // mChart.setDrawXLabels(false);
    mChart.setDrawGridBackground(false);
    // mChart.setDrawYLabels(false);
    XAxis xAxis = mChart.getXAxis();
    xAxis.setEnabled(false);
    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setTypeface(mTfLight);
    leftAxis.setLabelCount(6, false);
    leftAxis.setAxisMinimum(-2.5f);
    leftAxis.setAxisMaximum(2.5f);
    leftAxis.setGranularityEnabled(true);
    leftAxis.setGranularity(0.1f);
    YAxis rightAxis = mChart.getAxisRight();
    rightAxis.setDrawGridLines(false);
    rightAxis.setTypeface(mTfLight);
    rightAxis.setLabelCount(6, false);
    rightAxis.setAxisMinimum(-2.5f);
    rightAxis.setAxisMaximum(2.5f);
    rightAxis.setGranularity(0.1f);
    mSeekBarX.setOnSeekBarChangeListener(this);
    // set data
    mSeekBarX.setProgress(150);
    Legend l = mChart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
    l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    l.setDrawInside(false);
    l.setForm(LegendForm.SQUARE);
    l.setFormSize(9f);
    l.setTextSize(11f);
    l.setXEntrySpace(4f);
    mChart.animateXY(2000, 2000);
}
Also used : Legend(com.github.mikephil.charting.components.Legend) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Example 5 with XAxis

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

the class CombinedChartActivity 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_combined);
    mChart = (CombinedChart) findViewById(R.id.chart1);
    mChart.getDescription().setEnabled(false);
    mChart.setBackgroundColor(Color.WHITE);
    mChart.setDrawGridBackground(false);
    mChart.setDrawBarShadow(false);
    mChart.setHighlightFullBarEnabled(false);
    // draw bars behind lines
    mChart.setDrawOrder(new DrawOrder[] { DrawOrder.BAR, DrawOrder.BUBBLE, DrawOrder.CANDLE, DrawOrder.LINE, DrawOrder.SCATTER });
    Legend l = mChart.getLegend();
    l.setWordWrapEnabled(true);
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
    l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    l.setDrawInside(false);
    YAxis rightAxis = mChart.getAxisRight();
    rightAxis.setDrawGridLines(false);
    // this replaces setStartAtZero(true)
    rightAxis.setAxisMinimum(0f);
    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setDrawGridLines(false);
    // this replaces setStartAtZero(true)
    leftAxis.setAxisMinimum(0f);
    XAxis xAxis = mChart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTH_SIDED);
    xAxis.setAxisMinimum(0f);
    xAxis.setGranularity(1f);
    xAxis.setValueFormatter(new IAxisValueFormatter() {

        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            return mMonths[(int) value % mMonths.length];
        }
    });
    CombinedData data = new CombinedData();
    data.setData(generateLineData());
    data.setData(generateBarData());
    data.setData(generateBubbleData());
    data.setData(generateScatterData());
    data.setData(generateCandleData());
    data.setValueTypeface(mTfLight);
    xAxis.setAxisMaximum(data.getXMax() + 0.25f);
    mChart.setData(data);
    mChart.invalidate();
}
Also used : Legend(com.github.mikephil.charting.components.Legend) IAxisValueFormatter(com.github.mikephil.charting.formatter.IAxisValueFormatter) AxisBase(com.github.mikephil.charting.components.AxisBase) CombinedData(com.github.mikephil.charting.data.CombinedData) 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