Java Code Examples for com.github.mikephil.charting.charts.LineChart#invalidate()

The following examples show how to use com.github.mikephil.charting.charts.LineChart#invalidate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KcaResoureLogFragment.java    From kcanotify_h5-master with GNU General Public License v3.0 6 votes vote down vote up
public void setChartDataVisibility(View v, int k) {
    int interval_value = interval[position];
    int y_count = 7;
    LineChart chart = v.findViewById(R.id.reslog_chart);
    if (chart != null && chart.getLineData() != null) {
        ILineDataSet data = chart.getLineData().getDataSetByIndex(k);
        data.setVisible(is_draw_enabled[k]);
        int max_value = 0;
        int min_value = maximum[position];
        for (int i = 0; i < 4; i++) {
            if (is_draw_enabled[i]) {
                max_value = Math.max((int) chart.getLineData().getDataSetByIndex(i).getYMax(), max_value);
                min_value = Math.min((int) chart.getLineData().getDataSetByIndex(i).getYMin(), min_value);
            }
        }
        max_value = (int) (Math.ceil(max_value / (float) interval_value) * interval_value);
        min_value = (int) (Math.floor(min_value / (float) interval_value) * interval_value);
        int range = max_value - min_value;
        while (range % (y_count - 1) != 0) y_count -= 1;
        setChartYRange(chart, max_value, min_value, y_count, interval_value);
        chart.notifyDataSetChanged();
        chart.invalidate();
    }
}
 
Example 2
Source File: LineChartExtensions.java    From exchange-rates-mvvm with Apache License 2.0 6 votes vote down vote up
@BindingAdapter({"bind:items"})
public static void populateDiagram(LineChart view, List<SingleValue> items) {

    if (null == items || items.size() == 0) {
        return;
    }
    List<Entry> entries = new ArrayList<>();
    for (int i = 0; i < items.size(); i++) {
        final SingleValue item = items.get(i);
        final Entry entry = new Entry(i, (float) item.getValue(), item);
        entries.add(entry);
    }
    LineDataSet dataSet = new LineDataSet(entries, view.getContext().getString(R.string.currency_value));
    LineData lineData = new LineData(dataSet);

    formatXAxisLabels(view, items);
    view.setData(lineData);
    view.invalidate();
}
 
Example 3
Source File: DynamicalAddingActivity.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
@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.setOnChartValueSelectedListener(this);
        mChart.setDrawGridBackground(false);
        mChart.setDescription("");
        
        // add an empty data object
        mChart.setData(new LineData());
//        mChart.getXAxis().setDrawLabels(false);
//        mChart.getXAxis().setDrawGridLines(false);

        mChart.invalidate();
    }
 
Example 4
Source File: KcaResoureLogFragment.java    From kcanotify with GNU General Public License v3.0 6 votes vote down vote up
public void setChartDataVisibility(View v, int k) {
    int interval_value = interval[position];
    int y_count = 7;
    LineChart chart = v.findViewById(R.id.reslog_chart);
    if (chart != null && chart.getLineData() != null) {
        ILineDataSet data = chart.getLineData().getDataSetByIndex(k);
        data.setVisible(is_draw_enabled[k]);
        int max_value = 0;
        int min_value = maximum[position];
        for (int i = 0; i < 4; i++) {
            if (is_draw_enabled[i]) {
                max_value = Math.max((int) chart.getLineData().getDataSetByIndex(i).getYMax(), max_value);
                min_value = Math.min((int) chart.getLineData().getDataSetByIndex(i).getYMin(), min_value);
            }
        }
        max_value = (int) (Math.ceil(max_value / (float) interval_value) * interval_value);
        min_value = (int) (Math.floor(min_value / (float) interval_value) * interval_value);
        int range = max_value - min_value;
        while (range % (y_count - 1) != 0) y_count -= 1;
        setChartYRange(chart, max_value, min_value, y_count, interval_value);
        chart.notifyDataSetChanged();
        chart.invalidate();
    }
}
 
