Search in sources :

Example 26 with YAxis

use of com.github.mikephil.charting.components.YAxis 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);
    setTitle("BarChartActivity");
    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.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);
    chart.setDrawGridBackground(false);
    // chart.setDrawYLabels(false);
    IAxisValueFormatter xAxisFormatter = new DayAxisValueFormatter(chart);
    XAxis xAxis = chart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTTOM);
    xAxis.setTypeface(tfLight);
    xAxis.setDrawGridLines(false);
    // only intervals of 1 day
    xAxis.setGranularity(1f);
    xAxis.setLabelCount(7);
    xAxis.setValueFormatter(xAxisFormatter);
    IAxisValueFormatter custom = new MyAxisValueFormatter();
    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.setTypeface(tfLight);
    leftAxis.setLabelCount(8, false);
    leftAxis.setValueFormatter(custom);
    leftAxis.setPosition(YAxisLabelPosition.OUTSIDE_CHART);
    leftAxis.setSpaceTop(15f);
    // this replaces setStartAtZero(true)
    leftAxis.setAxisMinimum(0f);
    YAxis rightAxis = chart.getAxisRight();
    rightAxis.setDrawGridLines(false);
    rightAxis.setTypeface(tfLight);
    rightAxis.setLabelCount(8, false);
    rightAxis.setValueFormatter(custom);
    rightAxis.setSpaceTop(15f);
    // this replaces setStartAtZero(true)
    rightAxis.setAxisMinimum(0f);
    Legend l = chart.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);
    XYMarkerView mv = new XYMarkerView(this, xAxisFormatter);
    // For bounds control
    mv.setChartView(chart);
    // Set the marker to the chart
    chart.setMarker(mv);
    // setting data
    seekBarY.setProgress(50);
    seekBarX.setProgress(12);
// chart.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 27 with YAxis

use of com.github.mikephil.charting.components.YAxis 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);
    setTitle("BarChartActivityMultiDataset");
    tvX = findViewById(R.id.tvXMax);
    tvX.setTextSize(10);
    tvY = findViewById(R.id.tvYMax);
    seekBarX = findViewById(R.id.seekBar1);
    seekBarX.setMax(50);
    seekBarX.setOnSeekBarChangeListener(this);
    seekBarY = findViewById(R.id.seekBar2);
    seekBarY.setOnSeekBarChangeListener(this);
    chart = findViewById(R.id.chart1);
    chart.setOnChartValueSelectedListener(this);
    chart.getDescription().setEnabled(false);
    // chart.setDrawBorders(true);
    // scaling can now only be done on x- and y-axis separately
    chart.setPinchZoom(false);
    chart.setDrawBarShadow(false);
    chart.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(chart);
    // Set the marker to the chart
    chart.setMarker(mv);
    seekBarX.setProgress(10);
    seekBarY.setProgress(100);
    Legend l = chart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
    l.setOrientation(Legend.LegendOrientation.VERTICAL);
    l.setDrawInside(true);
    l.setTypeface(tfLight);
    l.setYOffset(0f);
    l.setXOffset(10f);
    l.setYEntrySpace(0f);
    l.setTextSize(8f);
    XAxis xAxis = chart.getXAxis();
    xAxis.setTypeface(tfLight);
    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 = chart.getAxisLeft();
    leftAxis.setTypeface(tfLight);
    leftAxis.setValueFormatter(new LargeValueFormatter());
    leftAxis.setDrawGridLines(false);
    leftAxis.setSpaceTop(35f);
    // this replaces setStartAtZero(true)
    leftAxis.setAxisMinimum(0f);
    chart.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 28 with YAxis

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

the class RadarChart method init.

@Override
protected void init() {
    super.init();
    mYAxis = new YAxis(AxisDependency.LEFT);
    mYAxis.setLabelXOffset(10f);
    mWebLineWidth = Utils.convertDpToPixel(1.5f);
    mInnerWebLineWidth = Utils.convertDpToPixel(0.75f);
    mRenderer = new RadarChartRenderer(this, mAnimator, mViewPortHandler);
    mYAxisRenderer = new YAxisRendererRadarChart(mViewPortHandler, mYAxis, this);
    mXAxisRenderer = new XAxisRendererRadarChart(mViewPortHandler, mXAxis, this);
    mHighlighter = new RadarHighlighter(this);
}
Also used : RadarChartRenderer(com.github.mikephil.charting.renderer.RadarChartRenderer) XAxisRendererRadarChart(com.github.mikephil.charting.renderer.XAxisRendererRadarChart) RadarHighlighter(com.github.mikephil.charting.highlight.RadarHighlighter) YAxisRendererRadarChart(com.github.mikephil.charting.renderer.YAxisRendererRadarChart) YAxis(com.github.mikephil.charting.components.YAxis)

Example 29 with YAxis

use of com.github.mikephil.charting.components.YAxis in project Gadgetbridge by Freeyourgadget.

the class AbstractWeekChartFragment method setupWeekChart.

