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
Related
I am using the GraphView library for drawing graphs in an Android app and I am very pleased with the library so far. I am using it in a fixed frame realtime scenario and have noticed that the x-axis and y-axis grid lines are thicker thatn the other unit grid lines. Is there any way I can make them similar to the other lines?
GraphView graph = (GraphView) cardView.findViewById(R.id.graph);
// Set manual X bounds
graph.getViewport().setXAxisBoundsManual(true);
graph.getViewport().setMinX(0);
graph.getViewport().setMaxX(40);
// Set manual Y bounds
graph.getViewport().setYAxisBoundsManual(true);
graph.getViewport().setMinY(-40);
graph.getViewport().setMaxY(60);
// Draw a border between between labels and viewport
graph.getViewport().setDrawBorder(false);
graph.getGridLabelRenderer().setHumanRounding(false);
graph.getGridLabelRenderer().setNumHorizontalLabels(11);
graph.getGridLabelRenderer().setNumVerticalLabels(6);
Basically I would like to change this:
to this:
Thanks in advance!
There is a setHighlightZeroLines method for the GridLabelRenderer class that is true by default. Code something like:
graphView.getGridLabelRenderer().setHighlightZeroLines(false);
should do what you want.
Please find Line Graph Series in detail:
Line Graph Series in detail
// styling series
series.setTitle("Random Curve 1");
series.setColor(Color.GREEN);
series.setDrawDataPoints(true);
series.setDataPointsRadius(10);
series.setThickness(8);
// custom paint to make a dotted line
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(10);
paint.setPathEffect(new DashPathEffect(new float[]{8, 5}, 0));
series2.setCustomPaint(paint);
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);
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);