MPAndroidChart - how to reduce the amount of entries to display - android

I am using MPAndroidChart to display Linecharts in my Android Application. Some of my Linecharts have a hugh amount of data which I add to a LineDataSet. When I display
the data on the screen, it becomes quite confusing for the user because the dots are so close to each other. So I am looking for a possiblity to display e.g. only every
fith data dot on the chart.
LineDataSet dataSet = new LineDataSet(entries, mViewModel.getMeterUnit().getValue());
dataSet.setColor(Color.RED);
dataSet.setDrawValues(false);
dataSet.setCircleColor(Color.BLACK);
dataSet.setCircleHoleColor(Color.BLACK);
XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setValueFormatter(new LineBarMeasurementFragment.LineChartXAxisValueFormatter());
xAxis.setLabelCount(0);
for (LimitLine l1 : limitLines) {
xAxis.addLimitLine(l1);
}
MinMax mx = getXMinMax(measurementList) ;
xAxis.setAxisMaximum(mx.getxMax());
xAxis.setAxisMinimum(mx.getxMin());
chart.getAxisLeft().setAxisMinimum(getYAxisMin(measurementList));
chart.getAxisRight().setEnabled(false);
chart.getDescription().setText(mViewModel.getMeterIdentifier().getValue());
LineData lineData = new LineData(dataSet);
chart.setData(lineData);
// something like chart.displayOnly(5)
chart.invalidate();

Related

MPAndroidChart show bar for 0 value

I want to show vertical bars for 0 values as well. I have tried setting chart.getAxisLeft().setAxisMinimum(-1);. The axis gets shifted but there is no bars shown for zero value.
BarData barData = new BarData(dataSet);
barData.setValueFormatter(formatter);
barData.setDrawValues(true);
barData.setBarWidth(0.5f);
chart.setDrawGridBackground(false);
chart.setDrawBarShadow(false);
chart.setDrawBorders(false);
chart.animateY(1000);
chart.getAxisLeft().setGranularityEnabled(true);
chart.getAxisLeft().setAxisMaximum(5);
chart.getAxisLeft().setGranularity(1);
chart.getAxisRight().setEnabled(false);
chart.getAxisLeft().setAxisMinimum(-1);
chart.setDescription(null);
chart.getLegend().setEnabled(false);
chart.setDrawValueAboveBar(false);
chart.setRenderer(new RoundedBarChart(chart, chart.getAnimator(), chart.getViewPortHandler()));
XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setAxisLineWidth(1);
xAxis.setDrawGridLines(false);

MPAndroid LineChart - HOW to align XAxis labels with gridlines, display XAxis values

I am new to using the MPAndroid LineChart. I have a simple code and have produced a graph as shown below:
However, on this, I want to do the following:
1) To match the XAxis labels with the vertical grid lines, so that the grid lines also pass through the blue dots; AND
2) To show the XAxis value on the blue dots. By default, the YAxis values can be shown - I know how to do this; currently I have disabled this, and it is not shown in the picture below, but if I were to show enable them, then, they will be 0.0, 2.0, 4.0, 6.0 and 8.0 on the 5 blue dots. What I want is to show the XAxis values instead.
Could you please suggest a way? Many thanks.
I'm not sure. but its work for me.
XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTTOM);
xAxis.setTextSize(10f);
xAxis.setTextColor(Color.RED);
xAxis.setDrawAxisLine(true);
xAxis.setDrawGridLines(false);
For dynamic XAxis label,
xAxis.setValueFormatter(new IndexAxisValueFormatter(getAreaCount));
public ArrayList<String> getAreaCount() {
ArrayList<String> label = new ArrayList<>();
for (int i = 0; i < yourList.size(); i++)
label.add(yourList.get(i).getTopicName());
return label;
}

MPAndroidChart bar chart issues in android