Example 5
Source File: PerformanceLineChart.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_performance_linechart);

    mTvCount = (TextView) findViewById(R.id.tvValueCount);
    mSeekBarValues = (SeekBar) findViewById(R.id.seekbarValues);
    mTvCount.setText("500");

    mSeekBarValues.setProgress(500);
    
    mSeekBarValues.setOnSeekBarChangeListener(this);

    mChart = (LineChart) findViewById(R.id.chart1);
    mChart.setDrawGridBackground(false);

    // no description text
    mChart.setDescription("");
    mChart.setNoDataTextDescription("You need to provide data for the chart.");

    // 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(false);
          
    mChart.getAxisLeft().setDrawGridLines(false);
    mChart.getAxisRight().setEnabled(false);
    mChart.getXAxis().setDrawGridLines(true);
    mChart.getXAxis().setDrawAxisLine(false);

    // dont forget to refresh the drawing
    mChart.invalidate();
}
 
Example 6
Source File: Utils.java    From Aria2App with GNU General Public License v3.0 4 votes vote down vote up
public static void setupChart(@NonNull LineChart chart, boolean small, @ColorRes @Nullable Integer fgColorRes) {
    chart.clear();

    int fgColor;
    Context context = chart.getContext();
    if (fgColorRes == null)
        fgColor = CommonUtils.resolveAttrAsColor(context, R.attr.colorOnSurface);
    else
        fgColor = ContextCompat.getColor(context, fgColorRes);

    chart.setDescription(null);
    chart.setDrawGridBackground(false);
    chart.setBackgroundColor(Color.alpha(0));
    chart.setTouchEnabled(false);

    Legend legend = chart.getLegend();
    legend.setTextColor(fgColor);
    legend.setEnabled(true);

    LineData data = new LineData();
    data.setValueTextColor(fgColor);
    chart.setData(data);

    YAxis ya = chart.getAxisLeft();
    ya.setAxisLineColor(fgColor);
    ya.setTextColor(fgColor);
    ya.setTextSize(small ? 8 : 9);
    ya.setAxisMinimum(0);
    ya.setDrawAxisLine(false);
    ya.setLabelCount(small ? 4 : 8, true);
    ya.setEnabled(true);
    ya.setDrawGridLines(true);
    ya.setGridColor(fgColor);
    ya.setValueFormatter(new CustomYAxisValueFormatter());

    chart.getAxisRight().setEnabled(false);
    chart.getXAxis().setEnabled(false);

    data.addDataSet(initUploadSet(context));
    data.addDataSet(initDownloadSet(context));

    chart.invalidate();
}
 
Example 7
Source File: Proxmark3TuneResultActivity.java    From Walrus with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_proxmark3_tune_results);

    Proxmark3Device.TuneResult tuneResult = Parcels.unwrap(getIntent().getParcelableExtra(
            EXTRA_TUNE_RESULT));

    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    if (tuneResult.lf) {
        setResultInfo(tuneResult.peakV, 2.948f, 14.730f, R.id.lfOk);
        ((TextView) findViewById(R.id.lf125)).setText(
                getResources().getString(R.string.tune_voltage, tuneResult.v125));
        ((TextView) findViewById(R.id.lf134)).setText(
                getResources().getString(R.string.tune_voltage, tuneResult.v134));
        ((TextView) findViewById(R.id.lfOptimal)).setText(
                getResources().getString(R.string.tune_peak_voltage, tuneResult.peakV,
                        (tuneResult.peakF / 1000)));

        LineChart lfChart = findViewById(R.id.lfChart);
        if (tuneResult.lfVoltages != null) {
            List<Entry> entries = new ArrayList<>();
            for (int i = 255; i >= 19; --i) {
                entries.add(new Entry(12e6f / (i + 1) / 1e3f, tuneResult.lfVoltages[i]));
            }

            LineDataSet lineDataSet = new LineDataSet(entries, getString(R.string.lf));
            lineDataSet.setColor(Color.BLACK);
            lineDataSet.setCircleColor(Color.BLUE);

            LineData lineData = new LineData(lineDataSet);

            lfChart.setData(lineData);
            lfChart.setDescription(null);
            lfChart.getLegend().setEnabled(false);
            lfChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
            lfChart.getAxisRight().setEnabled(false);
            lfChart.invalidate();
        } else {
            lfChart.setVisibility(View.GONE);
        }
    } else {
        findViewById(R.id.lf).setVisibility(View.GONE);
    }

    if (tuneResult.hf) {
        setResultInfo(tuneResult.hfVoltage, 3.167f, 7.917f, R.id.hfOk);
        ((TextView) findViewById(R.id.hfV)).setText(
                getResources().getString(R.string.tune_voltage, tuneResult.hfVoltage));
    } else {
        findViewById(R.id.hf).setVisibility(View.GONE);
    }
}
 
