I am making line chart using achartengine. I draw real time graph and values are updating with interval of 10 second. my Y axis is changing the scale which I do not want as my value will always from 10 to 180 so I want to have fixed y axis always. I am trying to make it work using this
renderer.setYAxisMin(10, 1);
renderer.setYAxisMax(180, 1);
In addition I want to reduce the space of my x -axis and screen bottom and border too.
Thanks
AchartEngine provides you api to set the range for Y axis and it is correct just you have to use it like this,
renderer.setYAxisMin(-125, 1);
renderer.setYAxisMax(-10, 1);
It is minor issue but takes time to recognize, I spent 15-30 mins to figure it out.
I hope I am not late
Related
I use MPAndroidChart to check the graph of the polonomial equation.
I want to get the maximum and minimum values in the graph obtained, but grid line of y axis(left axis) like this.Current Chart
Unlike the above figure, I would like to draw the y grid line of the graph as follows.The chart I want to get
Is there any way to display grid line of max and min value?
I tried to solve it using the setValueFormatter function, but I do not know how to approach it.
https://weeklycoding.com/mpandroidchart-documentation/axis-general/
You can use setShowOnlyMinMax(boolean enabled)
That is used to showing min / max label
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 am using the MPAndroidChart library.
I have multiple scattercharts in a ListView.
Every chart contains 365 xvalues (every day of the year).
The yvalues vary from 1 to 5.
The height of the charts is 150dp.
I would like to be able to zoom in, so I can see every single day.
But when I zoom in, the yvalues get out of range of the chart.
Is there a way to keep the yvalues within range of the chart?
I tried it with the next settings:
holder.chart.setTouchEnabled(true);
holder.chart.setDragEnabled(true);
holder.chart.setScaleEnabled(false);
holder.chart.setScaleMinima(3f, 0f);
holder.chart.centerViewPort(xIndex, 3);
But when I drag from left to right or right to left, values just disappear from the chart, even when in range.
Has anyone any idea how to accomplish this?
This is your issue:
holder.chart.setScaleMinima(3f, 0f);
You are setting the scale value of the y-axis to zero. By doing that, you practically zoom out the chart into infinity. If you do not want to manipulate the zoom/scale of the y-axis, set the y-scale to 1f. Like this:
holder.chart.setScaleMinima(3f, 1f);
Try to invalidate the chart after centerViewPort, worked for me.
holder.chart.invalidate();
I have set min max range for y-axis values but graph can scroll beyond those values which hampers the look and feel of graph. I wish to control/stop scrolling of graph along the y-axis. How can I do that?
What you need is specify which axis panning is available for: mRenderer.setPanEnabled(boolean enabledX, boolean enabledY)
Click here for more
use the following for locking both x and y axis scrolling, based on our need boolean values can be specified
render.setPanEnabled(false, false);
use setPanLimits method.
mRenderer.setPanLimits(new double[]{0,10,0,5});
this code will disable panning beyond 0 to the left,10 to the right on X axis,and beyond 0 down and 5 up on Y axis.