Id like to achive someting like this where more negative values appear below less negative. Is it possible for bars to start in other place than 0.
chart.getAxisLeft().setInverted(true);
does not do what i want.
How it should look
You can control the span of Y axis by two functions from AxisBase:
public void setAxisMinimum(float min)
public void setAxisMaximum(float max)
Just iterate through values, choose minimum and maximum values and set Y axis min and max values:
In the case of provided example:
mChart.getAxisLeft().setAxisMinimum(-112f);
mChart.getAxisLeft().setAxisMaximum(-12f);
Related
I am trying to show a min max values in a MP graph, so I have drawn a circles in a line graph. I want to show a Text as Min and Max at that point. How should I achieve it in android.
As shown in image above, I have two circles in the graph, These circles are the min and max value in a chart. But I also want a text with these circles as "Min" and "Max" in the graph
Take a look at this documentation to get an idea how to implement this feature on the YAxis.
Always 0 as min value use setStartAtZero(boolean enabled):
If the boolean is enabled, the axis will always have it's minimum value at zero, no matter which kind of data the chart displays.
Max and Min in value:
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.
Max and Min in percent:
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.
I am using MPAndroidChart to show a bargraph in my Android application. My Y axis values range is in between 0 and 30. I need to show Y axis labels from 0 to 5 always on viewport if Y axis values below 5. If exceeds 5, auto adjust the labels and show as usual. Any way to achieve this.
I need suggestion on how to limit the MpAndroid CandleStick chart combined with volume bar chart at the bottom so that volume bar max height can be limit to below 1/3 of chart area Yaxis . From the chart attached , this is somewhere Y Max at 3million region viewport in the left Axis. The current combined chart is ruin by the volume bar chart.
Thanks
setVisibleXRangeMaximum(float maxXRange): Sets the size of the area (range on the x-axis) that should be maximum visible at once. If this is e.g. set to 10, no more than 10 values on the x-axis can be viewed at once without scrolling.
setVisibleXRangeMinimum(float minXRange): Sets the size of the area (range on the x-axis) that should be minimum visible at once. If this is e.g. set to 10, it is not possible to zoom in further than 10 values on the x-axis.
setVisibleYRangeMaximum(float maxYRange, AxisDependency axis): Sets the size of the area (range on the y-axis) that should be maximum visible at once. You also need to provide the axis this constraint should apply to.
For more info Refer this
Thanks for your comment ,I do not think setting XrangeMax or Min will help , it only limit the x-axis down to certain visible display range instead of showing the full range of the dataset points . The chart shown above has about more than 4000 data points , I have narrowed the visible x-range using set chart.setVisibleXRangeMaximum(100) and also chart.moveViewToX(3000) to optimise performance. What I need is some functional procedure to set the max Y-axis (eg left Y-axis) at certain specific offset position , so that the lower portion of the chart could be restricted to the volume bar chart by clipping the specific rectangle viewports. I am not sure if that is possible , narrowing the YVsibleYrange is not what I have in mind. What I would like to have is
That is possible. All you need to do is plot the data against two different axes (as you are already doing), and then set the top space for each axis separately.
Customizing the axis range
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.
More information in the documentation.
To workaround , I have coded the Y axis to be at 1/x1 of Y viewport height to mark the volume bar top at YMAX in the multiple of x1 where x1 variable can be ={3, 4 or 5} float ymax=barDataSet.getYMax(); float ymaxd=(float)Math.floor (ymax*x1); leftAxis.setLabelCount(x1,false); leftAxis.setAxisMaxValue(ymaxd);
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);
How do I know what margins to use in an AChartEngine chart to prevent the y-axis labels from being displayed outside the chart when it is set to fill a layout? Can I automatically resize the chart so that the y-axis labels always are visible, even if they contain more than 2-3 digits?
/Markus
You cannot do this automatically, but you can tweak the values until it looks good. You can also rotate the labels when you have several digits values.
This is what I used to deal with Y axis labels that can have differing numbers of digits. Find your max Y value, round it to an int, convert to string and then count the length of the string. The length of the string can be used to calculate a value for the Left margin.
//**** Find max y value of dataset
Ymax = getMaxValue(U_Limit);
if(Ymax < 10){
Ymax = 10;
}else{
Ymax = Ymax*1.1;
}
//**** Find int value of number of digits in max y value
int PLAY_FACTOR = text_label_size*.5 // you may have to play around with this value
int leftMargin = (Double.toString(Math.round(Ymax)).length())*PLAY_FACTOR;
int margins[] = { 26, leftMargin, botMargin, 14 }; // Top,Left,Bottom,Right
renderer.setMargins(margins);
Found a better solution, if you use setYLabelsVerticalPadding with a negative value you can move a little bit down the label... in this way the upper Y label will be visible no matter what.
Hope it helps.