Example 8
Source File: InvertedLineChartActivity.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
@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.setDescription("");

    // 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);

    // set the marker to the chart
    mChart.setMarkerView(mv);
    
    XAxis xl = mChart.getXAxis();
    xl.setAvoidFirstLastClipping(true);
    
    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setInverted(true);
    leftAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true)
    
    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.setPosition(LegendPosition.LEFT_OF_CHART);
    l.setForm(LegendForm.LINE);

    // dont forget to refresh the drawing
    mChart.invalidate();
}
 
Example 9
Source File: CubicLineChartActivity.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
@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.setViewPortOffsets(0, 20, 0, 0);
    mChart.setBackgroundColor(Color.rgb(104, 241, 175));

    // no description text
    mChart.setDescription("");

    // 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(false);

    mChart.setDrawGridBackground(false);
    
    tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
    
    XAxis x = mChart.getXAxis();
    x.setEnabled(false);
    
    YAxis y = mChart.getAxisLeft();
    y.setTypeface(tf);
    y.setLabelCount(6, false);
    y.setTextColor(Color.WHITE);
    y.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
    y.setDrawGridLines(false);
    y.setAxisLineColor(Color.WHITE);
    
    mChart.getAxisRight().setEnabled(false);

    // add data
    setData(45, 100);
    
    mChart.getLegend().setEnabled(false);
    
    mChart.animateXY(2000, 2000);

    // dont forget to refresh the drawing
    mChart.invalidate();
}
 
Example 10
Source File: GraphActivity.java    From Simple-Accounting with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_graph);

	ActionBar actionBar = getSupportActionBar();
	if (actionBar != null) {
		// Show the Up button in the action bar.
		actionBar.setDisplayHomeAsUpEnabled(true);
	}

	// programmatically create a LineChart
	LineChart chart = findViewById(R.id.chart);

	Session session = getIntent().getParcelableExtra(GRAPH_SESSION);
	int[] updateDate = {getIntent().getIntExtra(GRAPH_UPDATE_MONTH, -1),
			getIntent().getIntExtra(GRAPH_UPDATE_YEAR, -1)};

	((TextView) findViewById(R.id.title)).setText(Utils.INSTANCE.getTitle(this, session, updateDate));

	loadMonthAsyncTask = new LoadMonthAsyncTask(session, null,
			new TableGeneral(this), (result) -> {
		if(result.getDbRows().length > 0) {
			List<Entry> entries = new ArrayList<>();
			BigDecimal bigDecimal = BigDecimal.ZERO;

			for (String[] s : result.getDbRows()) {
				if(s[0] != null) {
					int day = parseInt(s[0]);

					float credit = s[2] != null ? Float.parseFloat(s[2]) : 0,
							debit = s[3] != null ? Float.parseFloat(s[3]) : 0;

					bigDecimal = bigDecimal.add(new BigDecimal(credit));
					bigDecimal = bigDecimal.subtract(new BigDecimal(debit));
					entries.add(new Entry(day, bigDecimal.floatValue()));
				}
			}

			if(entries.size() > 0) {
				for(int i = 0; i < entries.size(); i++) {
					int entriesInDay = 0, day = (int) entries.get(i).getX();
					for(int j = i; j < entries.size() && day == entries.get(j).getX(); j++) {
						entriesInDay++;
					}

					for(int j = i, k = 0; j < entries.size() && day == entries.get(j).getX(); j++, k++) {
						float separationWidth =  1 / (entriesInDay + 1f);//the amount of space between points in the same day (X axis)
						entries.get(j).setX(day + (k+1) * separationWidth);
					}

					while(day == entries.get(i).getX()) i++;
				}

				LineDataSet dataSet = new LineDataSet(entries, null);
				dataSet.setValueFormatter(new MoneyFormatter());

				chart.setData(new LineData(dataSet));
			} else {
				chart.setNoDataText(getString(R.string.nothing_to_graph));
				Snackbar.make(chart, R.string.without_day_data_is_not_charted, Snackbar.LENGTH_LONG).show();
			}
		} else {
			chart.setNoDataText(getString(R.string.nothing_to_graph));
		}

		chart.notifyDataSetChanged();
		chart.invalidate();
	});

	loadMonthAsyncTask.execute();

	chart.getAxisRight().setEnabled(false);
	chart.getXAxis().setValueFormatter(new DeleteNonWholeFormatter());
	chart.getXAxis().setAxisMinimum(0);
	chart.getXAxis().setAxisMaximum(32);
	chart.getXAxis().setDrawGridLines(false);
	chart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
	chart.getLegend().setEnabled(false);
	chart.setDescription(null);
	chart.setNoDataText(getString(R.string.loading));
}
 
