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!
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);
Similar to MPAndroidChart - First and last bars not rendering correctly, the first and last bubble in my chart isn't rendered fully, and is sliced in half as seen in the image.
The following is the current implementation for the BubbleChart.
private void initializeBubbleChart() {
mChart = (BubbleChart) findViewById(R.id.bubblechart);
mChart .setDescription("");
mChart .setOnChartValueSelectedListener(this);
mChart .setDrawGridBackground(false);
mChart .setTouchEnabled(true);
mChart .setDragEnabled(true);
mChart .setScaleEnabled(true);
AxisValueFormatter xAxisFormatter = new DayAxisValueFormatter(mChart);
XAxis xAxis = mChart .getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setTypeface(typeFace);
xAxis.setDrawGridLines(false);
xAxis.setGranularity(1f); // only intervals of 1 day
xAxis.setValueFormatter(xAxisFormatter);
AxisValueFormatter yAxis = new YAxisValueFormatter("duration");
YAxis leftAxis = mChart .getAxisLeft();
leftAxis.setTypeface(typeFace);
leftAxis.setSpaceTop(30f);
leftAxis.setSpaceBottom(30f);
leftAxis.setDrawGridLines(false);
leftAxis.setValueFormatter(yAxis);
leftAxis.setDrawZeroLine(false);
YAxis rightAxis = mChart .getAxisRight();
rightAxis.setTypeface(typeFace);
rightAxis.setSpaceTop(30f);
rightAxis.setSpaceBottom(30f);
rightAxis.setDrawGridLines(false);
rightAxis.setValueFormatter(yAxis);
rightAxis.setDrawZeroLine(false);
populateData();
}
#Philipp Jahoda
Use setAxisMinValue() and setAxisMaxValue() to customize the axis range:
xAxis.setAxisMinValue(valueBelowActualMinimum);
xAxis.setAxisMaxValue(valueAboveActualMaximum);
and modify the DayAxisValueFormatter to show or suppress labels for the edge values.
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);
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);
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.