Search in sources :

Example 1 with MyAxisValueFormatter

use of com.xxmassdeveloper.mpchartexample.custom.MyAxisValueFormatter 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 2 with MyAxisValueFormatter

use of com.xxmassdeveloper.mpchartexample.custom.MyAxisValueFormatter 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)

Aggregations

Legend (com.github.mikephil.charting.components.Legend)2 XAxis (com.github.mikephil.charting.components.XAxis)2 YAxis (com.github.mikephil.charting.components.YAxis)2 MyAxisValueFormatter (com.xxmassdeveloper.mpchartexample.custom.MyAxisValueFormatter)2 IAxisValueFormatter (com.github.mikephil.charting.formatter.IAxisValueFormatter)1 DayAxisValueFormatter (com.xxmassdeveloper.mpchartexample.custom.DayAxisValueFormatter)1 XYMarkerView (com.xxmassdeveloper.mpchartexample.custom.XYMarkerView)1