I am using MPAndroidChart.
How to change the BarEntryLabels in to left in HorizontalBarChart?vHow to remove that projects from its bottom?
How to disable zoom ?
While clicking on to particular bar colour is changing how to disable it?
IN BarChart there i have added 6 months but EntryLabels is not properly aligned to corresponding bar.
Code:
BARENTRY = new ArrayList<>();
BarEntryLabels = new ArrayList<String>();
AddValuesToBARENTRY();
AddValuesToBarEntryLabels();
Bardataset = new BarDataSet(BARENTRY, "Projects");
BARDATA = new BarData(BarEntryLabels, Bardataset);
Bardataset.setColors(new int[]{Color.parseColor("#701112")});
horizontalBarChart.setData(BARDATA);
horizontalBarChart.setDrawBarShadow(false);
horizontalBarChart.setDrawValueAboveBar(true);
// if more than 60 entries are displayed in the chart, no values will be
// drawn
horizontalBarChart.setMaxVisibleValueCount(60);
// scaling can now only be done on x- and y-axis separately
horizontalBarChart.setPinchZoom(false);
// draw shadows for each bar that show the maximum value
// mChart.setDrawBarShadow(true);
horizontalBarChart.setDrawGridBackground(false);
horizontalBarChart.setDescription("");
Bardataset.setBarSpacePercent(10f);
barChart.setData(BARDATA);
barChart.setDrawBarShadow(false);
barChart.setDrawValueAboveBar(true);
// if more than 60 entries are displayed in the chart, no values will be
// drawn
barChart.setMaxVisibleValueCount(60);
// scaling can now only be done on x- and y-axis separately
barChart.setPinchZoom(false);
// draw shadows for each bar that show the maximum value
// mChart.setDrawBarShadow(true);
barChart.setDrawGridBackground(false);
barChart.setDescription("");
For the "project" legend part try this
Legend legend = mBarChart.getLegend();
legend.setEnabled(false);
To make touch disable set setTouchEnabled(boolean enabled) on your bar chart object like this
mBarChart.setTouchEnabled(false);
and if you want to show all label you should try
axis.setLabelCount(...)
mBarChart.getXAxis().setValueFormatter(new IndexAxisValueFormatter(labels));
and also try official documents
BARENTRY1 = new ArrayList<>();
BarEntryLabels1 = new ArrayList<String>();
AddValuesToHorizontalBARENTRY();
AddValuesToHorizontalBarEntryLabels();
Bardataset = new BarDataSet(BARENTRY1, "Projects");
BARDATA = new BarData(BarEntryLabels1, Bardataset);
Bardataset.setColors(new int[]{Color.parseColor("#701112")});
horizontalBarChart.setData(BARDATA);
horizontalBarChart.setDrawBarShadow(false);
horizontalBarChart.setDrawValueAboveBar(true);
horizontalBarChart.setPinchZoom(false);
horizontalBarChart.setDrawGridBackground(false);
horizontalBarChart.setDescription("");
Bardataset.setBarSpacePercent(10f);
Legend legend = horizontalBarChart.getLegend();
legend.setEnabled(false);
horizontalBarChart.setTouchEnabled(false);
XAxis xAxis1 = horizontalBarChart.getXAxis();
xAxis1.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis1.setTextSize(8);
xAxis1.setSpaceBetweenLabels(8);
xAxis1.setTextColor(Color.parseColor("#701112"));
xAxis1.setTypeface(tf);
YAxis leftAxis = barChart.getAxisLeft();
leftAxis.setEnabled(false);
Do like this.The following issue will be fix.

MPAndroidChart vertical values

I want to delimit on vertical values between 13 and 14 not this is how it looks my linear chart, always starts on 0 as the starting limit, I want to be something around 13. Please see the image on the next link to see what I am talking about, I am attaching the piece of code for it enter image description here
LineChart lineChart = (LineChart) rootView.findViewById(R.id.chart);
LineData data = new LineData(labels, dataset);
dataset.setColors(ColorTemplate.COLORFUL_COLORS); //
dataset.setDrawCubic(true);
dataset.setDrawFilled(true);
lineChart.setData(data);
lineChart.animateY(5000);
Finally I got the answer about this, you can check it here
LineChart lineChart = (LineChart) rootView.findViewById(R.id.chart);
LineData data = new LineData(labels, dataset);
lineChart.getAxisLeft().setLabelCount(2, true);
lineChart.getAxisRight().setEnabled(false);
lineChart.getAxisLeft().setStartAtZero(false);
lineChart.setAutoScaleMinMaxEnabled(false);
lineChart.getAxisLeft().setAxisMaxValue(maxYval + 1);
lineChart.getAxisLeft().setAxisMinValue(minYval - 1);
dataset.setColors(ColorTemplate.COLORFUL_COLORS); //
dataset.setValueTextSize(10);
dataset.setDrawCubic(true);
dataset.setDrawFilled(true);
lineChart.setData(data);
lineChart.animateY(10);

MPAndroidChart - BarChart on xaxis geting postion instead of values

I was trying MPAndroidChart for a basic bar chart. I am facing issue with Xaxis.
Here is my code to set Xaxis :
protected List weeks =new ArrayList() ;
weeks.add("jan");
weeks.add("feb");
weeks.add("mar");
weeks.add("apr");
weeks.add("may");
weeks.add("jun");
XAxis xAxis = mChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setDrawAxisLine(true);
xAxis.setDrawGridLines(false);
xAxis.setTextColor(Color.WHITE);
xAxis.setValues(weeks);
But in xaxis I am geting postion i.e. 0 , 1, 2, 3, 4, 5 instead of months name.
Thanks
You should provide the x-axis labels for the data object you are using and not set them directly to the axis.
E.g.
LineData data = new LineData(xValues, dataSets);
For more details, read the documentation.

Categories

Resources