Example 11
Source File: UserProfileActivity.java    From zhizhihu with Apache License 2.0 4 votes vote down vote up
private void initHeaderView(UserDetail detail) {

        View headerView = LayoutInflater.from(this)
                .inflate(R.layout.layout_user_profile_header, mTopAnswerListView, false);
        mUserAvatarImg = ButterKnife.findById(headerView, R.id.user_avatar_img);
        mUserDescriptionTxt = ButterKnife.findById(headerView, R.id.user_description_txt);
        mUserSignatureTxt = ButterKnife.findById(headerView, R.id.user_signature_txt);
        mAgreeCountTxt = ButterKnife.findById(headerView, R.id.agree_count_txt);
        mFollowerCountTxt = ButterKnife.findById(headerView, R.id.follower_count_txt);
        mFavCountTxt = ButterKnife.findById(headerView, R.id.fav_count_txt);
        mAskCountTxt = ButterKnife.findById(headerView, R.id.ask_count_txt);
        mAnswerCountTxt = ButterKnife.findById(headerView, R.id.answer_count_txt);
        mPostCountTxt = ButterKnife.findById(headerView, R.id.post_count_txt);


        List<String> xData = new ArrayList<>();
        List<Entry> answerDatas = new ArrayList<>();
        List<Entry> agreeDatas = new ArrayList<>();
        List<Entry> followerDatas = new ArrayList<>();

        for (int i = 0; i < detail.getTrend().size(); i++) {
            UserDetail.Trend trend = detail.getTrend().get(i);

            xData.add(trend.getDate());
            answerDatas.add(new Entry(Float.parseFloat(trend.getAnswer()), i));
            agreeDatas.add(new Entry(Float.parseFloat(trend.getAgree()), i));
            followerDatas.add(new Entry(Float.parseFloat(trend.getFollower()), i));
        }
        LineDataSet answerDataSet = new LineDataSet(answerDatas, "回答数");
        LineDataSet agreeDataSet = new LineDataSet(agreeDatas, "赞同数");
        LineDataSet followerDataSet = new LineDataSet(followerDatas, "粉丝数");

        LineChart trendsChart = ButterKnife.findById(headerView, R.id.trends_chart);
        LineChart agreeChart = ButterKnife.findById(headerView, R.id.agree_chart);
        LineChart followerChart = ButterKnife.findById(headerView, R.id.follower_chart);

        XAxis xAxis = trendsChart.getXAxis();
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        LineData data = new LineData(xData, answerDataSet);
        trendsChart.setData(data);
        trendsChart.invalidate();

        XAxis agreeX = agreeChart.getXAxis();
        agreeX.setPosition(XAxis.XAxisPosition.BOTTOM);
        LineData agreeData = new LineData(xData, agreeDataSet);
        agreeChart.setData(agreeData);
        agreeChart.invalidate();

        XAxis followerX = followerChart.getXAxis();
        followerX.setPosition(XAxis.XAxisPosition.BOTTOM);
        LineData followerData = new LineData(xData, followerDataSet);
        followerChart.setData(followerData);
        followerChart.invalidate();


        Glide.with(this)
                .load(detail.getAvatar())
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(mUserAvatarImg);

        mUserDescriptionTxt.setText(detail.getDescription());
        mUserSignatureTxt.setText(detail.getSignature());

        mAgreeCountTxt.setText(detail.getDetail().getAgree());
        mFollowerCountTxt.setText(detail.getDetail().getFollower());
        mFavCountTxt.setText(detail.getDetail().getFav());
        mAskCountTxt.setText(detail.getDetail().getAsk());
        mAnswerCountTxt.setText(detail.getDetail().getAnswer());
        mPostCountTxt.setText(detail.getDetail().getPost());

        mTopAnswerListView.addHeaderView(headerView);

    }
 
