for Line chart i'm using mp android chart i want to remove the line which is left side of the graph not the gridlines.
code:-
chart.setGridBackgroundColor(128);
chart.setBorderColor(255);
chart.getAxisRight().setEnabled(false);
YAxis leftAxis = chart.getAxisLeft();
leftAxis.setEnabled(false);
chart.setDrawGridBackground(true);
XAxis xAxis = chart.getXAxis();
xAxis.setDrawGridLines(true);
chart.getAxisRight().setDrawLabels(false);
chart.getAxisLeft().setDrawLabels(false);
chart.getLegend().setEnabled(false);
chart.setPinchZoom(false);
chart.setDescription("");
chart.setTouchEnabled(false);
chart.setDoubleTapToZoomEnabled(false);
chart.getXAxis().setEnabled(true);
chart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
chart.getXAxis().setDrawGridLines(false);
chart.invalidate();
Add this following code,
YAxis leftAxis = lineChart.getAxisLeft();
leftAxis.setEnabled(false);
You can enable or disable gridline by,
lineChart.setDrawGridBackground(true);
XAxis xAxis = lineChart.getXAxis();
xAxis.setDrawGridLines(true);
xAxis.setDrawAxisLine(true);
UPDATE
chart.setGridBackgroundColor(128);
chart.setBorderColor(255);
chart.getAxisRight().setEnabled(false);
YAxis leftAxis = chart.getAxisLeft();
leftAxis.setEnabled(false);
chart.setDrawGridBackground(true);
chart.getAxisRight().setDrawLabels(false);
chart.getAxisLeft().setDrawLabels(false);
chart.getLegend().setEnabled(false);
chart.setPinchZoom(false);
chart.setDescription("");
chart.setTouchEnabled(false);
chart.setDoubleTapToZoomEnabled(false);
chart.getXAxis().setEnabled(true);
chart.setDrawGridBackground(true);//enable this too
chart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
chart.getXAxis().setDrawGridLines(true);//enable for grid line
chart.getYAxis().setDrawGridLines(false);//disable vertical line
chart.invalidate();
I had got by adding following line
leftAxis.setDrawAxisLine(false);
If the X Axis line is to be removed then use
chart.getXAxis().setDrawAxisLine(false);
Related
I am displaying a simple bar graph where in I want to display the Y labels above the bar. For this i am setting mChart.setDrawValueAboveBar(true);. It is just not displaying anything. If this value is set to false, labels are displayed in the bar.
Below is the code for default settings:
mChart.setDrawBarShadow(false);
mChart.setDrawValueAboveBar(true);
mChart.setSelected(false);
mChart.getDescription().setEnabled(false);
// scaling can now only be done on x- and y-axis separately
mChart.setPinchZoom(false);
mChart.setDoubleTapToZoomEnabled(false);
mChart.setDrawBarShadow(false);
mChart.setDrawGridBackground(false);
mChart.getAxisLeft().setDrawLabels(true);
mChart.getAxisRight().setDrawLabels(true);
mChart.getXAxis().setDrawLabels(true);
mChart.getLegend().setEnabled(false);
XAxis xAxis = mChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setGranularity(1f);
xAxis.setAxisLineColor(ContextCompat.getColor(mContext, R.color.red));
xAxis.setTextColor(ContextCompat.getColor(mContext, R.color.red));
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setValueFormatter(new LargeValueFormatter());
leftAxis.setDrawGridLines(false);
leftAxis.setEnabled(false);
leftAxis.setAxisMinimum(0f);
leftAxis.setSpaceBottom(0);
leftAxis.setSpaceTop(15f);
leftAxis.disableAxisLineDashedLine();
leftAxis.disableGridDashedLine();
YAxis rightAxis = mChart.getAxisRight();
rightAxis.setDrawGridLines(false);
rightAxis.setAxisMinimum(0f);
rightAxis.setSpaceBottom(0);
rightAxis.setSpaceTop(15f);
rightAxis.disableAxisLineDashedLine();
rightAxis.disableGridDashedLine();
rightAxis.setEnabled(false);
The value on the last point of the LineChart doesn't show even
in the mpAndroidChart example.
always value of the last point can't be seen I tried adding padding , layout_margin and setExtraOffsets ..
Screenshot
I'm using v3.0.0, and this is the LineChart Code:
lineChart.setDragEnabled(true);
lineChart.getDescription().setEnabled(false);
lineChart.animateY(2000);
lineChart.setDrawBorders(false);
lineChart.setVisibleXRange(3,7);
YAxis leftAxis=lineChart.getAxisLeft();
leftAxis.setDrawGridLines(false);
leftAxis.setEnabled(false);
YAxis rightAxis = lineChart.getAxisRight();
rightAxis.setEnabled(false);
IAxisValueFormatter xAxisFormatter = new DayAxisValueFormatter(lineChart);
XAxis xAxis = lineChart.getXAxis();
xAxis.setTextColor(Color.WHITE);
xAxis.setTextSize(13);
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setDrawGridLines(false);
xAxis.setGranularity(1f);
xAxis.setCenterAxisLabels(false);
xAxis.setValueFormatter(xAxisFormatter);
I finally got it to work by a workaround.
Add an extra Entry for each dataSet after the last Entry and then set the setAxisMaximum for the xAxis to the last value, like this
dataset1.addEntry(new Entry(endDay+1,yValues1[i]));
dataSet2.addEntry(new Entry(endDay+1,yValues2[i]));
dataSet3.addEntry(new Entry(endDay+1,yValues3[i]));
xAxis.setAxisMaximum(endDay+0.1f);`
I am using mpandroidchart library to draw Bar chart for my ANDROID app. I deleted all background lines except horizontal lines. How to delete them?
Try with this:
XAxis xAxis = mChart.getXAxis();
xAxis.setDrawGridLines(false);
xAxis.disableGridDashedLine();
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setDrawAxisLine(false); //If you do not want Axis Line.
leftAxis.setDrawGridLines(false); //If you do not want Grid Line.
YAxis rightAxis = mChart.getAxisRight();
rightAxis.setDrawAxisLine(false); //If you do not want Axis Line.
rightAxis.setDrawGridLines(false); //If you do not want Grid Line.
Hope this answer will help you.
To remove horizontal lines, use
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setDrawGridLines(false);
and
YAxis rightAxis = mChart.getAxisRight();
rightAxis.setDrawGridLines(false);
To remove vertical lines, use
XAxis xAxis = mChart.getXAxis();
xAxix.setDrawGridLines(false);
I have downloaded the MPAndroidChart library to draw a LineChart, i have noticed that this LineChart always draw the xAxis on top of yAxis, me i need to draw xAxis on bottom of yAxis
this is how i initialize the chart
mChart = (LineChart) findViewById(R.id.chart1);
mChart.setDescription("");
mChart.setNoDataTextDescription("You need to provide data for the chart.");
// enable value highlighting
mChart.setHighlightEnabled(true);
// enable touch gestures
mChart.setTouchEnabled(true);
mChart.setDragDecelerationFrictionCoef(0.9f);
// enable scaling and dragging
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);
mChart.setDrawGridBackground(false);
mChart.setHighlightPerDragEnabled(true);
mChart.setBackgroundColor(Color.WHITE);
XAxis xAxis = mChart.getXAxis();
xAxis.setDrawGridLines(false);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setTextColor(ColorTemplate.getHoloBlue());
leftAxis.setAxisMaxValue(200f);
leftAxis.setDrawGridLines(false);
YAxis rightAxis = mChart.getAxisRight();
rightAxis.setDrawAxisLine(false);
rightAxis.setTextColor(Color.WHITE);
rightAxis.setDrawGridLines(false);
MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
// set the marker to the chart
mChart.setMarkerView(mv);
Try this: xAxis.setPosition(XAxisPosition.BOTTOM)
More that in the documentation.
I need to remove right legends from BarChart.
This is my code.
mChart = (BarChart) rootView.findViewById(R.id.chart1);
mChart.setOnChartValueSelectedListener(this);
mChart.setDrawBarShadow(false);
mChart.setDrawValueAboveBar(true);
mChart.setDescription("");
mChart.setMaxVisibleValueCount(60);
mChart.setPinchZoom(false);
mChart.setDrawGridBackground(false);
mTf = Typeface.createFromAsset(getActivity().getAssets(), "OpenSans-Regular.ttf");
XAxis xAxis = mChart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTTOM);
xAxis.setTypeface(mTf);
xAxis.setDrawGridLines(false);
xAxis.setSpaceBetweenLabels(2);
ValueFormatter custom = new MyValueFormatter();
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setTypeface(mTf);
leftAxis.setLabelCount(8);
leftAxis.setValueFormatter(custom);
leftAxis.setPosition(YAxisLabelPosition.OUTSIDE_CHART);
leftAxis.setSpaceTop(15f);
Legend l = mChart.getLegend();
l.setPosition(LegendPosition.BELOW_CHART_LEFT);
l.setForm(LegendForm.SQUARE);
l.setFormSize(9f);
l.setTextSize(11f);
l.setXEntrySpace(4f);
mChart.animateXY(3000, 3000);
Thanks!
Add this line
rightAxis.setDrawLabels(false);
To hide only the labels.
For hiding the whole right axis, call:
rightAxis.setEnabled(false);
A simple one liner:
chart.getAxisRight().setEnabled(false);
For those using Kotlin lang:
chart.axisRight.isEnabled = false
Hope it helps!