I'm trying to hide the bottom labels from the HorizontalBarChart graph (in black border) using MPAndroidChart.
I tried setDrawLabels(false) for XAxis, YAxis left, YAxis right with no success.
What parameter should i change and set to false to hide this line?
It work when i disable the axis right from my horizontal bar chart.
// Right Y Axis
YAxis yr = chart.getAxisRight();
yr.setEnabled(false);
// yr.setDrawGridLines(false);
// yr.setDrawAxisLine(false);
// yr.disableGridDashedLine();
Try:
XAxis xl = chart.getXAxis();
//This will stop the grid lines from being drawn
xl.setDrawGridLines(false);
//This Will stop the labels from being drawn
xl.setDrawLabels(false);
Related
I've got the following line chart using MPAndroidChart:
Print of the first X position
Print of the last X position
I'm using the following method:
chart.setVisibleXRangeMaximum(5)
Which shows only 5 values on the viewport, the rest of them will be shown by scrolling.
I'm also using this method:
chart.setViewPortOffsets(0,25,0,40);
Which removes the left and right offset to make the chart covers whole screen and sets top and bottom offsets to have a space between the container it's placed in.
The problem is that both, first and last position got hidden into the device border. I think if there was a way to set a padding to these individual values, the problem could be fixed.
I tried to use some methods to change the space or offset of the X-axis, but neither of them worked.
I'm trying to create a chart like this where the entire filled dataset covers whole screen, but the first and last values are placed with a padding between the border of the device and the value itself.
The entire code of my chart is down bellow:
LineChart chart = view.findViewById(R.id.chartCalendar);
// Setting up the data
List<Entry> entries = new ArrayList<Entry>();
entries.add(new Entry(1,1200));
.....
// Creating dataset
LineDataSet dataSet = new LineDataSet(entries, "Label"); // add entries to dataset
// Dataset styling
dataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);
dataSet.setDrawFilled(true);
dataSet.setFillColor(ContextCompat.getColor(this.getActivity(), R.color.whiteBlue));
dataSet.setColor(ContextCompat.getColor(this.getActivity(), R.color.darkBlue));
dataSet.setLineWidth(2); // Line border thickness
dataSet.setCircleColor(ContextCompat.getColor(this.getActivity(), R.color.darkBlue)); // Border circle values color
// Setting up LineChart
LineData lineData = new LineData(dataSet);
// Styling chart
chart.setData(lineData);
chart.getAxisLeft().setDrawGridLines(false);
chart.getAxisRight().setDrawGridLines(false);
chart.getXAxis().setDrawGridLines(false);
chart.getXAxis().setAxisMaximum(31);
chart.setVisibleXRangeMaximum(5); // Show maximum 10 before scrolling
chart.getLegend().setEnabled(false);
chart.setDrawBorders(false);// Hide the description
chart.getXAxis().setTextColor(ContextCompat.getColor(this.getActivity(), R.color.white)); // Change X-axis label color
YAxis yAxis = chart.getAxisLeft();
yAxis.setTextColor(ContextCompat.getColor(this.getActivity(), R.color.white)); // change Y-axis label color
yAxis.setAxisLineColor(ContextCompat.getColor(this.getActivity(), R.color.darkBlue));
yAxis.setTextColor(ContextCompat.getColor(this.getActivity(), R.color.white));
// remove axis
YAxis leftAxis = chart.getAxisLeft();
leftAxis.setEnabled(false);
YAxis rightAxis = chart.getAxisRight();
rightAxis.setEnabled(false);
// X axis to bottom
chart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
chart.getLineData().setValueTextColor(ContextCompat.getColor(this.getActivity(), R.color.white)); // Change value color
chart.getXAxis().setGranularity(1);
chart.setViewPortOffsets(0,25,0,40);
chart.getDescription().setEnabled(false);
// Refresh graph
chart.animateX(500);
Do you guys have any idea of how to fix it? Thanks!
To avoid the first and last values from being clipped, use your_chart.xAxis.setAvoidFirstLastClipping(true)
I want the xaxis labels to come down. Those large labels pushes the graph on top where i am not able to view the graph itself as shown in the figure given below. There is lot of space between the xaxis labels and legends(Legends not shown in figure below). I want to overcome this and view the chart. Find my code below
barChart.getAxisLeft().setAxisMinimum(-1.0f);
barChart.getAxisLeft().setDrawGridLines(false);
barChart.getAxisRight().setDrawGridLines(false);
barChart.getAxisRight().setEnabled(false);
barChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
barChart.getXAxis().setDrawGridLines(false);
barChart.getXAxis().setLabelRotationAngle(-90.0f);
barChart.getXAxis().setLabelCount(12);
barChart.getXAxis().setCenterAxisLabels(true);
barChart.getXAxis().setGranularityEnabled(true);
barChart.getXAxis().setValueFormatter(new IndexAxisValueFormatter(xAxisLabelList));
barChart.getXAxis().setAxisMaximum(12f);
barChart.groupBars(1f, 0.5f, 0f);
barChart.invalidate();
You can use barChart.setExtraBottomOffset(-10f); to reduce extra white-space below labels.
And increase your chart height in xml file.
I'm using MpLine chart in my project. My problem is some times top part of y axis is not showing. In my xml I gave fixed height of 75dp to the graph. How can I make the graph to be shown within this height.Any help will appreciated and thanks in advance.
YAxis leftAxis = chart.getAxisLeft();
leftAxis.setAxisMaxValue(1000f); //to set max height place your value in place of 100f
leftAxis.setAxisMinValue(0f); // to set minimum yAxis place
Hope this helps! :)
How can i solve the problem of the values intersecting with the legend while maintaning the same position for the legend, or is it not possible?
Also how can i remove the value from above the bar
I have tried using
mChart.setDrawValueAboveBar(false);
mChart.setDrawValuesForWholeStack(false);
But they are no good
You can increase the space between the largest value and the top of the graph:
YAxis leftAxis = chart.getAxisLeft();
leftAxis.setSpaceTop(40f); // e.g. 40% space
What this does is setting the top spacing (in percent of the total axis-range) of the highest value in the chart in comparison to the highest value on the axis.
As for removing the y-values that are drawn by the bars: https://github.com/PhilJay/MPAndroidChart/wiki/The-ChartData-class
Call setDrawValues(false) on your BarData or BarDataSet object.
I have a simple linechart with MPAndroidChart library:
chart.setDrawYValues(false);
chart.setDescription("");
chart.setDrawVerticalGrid(true);
chart.setDrawGridBackground(false);
XLabels xl = holder.chart.getXLabels();
xl.setCenterXLabelText(true);
xl.setPosition(XLabelPosition.BOTTOM);
YLabels yl = holder.chart.getYLabels();
yl.setLabelCount(5);
// set data
chart.setData((LineData) mChartData);
chart.setDrawYValues(true);
chart.setValueTextSize(20f);
// zooming on both axis
chart.setPinchZoom(true);
chart.animateX(1000);
But I have a visualization problem. Labels on the X axis aren't under the relative grid line, but between the two lines (on Y axis I don't have this problem). Is there a way to put Y labels exactly under the relative grid line?
Calling this:
XLabels xl = chart.getXLabels();
xl.setCenterXLabelText(true);
will cause the labels to be drawn between the lines. If you call setCenterXLabelText(false); the labels should be exactly above the individual grid-lines.
Also check the example project LineChart. There the labels are exactly above the lines.
Update
There is no getXLabels method in version 3.1.0. Use this:
chart.xAxis.setCenterAxisLabels(true)