use of com.github.mikephil.charting.components.YAxis in project MPAndroidChart by PhilJay.
the class DrawChartActivity 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_draw_chart);
setTitle("DrawChartActivity");
chart = findViewById(R.id.chart1);
// listener for selecting and drawing
chart.setOnChartValueSelectedListener(this);
chart.setOnDrawListener(this);
// if disabled, drawn data sets with the finger will not be automatically
// finished
// chart.setAutoFinish(true);
chart.setDrawGridBackground(false);
// add dummy-data to the chart
initWithDummyData();
XAxis xl = chart.getXAxis();
xl.setTypeface(tfRegular);
xl.setAvoidFirstLastClipping(true);
YAxis yl = chart.getAxisLeft();
yl.setTypeface(tfRegular);
chart.getLegend().setEnabled(false);
// chart.setYRange(-40f, 40f, true);
// call this to reset the changed y-range
// chart.resetYRange(true);
}
use of com.github.mikephil.charting.components.YAxis 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);
setTitle("FilledLineActivity");
chart = findViewById(R.id.chart1);
chart.setBackgroundColor(Color.WHITE);
chart.setGridBackgroundColor(fillColor);
chart.setDrawGridBackground(true);
chart.setDrawBorders(true);
// no description text
chart.getDescription().setEnabled(false);
// if disabled, scaling can be done on x- and y-axis separately
chart.setPinchZoom(false);
Legend l = chart.getLegend();
l.setEnabled(false);
XAxis xAxis = chart.getXAxis();
xAxis.setEnabled(false);
YAxis leftAxis = chart.getAxisLeft();
leftAxis.setAxisMaximum(900f);
leftAxis.setAxisMinimum(-250f);
leftAxis.setDrawAxisLine(false);
leftAxis.setDrawZeroLine(false);
leftAxis.setDrawGridLines(false);
chart.getAxisRight().setEnabled(false);
// add data
setData(100, 60);
chart.invalidate();
}
use of com.github.mikephil.charting.components.YAxis in project MPAndroidChart by PhilJay.
the class HorizontalBarNegativeChartActivity 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_horizontalbarchart);
setTitle("HorizontalBarChartActivity");
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
seekBarX = findViewById(R.id.seekBar1);
seekBarY = findViewById(R.id.seekBar2);
seekBarY.setOnSeekBarChangeListener(this);
seekBarX.setOnSeekBarChangeListener(this);
chart = findViewById(R.id.chart1);
chart.setOnChartValueSelectedListener(this);
// chart.setHighlightEnabled(false);
chart.setDrawBarShadow(false);
chart.setDrawValueAboveBar(true);
chart.getDescription().setEnabled(false);
// if more than 60 entries are displayed in the chart, no values will be
// drawn
chart.setMaxVisibleValueCount(60);
// scaling can now only be done on x- and y-axis separately
chart.setPinchZoom(false);
// draw shadows for each bar that show the maximum value
// chart.setDrawBarShadow(true);
chart.setDrawGridBackground(false);
XAxis xl = chart.getXAxis();
xl.setPosition(XAxisPosition.BOTTOM);
xl.setTypeface(tfLight);
xl.setDrawAxisLine(true);
xl.setDrawGridLines(false);
xl.setGranularity(10f);
YAxis yl = chart.getAxisLeft();
yl.setTypeface(tfLight);
yl.setDrawAxisLine(true);
yl.setDrawGridLines(true);
// yl.setInverted(true);
YAxis yr = chart.getAxisRight();
yr.setTypeface(tfLight);
yr.setDrawAxisLine(true);
yr.setDrawGridLines(false);
// yr.setInverted(true);
chart.setFitBars(true);
chart.animateY(2500);
// setting data
seekBarY.setProgress(50);
seekBarX.setProgress(12);
Legend l = chart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
l.setFormSize(8f);
l.setXEntrySpace(4f);
}
use of com.github.mikephil.charting.components.YAxis 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);
setTitle("LineChartActivity1");
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
seekBarX = findViewById(R.id.seekBar1);
seekBarX.setOnSeekBarChangeListener(this);
seekBarY = findViewById(R.id.seekBar2);
seekBarY.setMax(180);
seekBarY.setOnSeekBarChangeListener(this);
{
// // Chart Style // //
chart = findViewById(R.id.chart1);
// background color
chart.setBackgroundColor(Color.WHITE);
// disable description text
chart.getDescription().setEnabled(false);
// enable touch gestures
chart.setTouchEnabled(true);
// set listeners
chart.setOnChartValueSelectedListener(this);
chart.setDrawGridBackground(false);
// create marker to display box when values are selected
MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
// Set the marker to the chart
mv.setChartView(chart);
chart.setMarker(mv);
// enable scaling and dragging
chart.setDragEnabled(true);
chart.setScaleEnabled(true);
// chart.setScaleXEnabled(true);
// chart.setScaleYEnabled(true);
// force pinch zoom along both axis
chart.setPinchZoom(true);
}
XAxis xAxis;
{
// // X-Axis Style // //
xAxis = chart.getXAxis();
// vertical grid lines
xAxis.enableGridDashedLine(10f, 10f, 0f);
}
YAxis yAxis;
{
// // Y-Axis Style // //
yAxis = chart.getAxisLeft();
// disable dual axis (only use LEFT axis)
chart.getAxisRight().setEnabled(false);
// horizontal grid lines
yAxis.enableGridDashedLine(10f, 10f, 0f);
// axis range
yAxis.setAxisMaximum(200f);
yAxis.setAxisMinimum(-50f);
}
{
// // Create Limit Lines // //
LimitLine llXAxis = new LimitLine(9f, "Index 10");
llXAxis.setLineWidth(4f);
llXAxis.enableDashedLine(10f, 10f, 0f);
llXAxis.setLabelPosition(LimitLabelPosition.RIGHT_BOTTOM);
llXAxis.setTextSize(10f);
llXAxis.setTypeface(tfRegular);
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(tfRegular);
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(tfRegular);
// draw limit lines behind data instead of on top
yAxis.setDrawLimitLinesBehindData(true);
xAxis.setDrawLimitLinesBehindData(true);
// add limit lines
yAxis.addLimitLine(ll1);
yAxis.addLimitLine(ll2);
// xAxis.addLimitLine(llXAxis);
}
// add data
seekBarX.setProgress(45);
seekBarY.setProgress(180);
setData(45, 180);
// draw points over time
chart.animateX(1500);
// get the legend (only possible after setting data)
Legend l = chart.getLegend();
// draw legend entries as lines
l.setForm(LegendForm.LINE);
}
use of com.github.mikephil.charting.components.YAxis in project MPAndroidChart by PhilJay.
the class CubicLineChartActivity 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);
setTitle("CubicLineChartActivity");
tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);
seekBarX = findViewById(R.id.seekBar1);
seekBarY = findViewById(R.id.seekBar2);
chart = findViewById(R.id.chart1);
chart.setViewPortOffsets(0, 0, 0, 0);
chart.setBackgroundColor(Color.rgb(104, 241, 175));
// no description text
chart.getDescription().setEnabled(false);
// 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.setDrawGridBackground(false);
chart.setMaxHighlightDistance(300);
XAxis x = chart.getXAxis();
x.setEnabled(false);
YAxis y = chart.getAxisLeft();
y.setTypeface(tfLight);
y.setLabelCount(6, false);
y.setTextColor(Color.WHITE);
y.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
y.setDrawGridLines(false);
y.setAxisLineColor(Color.WHITE);
chart.getAxisRight().setEnabled(false);
// add data
seekBarY.setOnSeekBarChangeListener(this);
seekBarX.setOnSeekBarChangeListener(this);
// lower max, as cubic runs significantly slower than linear
seekBarX.setMax(700);
seekBarX.setProgress(45);
seekBarY.setProgress(100);
chart.getLegend().setEnabled(false);
chart.animateXY(2000, 2000);
// don't forget to refresh the drawing
chart.invalidate();
}
Aggregations