I want to set a label in the x-axis for every y-value I have in my LineChart. I want to obtain this result:
Can someone help me in finding the correct way of doing this in MPAndroidChart?
You may be looking for granularity - see the wiki page for the axis and the javadoc.
Calling like this:
mChart.getXAxis().setGranularity(0.3f);
mChart.getXAxis().setGranularityEnabled(true);
will ensure that 0.3 is the minimum interval on the axis when you are zoomed in. Apart from that you may have to tweak the the scale of the x-axis by calling:
mChart.getXAxis().setAxisMinValue(10.01f); //experiment with these values
mChart.getXAxis().setAxisMaxValue(10.14f);
mChart.getXAxis().setLabelCount(5);
I use combined chart which combines line (RED) and scatter charts. However for some reason scatter chart points are cropped at the edge of chart here is example:
Is there any way to prevent it?
here is my chart code:
chart.getAxisLeft().setAxisMaxValue(1.1f);
chart.getLegend().setEnabled(false);
chart.setTouchEnabled(false);
chart.setDragEnabled(false);
chart.setScaleEnabled(false);
chart.setPinchZoom(false);
chart.setDoubleTapToZoomEnabled(false);
chart.setHighlightPerDragEnabled(false);
chart.setHighlightPerTapEnabled(false);
chart.getAxisRight().setEnabled(false);
chart.getAxisLeft().setEnabled(false);
chart.getXAxis().setEnabled(false);
chart.setDescription("");
chart.setNoDataText("");
and my scatter data set:
foodDataSet = new ScatterDataSet(foodEntries, "Food");
foodDataSet.setColor(ContextCompat.getColor(getContext(), R.color.green_main));
foodDataSet.setScatterShape(ScatterChart.ScatterShape.CIRCLE);
foodDataSet.setScatterShapeSize(10f);
foodDataSet.setDrawValues(false);
foodDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
Update
here is chart with axis
After some tries I was able to find hack to solve issue. However it would be good if proper solution could be advised. Current solution
chart.setData(data);
chart.getXAxis().setAxisMinValue(-0.1f);
chart.setVisibleXRangeMinimum(xAxisLabels.size() - 0.81f);
chart.invalidate();
Min value should be increased if bigger data points are used, but it will require update min visible x range too. Reduce subtraction value to increase offset.
Disadvantage of such solution is it doesn't scale well
If anyone else is having this problem, here's what I did to make mine scale with the number of entries. This assumes that the number of entries is the same for each data set which may or may not be the case for your specific data.
float xAxisSideOffset = (float)(xMax - xMin) / (data.getEntryCount()/data.getDataSetCount());
combinedChart.getXAxis().setAxisMinimum(xMin - timeInterval - xAxisSideOffset/2);
combinedChart.getXAxis().setAxisMaximum(xMax - timeInterval + xAxisSideOffset/2);
I use MPAndroidChart to display the stock chart, but the Y line value is so close,the chart is like this
I can use finger zoom like this way
Which is I want the default looks like
Is there any way to set Y line max and min value or set default zoom.
I tried the lib function , but it does not work
Take a look at the documentation of the YAxis. There are various methods that allow you to control the axis range.
setStartAtZero(boolean enabled): If this is enabled, this axis will always have it's minimum value at zero (0), no matter which kind of data the chart displays.
setAxisMaxValue(float max): Set a custom maximum value for this axis. If set, this value will not be calculated automatically depending on the provided data.
setAxisMinValue(float min): Set a custom minimum value for this axis. If set, this value will not be calculated automatically depending on the provided data.
setSpaceTop(float percent): Sets 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.
setSpaceBottom(float percent): Sets the bottom spacing (in percent of the total axis-range) of the lowest value in the chart in comparison to the lowest value on the axis.
There is a kind of dependency between left and right axises. I had only right axis enabled and set
chart.getAxisRight().setStartAtZero(false);
but that didn't work till I set the same parameter to my leftYAxis, which was disabled. So I have now
chart.getAxisLeft().setStartAtZero(false);
chart.getAxisRight().setStartAtZero(false);
edit:
setStartAtZero is deprecated, the code recommends using setAxisMinimum instead.
* This method is deprecated.
* Use setAxisMinimum(...) / setAxisMaximum(...) instead.
You can find more on that in the documentation.
You can also use the
mChart.setVisibleYRangeMaximum(150, AxisDependency.LEFT);
method to set highest visible value on y axis.
use setScaleMinima()
and chart.moveViewToY(max), YAxis.AxisDependency.LEFT);
is the best solution.
please try this , i am not sure that what your want.when i face minim zoom level in MPAndroidChart i used this method like this,
mChart.setPinchZoom(true);
mChart.setScaleMinima(200,200); //for min and max value for zoom
i
Hope to be ok for your problem
None of the other answers worked for me (I'm not sure why). However, I made it work using:
ratingTracker.getAxisLeft().mAxisMaximum = max;
ratingTracker.getAxisLeft().mAxisMinimum = min;
Hope this works for you!
Mp Android Line chart in this fix the Y-Axis Minimum and maximum value so your graph line value start middle of the graph chart.
use this function so your problem will solve
yAxis.setAxisMinimum();
yAxis.setAxisMaximum();
in this code you can put any value you want and your graph Y-axis line
Minimum and Maximum value
Try below line of code :
YAxis yAxis = chart.getAxisLeft();
yAxis.setEnabled(false);
yAxis.setAxisMinimum(-400);
yAxis.setAxisMaximum(400);
I'm passing Androidplot a series with x-values ranging from 0 to 100, but I only want to display the range from 90 to 100. How can I accomplish this?
The graph is redrawn with new data every second. My plan is to call some command before redraw() that sets the x-axis range as I want it.
Use setDomainBoundaries:
setDomainBoundaries(90, 100, BoundaryMode.FIXED );
I have a seekbar, and would like to take the progress (0 - 100) and convert it to -100 to +100. I am not too good at coming up with formulas like this, so I was hoping I could get some thoughts on a formula to do this.
If setting default min and max values are possible I don't want to do that because the seekbar min and max values could change so doing math is better idea IMO.
Thanks for the help!
You need to rescale from a width of 100 to 200 first, then set your basis to -100. So your function would be something like f(x) = x*2 - 100