Example 12
Source File: CalibrationLinearityActivity.java    From NoiseCapture with GNU General Public License v3.0 4 votes vote down vote up
private void updateLineChart() {
    LineChart lineChart = getLineChart();
    if(lineChart == null) {
        return;
    }
    if(freqLeqStats.isEmpty()) {
        return;
    }
    float YMin = Float.MAX_VALUE;
    float YMax = Float.MIN_VALUE;

    ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();

    // Read all white noise values for indexing before usage
    int idStep = 0;
    double referenceLevel = freqLeqStats.get(0).whiteNoiseLevel.getGlobaldBaValue();
    for(LinearCalibrationResult result : freqLeqStats) {
        ArrayList<Entry> yMeasure = new ArrayList<Entry>();
        int idfreq = 0;
        for (LeqStats leqStat : result.measure) {
            float dbLevel = (float)leqStat.getLeqMean();
            YMax = Math.max(YMax, dbLevel);
            YMin = Math.min(YMin, dbLevel);
            yMeasure.add(new Entry(dbLevel, idfreq++));
        }
        LineDataSet freqSet = new LineDataSet(yMeasure, String.format(Locale.getDefault(),"%d dB",
                (int)(result.whiteNoiseLevel.getGlobaldBaValue() - referenceLevel)));
        freqSet.setColor(ColorTemplate.COLORFUL_COLORS[idStep % ColorTemplate.COLORFUL_COLORS.length]);
        freqSet.setFillColor(ColorTemplate.COLORFUL_COLORS[idStep % ColorTemplate.COLORFUL_COLORS.length]);
        freqSet.setValueTextColor(Color.WHITE);
        freqSet.setCircleColorHole(ColorTemplate.COLORFUL_COLORS[idStep % ColorTemplate.COLORFUL_COLORS.length]);
        freqSet.setDrawValues(false);
        freqSet.setDrawFilled(true);
        freqSet.setFillAlpha(255);
        freqSet.setDrawCircles(true);
        freqSet.setMode(LineDataSet.Mode.LINEAR);
        dataSets.add(freqSet);
        idStep++;
    }


    ArrayList<String> xVals = new ArrayList<String>();
    double[] freqs = FFTSignalProcessing.computeFFTCenterFrequency(AudioProcess.REALTIME_SAMPLE_RATE_LIMITATION);
    for (double freqValue : freqs) {
        xVals.add(Spectrogram.formatFrequency((int)freqValue));
    }

    // create a data object with the datasets
    LineData data = new LineData(xVals, dataSets);
    lineChart.setData(data);
    YAxis yl = lineChart.getAxisLeft();
    yl.setAxisMinValue(YMin - 3);
    yl.setAxisMaxValue(YMax + 3);
    lineChart.invalidate();
}