private void setupWeekChart() {
    mWeekChart.setBackgroundColor(BACKGROUND_COLOR);
    mWeekChart.getDescription().setTextColor(DESCRIPTION_COLOR);
    mWeekChart.getDescription().setText("");
    mWeekChart.setFitBars(true);
    configureBarLineChartDefaults(mWeekChart);
    XAxis x = mWeekChart.getXAxis();
    x.setDrawLabels(true);
    x.setDrawGridLines(false);
    x.setEnabled(true);
    x.setTextColor(CHART_TEXT_COLOR);
    x.setDrawLimitLinesBehindData(true);
    x.setPosition(XAxis.XAxisPosition.BOTTOM);
    YAxis y = mWeekChart.getAxisLeft();
    y.setDrawGridLines(false);
    y.setDrawTopYLabelEntry(false);
    y.setTextColor(CHART_TEXT_COLOR);
    y.setDrawZeroLine(true);
    y.setSpaceBottom(0);
    y.setAxisMinimum(0);
    y.setValueFormatter(getYAxisFormatter());
    y.setEnabled(true);
    YAxis yAxisRight = mWeekChart.getAxisRight();
    yAxisRight.setDrawGridLines(false);
    yAxisRight.setEnabled(false);
    yAxisRight.setDrawLabels(false);
    yAxisRight.setDrawTopYLabelEntry(false);
    yAxisRight.setTextColor(CHART_TEXT_COLOR);
}
Also used : XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Example 30 with YAxis

use of com.github.mikephil.charting.components.YAxis in project Weather by Sparker0i.

the class GraphsFragment method loadSnowChart.

public void loadSnowChart() {
    snowChart.setDrawGridBackground(false);
    snowChart.setBackgroundColor(Color.BLACK);
    snowChart.setTouchEnabled(true);
    snowChart.setDragEnabled(true);
    snowChart.setMaxHighlightDistance(300);
    snowChart.setPinchZoom(true);
    snowChart.setPadding(2, 2, 2, 2);
    snowChart.getLegend().setEnabled(true);
    snowChart.getLegend().setTextColor(Color.WHITE);
    YAxis yAxisRight = snowChart.getAxisRight();
    yAxisRight.setDrawGridLines(false);
    yAxisRight.setDrawAxisLine(false);
    yAxisRight.setDrawLabels(false);
    yAxisRight.setTextColor(Color.WHITE);
    yAxisRight.enableAxisLineDashedLine(2f, 4f, 2f);
    YAxis yAxisLeft = snowChart.getAxisLeft();
    yAxisLeft.setTextColor(Color.WHITE);
    XAxis x = snowChart.getXAxis();
    x.setEnabled(true);
    x.setPosition(XAxis.XAxisPosition.BOTTOM);
    x.setDrawGridLines(false);
    x.setTextColor(Color.parseColor("#FFFFFF"));
    x.setValueFormatter(new XFormatter(dates));
    LineDataSet set;
    if (snowChart.getData() != null) {
        snowChart.getData().removeDataSet(snowChart.getData().getDataSetByIndex(snowChart.getData().getDataSetCount() - 1));
        snowChart.getLegend().setTextColor(Color.parseColor("#FFFFFF"));
    }
    set = new LineDataSet(snowEntries, getString(R.string.g_snow));
    set.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
    set.setCubicIntensity(0.2f);
    set.setDrawCircles(false);
    set.setLineWidth(2f);
    set.setDrawValues(false);
    set.setValueTextSize(10f);
    set.setColor(Color.YELLOW);
    set.setHighlightEnabled(false);
    set.setValueFormatter(mValueFormatter);
    LineData data = new LineData(set);
    snowChart.setData(data);
    snowChart.invalidate();
}
Also used : LineData(com.github.mikephil.charting.data.LineData) LineDataSet(com.github.mikephil.charting.data.LineDataSet) XFormatter(com.a5corp.weather.utils.XFormatter) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Aggregations

YAxis (com.github.mikephil.charting.components.YAxis)51 XAxis (com.github.mikephil.charting.components.XAxis)45 Legend (com.github.mikephil.charting.components.Legend)22 IAxisValueFormatter (com.github.mikephil.charting.formatter.IAxisValueFormatter)11 AxisBase (com.github.mikephil.charting.components.AxisBase)10 LineData (com.github.mikephil.charting.data.LineData)8 LineDataSet (com.github.mikephil.charting.data.LineDataSet)7 XFormatter (com.a5corp.weather.utils.XFormatter)5 Entry (com.github.mikephil.charting.data.Entry)5 MyMarkerView (com.xxmassdeveloper.mpchartexample.custom.MyMarkerView)5 ArrayList (java.util.ArrayList)5 Typeface (android.graphics.Typeface)4 View (android.view.View)4 OsmandSettings (net.osmand.plus.OsmandSettings)4 SuppressLint (android.annotation.SuppressLint)3 Paint (android.graphics.Paint)3 SpannableString (android.text.SpannableString)3 LimitLine (com.github.mikephil.charting.components.LimitLine)3 MarkerView (com.github.mikephil.charting.components.MarkerView)2 YAxisRenderer (com.github.mikephil.charting.renderer.YAxisRenderer)2