So I'm using MPAndroidChart to draw a linechart using data from a Firebase Real-time Database.
This is how it shows:
The first point is 2100 and the rest of the points are around 5-6, but because is not scaled, it shows them at 0. How can I scale the chart to show them correctly or can I plot the last 10 points?
From what you write, I understand that all the points are displayed correctly, but the chart is not very useful because of the outlier. You could zoom in to the lower part of the chart, e.g.:
chart.zoom(1f, 10f, 0f, 0f)
This zooms in by a factor of 10 on the Y axis and leaves the X axis as is.
Another solution would be a logarithmic scale, but this seems not to be supported by MpAndroidChart.
Related
I am using MPAndroidChart for drawing line chart.
I need to draw a Dual YAxis Line chart (i.e. with 2 Y Axis, one on left and other on right). But when I draw the graph it is being drawn from left. It takes into consideration the Left YAxis values rather than the Right YAxis values.
I am drawing Weights(kg) on right side and Heights(ft) on the left side.
As weights will be in terms of 40s, 50s etc and heights in terms of 5, 6 etc... The Line being drawn for Height takes left reference, which has 50s, 60s and hence never comes up.
Please let me know how to direct to draw considering the right Y Axis for Height rather than left Y Axis.
You can just use the setAxisDependency function in order to let a DataSet depend on a given axis. In your case it should be set to right:
LineDataSet set = new LineDataSet(data, "Your Label");
set.setAxisDependency(YAxis.AxisDependency.RIGHT); // plot this set against the right axis
I am using MPAndroidChart library.
I'm trying to make spaces between labels in the XAxis of my line chart.
I have tried this but nothing changes:
xAxis.setSpaceBetweenLabels(someInt);
A bit late, but you can increase the zoom level using zoom(scaleX, scaleY, x, y) method. Increase the scaleX value and you will start seeing spaces between labels on the x axis. A good estimation is dividing the number of labels by 10. So if you have 500 labels, use zoom(50f, 0.5f, 1f, 1f).
xAxis.labelCount = 3
//replace the integer with whatever you need
You can use xAxis.setLabelCount(some int);
or
chart.setVisibleXRangeMaximum(some float);
which sets the size of the area (range on the x-axis) that should be minimum visible at once.
You can read it also in the documentation
https://github.com/PhilJay/MPAndroidChart/wiki/The-Axis
and for the View Port https://github.com/PhilJay/MPAndroidChart/wiki/Modifying-the-Viewport
I have the whole line chart working. However the fonts are really small for the labels in x axis and y axis and also on the points where it is plotted. I've circled them in the picture in order to let you know what labels I am talking about.
Also I have disabled the zoom buttons, however we can still zoom using our fingers on the screen. When I zoom in the chart gets messed up. How do I not allow any kind of zooming?
You can set labels size in pixels for 2 axis together
renderer.setLabelsTextSize(float textSize)
Also you can set label color, align gor X and Y axis, for example:
renderer.setXLabelsColor(Color color);
renderer.setYLabelsAlign(Paint.Align.RIGHT);
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 am developing a new game for Android. In this I am using Android OpenGL ES
1.1. In this when I translate in Z axis to -2, the triangle moves backwards. Now when I translate in X axis and Y axis the triangle is visible till a limit of say -1.4 to 1.4 in Y axis and -0.8 to 0.8 in X axis.
Now If I move further down say about -4 in Z axis, I can move the triangle in
Y-axis to say about from -1.9 to 1.9 and X- axis from -1.2 to 1.2. The numbers provided are only approximate values. The point is that when I move back wards in Z axis, I am able to move triangle for a longer range in X and Y axis. This keeps increasing as I move backwards.
Now I would like to know calculate this visible range for a given value of Z. I mean If I know the Z value to be as -3 I would like to calculate in code what is the visible range of triangle to which i can translate in X and Y axis. I right now do it manually by trying trial and error with different values. Please let me know how to calculate it in code. Thank you very much in advance for your time and help.
This greatly depends on what matrices you put the triangle through, or you have loaded into opengl. Last time I checked, by default, the clip coordinates for opengl was -1 to 1 in the x, y, and z axis.