Achartengine: scolling and re-draw Pan. How can I do? - android

I'm using achartengine and I show a ghraph where on the x axis are putted the last 30 days starting by the current date and on the y axis some values from 15 to 0. In my code I used
for(int i=0; i<= array of value to be inserted i++){
.....
aRenderer.addXTextLabel(//value I want is showd on x axis);
.....
}
aRenderer.setXAxisMin(dateMin);
aRenderer.setXAxisMax(adateMax);
aRenderer.setXLabels(0);
Now given that I customized my x labels, when I scroll on the right and on the left, the other labesl don't appeare. So I thought of create a new class that implements PanLinstener and in the panApplied() redraw the labels when I scroll the panel.
Someone has a better idea to to this?
This is what I obtain when I scroll to left from right:

I opted for implementing a PanLinstener, re-drawing the graphs in the panApplied() method.

Under the panApplied() method you will have to rebuild the custom labels.
You will probably need to know the X axis range: renderer.getXAxixMin() and renderer.getXAxisMax() and add new custom labels between this interval.

Related

MPAndroidChart centre view on middle of chart

I am using the MPAndroidChart library to graph live sensor data in a line graph. I'm hoping to give the data a sort of 'buffer' on the right-hand end so that new data is in the centre of the screen. I've tried to illustrate what I mean below:
Basically, I have got it so the ViewPort scrolls and shows the most recent item in the right-most end of the screen, but I would like it in the centre. Thanks!
you need to set Xaxis maximum, set visibleXrange and last move the viewport
double range = 5; // how many data you want to show in view port
double maxX = 100; // your highest X value
chartView.getXAxis().setAxisMaximum(maxX + range/2);
chartView.setVisibleXRange(range, range);
chartView.moveViewToX(maxX);
chartView.notifyDataSetChanged();

MPAndroidChart: How to create dual axis?

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

MPAndroidChart Scatterchart in ListView

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();

How to stop scrolling of AChartEngine dynamic line graph along the y-axis?

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.

How to space out labels on Y-Axis aChartEngine Android

Good day, i have a slight issue. i have created my own Labels on the Y-Axis with the following code below, but they are so clustered together, How can i space them out?.
Here is my code:
renderer.setYLabels(0);
//value_value is an array which would use as the labels for the y axis
int value_size = value_value.length;
int m = 0;
//int add = value_size/10;
int add = largest_size/10; // largest_size is the biggest value in the array value_value
for(int i=0; i< 10; i++){
if(m > value_value.length){
break;
}
renderer.addYTextLabel((double)i, value_value[m].toString(), 1);
m+=add;
}
P.S: from the api docs, there is a 3rd parameter "int scale" which i thought would help me space out the margins but i never seem to use it correctly. if i put any value there, i get a NullPointerException. What does it really do and how to use it?
Any help will be highly appreciated. Thank you.
My Graph:
Adding custom labels can be tricky because you always have to make sure you are not overlapping them. You should add only as many as needed to avoid overlapping. You can also listen for pan and zoom events and update the custom labels accordingly.
The scale parameter is useful when you have multiple Y axis scales. If you don't have then you don't need to use the parameter.

Categories

Resources