Achartengine X labels with uneven interval of time - android

I am using TimeChartView of AChartEngine 0.7.0 to draw chart.
on x-axis there is date and for y-axis there is value for specific date.
i am parsing these values from xml so someday I get value of complete last 5 day but someday only of 3 days so when i get value of 3 days, chart shows x-values shifted compared to y-values. also sometimes there is repetition of date due to fix number of x-labels which i have solved.
I think i have similar problem to this SO Quest and mostly to this as I want to set X-intervals by using dates.
Here Originally from XML,I am having values of date 28.09,27.09,26.09 but it displays as above.

When the number of (x,y) values are changed suppose from 5 to 3 or vice versa you should first remove the values that repaint the chart
public XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
dataset.getSeriesAt(0).clear(); // use this to clear your data set
dataset.getSeriesAt(0).add(x, y) // use this to add the new x,y values

Related

How to set start index for XAxis?

I want to display LineChart with values associated with time.
Currently X index for Entries is it's time presentation in minutes for the day (like for value (11.04,14:30) it's X index is 870).
Difference in times in one chart could be small, so i want to set the start position for left side of XAxis - so for first entry with 14:30 time the start position for XAxis could be 14:00 (840 index).
I've tried to do this with moveViewToX(840) accompanied with i.e. setVisibleXRangeMaximum(6*30); , but XAxis starts from 0 as without that call.
I can modify each Entry's xvalues (i.e. subtract from it's x-value the value of current 'start time') and then use XValueFormatter to display index label properly, but i hope there is another, more handy way. With dynamic data adding it could be not so simple task..
It seems that i haven't read wiki well
Please note that all methods modifying the viewport need to be called on the Chart after setting data.
setVisibleXRangeMaximum begin to work when I call it after adding Entries to the chart. At first try it was called right after adding only XValues.

MPAndroidChart LineChart for a month with only data for beginning of the month

I want to build a month by month line chart with MPAndroidChart. I would like each chart to have a width set to the number of days in the month. For simplicity let's say each month is 30 days.
The problem I am encountering is in the first few days of the month I may only have a few data points. So the graph is two, three, or four days wide since that is how many data points I have for that month. I could fill in the rest of the month with 0 values but then I would end up with 0 value entries on the line chart that are in the future. It would look strange and might be confusing to users.
Is there a way to set the x-axis to 30 units while only having < 30 units of data? That way the data in the graph will fill in as the current month progresses.
Something like:
XAxis xaxis = chart.getXAxis();
xaxis.setAvoidFirstLastClipping(true);
xaxis.setMinValue(1);
xaxis.setMaxValue(30);
xaxis.setIncrement(1);
The last three do not appear in the API. Is there some other way?
New with MPAndroidChart and any insights much appreciated.
You can use setAxisMaxValue and setAxisMinValue which is
available in com.github.PhilJay:MPAndroidChart:v3.0.1
For example,
XAxis xaxis = chart.getXAxis();
xaxis.setAxisMaxValue(30f);
xaxis.setAxisMinValue(0f);
And also you can use xaxis.mAxisRange.
Yes, all you need to do is provide a long enough x-values array for the chart.
You want 30 days? Make your x-values array 30 entries long.

Android Graph with irregular X axis values

I have tried to see if I can do this on AndroidPlot, HelloCharts and MPAndroidChart.
I have a Weight Management App and want to show a chart of how weight has changed over time.
I've just started looking at this and am falling at the first hurdle of plotting irregular intervals on the X axis. All of the examples for all of these seem to show linear plotting with every interval on the X axis having a value plotted.
But my users might weigh themselves everyday for a week and then wait a month before the next weight so there should be a linear date scale and weights mapped against it but with many days not having a value to plot.
Am i missing something obvious or is this something that these libraries just don't do and I will have to look at building it from scratch?
What you could do is simply fill your x-values array with all days up to the current day, beginning from the first day the person weighed himself. (this will support one weight entry per day - if a person weighs himself more often than once a day, you can simply take the e.g. highest value and display it in the chart, and only show the others upon clicking the chart entry)
ArrayList<String> xvals = new ArrayList<String>();
for(int i = startingday; i < currentday; i+= oneday) {
xvals.add(daystring);
}
Each entry in this x-values array will represent one day, in indices from 0 to the last day.
If you want to add the weight measurement for the first day, create a new Entry with x-index 0 and the weight value. If you want to add the weight measurement for the 10th day, add a new Entry with x-index 10 and the weight value.

How can i customize the layout and position of X axis when drawing a graph using achartengine

I want to construct a graph using achartengine library showing some values corresponding to date/time.
The date axis(behaving as X axis) should be present on the top.
Also i want to customize the layout of X axis.
I want to show the date on X axis above and for each date there are certain time intervals.
Example : I want to plot the readings every 4 hours every day . I want to distinguish the readings day wise as well as hour interval wise.
I hope I am clear.
Can somebody please help me in achieving this ?
Thanks !

Issues faced while drawing dynamic line graph using AChartEngine in Android

How to stop scrolling of AChartEngine dynamic line graph along the y-axis?
When I dynamically plot values I wish to display the recent plotted value. How to do that?
I wish to plot y- axis values in range 20 to 200 and want to display only 5 values so I have used mRenderer.setYLabels(5); But, when I do so grid lines are displayed for only those values. And user will not be able to know the exact y axis co-ordinate. How to show grid lines for each value and show labels for only some values?
If I manually scroll graph horizontally towards right or left, x-axis labels change. I set range as 0-10 with setXLables(2); but it changes to 0,5,10… How to control this behavior?
These should be 4 separate questions, not numbered ones. So, I will only answer the first one of them:
You can set the min and max displayed values:
renderer.setXAxisMin(minValue);
renderer.setXAxisMax(maxValue);
If by scrolling you mean panning, then this is the way to do:
renderer.setPanEnabled(false, false);
renderer.setZoomEnabled(false, false);

Categories

Resources