I'm drawing a bubble chart using MPAndroidChart, and want to hide the bubble size value. How do I do that?
How do I hide the "5' and "66.8"?
It can be done by using bubbleDataSet.setDrawValues(false);
Code:
BubbleDataSet set1 = new BubbleDataSet(yVals1, "DS 1");
set1.setColor(ColorTemplate.COLORFUL_COLORS[0], 130);
set1.setDrawValues(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 am using MPAndroidChart for drawing a bar chart.
How can I draw border around each bar in the graph that is displayed?
This is not possible by default.
You will have to modify the library, specifically the BarChartRenderer class.
Simply take the RectF object that represents the bar that is to be drawn and draw it once again over the original bar whilst changing the Paint mode to STROKE instead of FILL.
Of course you will also have to change the Paint color to distinguish the border from the bar.
So, after a rigorous searching and checking the Demo App the Library Developer used to demonstrate the Library functionalities, I got this.
BarChart barChart = new BarChart();
BarData barData = new BarData(barDataSet);
//set the appropriate properties of object **barData**
//then set the data property of the chart
barChart.setData(barData);
.
.
.
.
//add border to chart bars
for (IBarDataSet set : barChart.getData().getDataSets())
((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);
.
.
.
//set up other properties as well
Intent
barData.sliceSpace = 2f
and for mas styling
eneficioChar.holeRadius = 1f
val set1 = BarDataSet(entries,seriesLabel)
set1.color = Color.YELLOW
set1.barBorderWidth = 1f
set1.barBorderColor=Color.RED
I am working on designing a Line chart using the MPAndroidChart library. in that chart, the "points labels" should be removed or suppressed, and once we click that point circle the marker should be displayed. However, right now it displays the point labels on each point circle, so what I need is to show the point in the marker only once it is clicked. Also, while I've tried to customize the chart the Y-axis points are displayed as float; I have tried to display them as int but that won't work.
How can I fix this?
I found the answer at last. We have to add set1.setDrawValues(false); in LineDataSet value properties. This will make the changes, as the points are not displayed.
LineDataSet set1 = new LineDataSet(yVals1, "");
set1.setDrawValues(false);
ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>();
dataSets.add(set1); // add the datasets
If you want to keep the value but remove the Label (as it may already exist in the legend) the do mChart.setDrawEntryLabels(false);
i use this it worked for me
dataSet.setValueFormatter(new DefaultAxisValueFormatter(0));
or
dataSet.setValueFormatter(new DefaultValueFormatter(0));
hope this help you
Set the value of the text size to 0f, and this would accomplish what you wanted
set1.setValueTextSize(0f);
I am using MPAndroidChart library.
I would like modify the size of bar present in bar chart. Could you let us know where to check for modify size of bar in bar chart in mp android chart
You can reduce the spacing between the bars that will automatically increase the width of bars.
BarDataSet set = new BarDataSet(vals, "Set A");
set.setBarSpacePercent(50f);
UPDATE v3.0.0:
As of this library version, you can control the bar width with the following method:
BarData barData = new BarData(...);
barData.setBarWidth(1f);
The number you provide for this method represents a certain interval on the x-axis. If your total axis has a range of e.g. 10k, and you set the bar width to 1000, the bar will cover 10% of the total x-axis range.
As for the latest version of the library BarDataSet does not have this function any longer, its in BarData class.
BarData data = new BarData(dataset);
data.setBarWidth(0.5f);
Kotlin:
barChartView.data = BarData(dataSetList).apply {
barWidth = 0.5f
}
To fit data in graph (No scroll behavior)
barChartView.xAxis.axisMaximum = dataList.size
barChartView.setVisibleXRange(1f,xAxisLabels.size.toFloat())
This applies to MPAndroidChart API. To reduce the Bar width you have to increase space between bars (as mentioned Rakesh). The value 50F should be good for mobile display but you can increase/decrease it to suit your device screen.
Sample code as requested by one user :
BarDataSet barDataSet = new BarDataSet(group1, "X");
barDataSet.setColors(ColorTemplate.COLORFUL_COLORS);
barDataSet.setBarSpacePercent(50f);
The API imports are-
import com.github.mikephil.charting.data.BarDataSet;
data.barWidth = 0.5f
it means barWidth/(barWidth + blankWith) = 0.5f
I want to create pie chart with some values . I created pie chart like this
Now i want to change label text color and reduce gap/space between pie and legend. How can i do this? Can anybody help me to resolve this? Thanks in advance.
You can change the labels color this way:
renderer.setLabelsColor(Color.BLUE);
You can make the pie chart bigger which would get it closer to the legend this way:
renderer.setScale(1.25f);
change the following things:=
// set up gradient paints for series...
GradientColor gp0 = new GradientColor(Color.YELLOW, Color.rgb(2, 2, 64));
GradientColor gp1 = new GradientColor(Color.WHITE, Color.rgb(0, 64, 0));
GradientColor gp2 = new GradientColor(Color.YELLOW, Color.rgb(64, 0, 0));
renderer.setSeriesPaintType(0, gp0);
renderer.setSeriesPaintType(1, gp1);
renderer.setSeriesPaintType(2, gp2);