Android Graph with irregular X axis values - android

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.

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.

AChartEngine dates on X-axis with BarChart or CubeChart

I'm trying to make a chart with dates on x-axis and consumption per time month/day etc. on y-axis.
I have database of actual states of energy meters in specific datetime:
1.1.2014 - 150 kWh
5.1.2014 - 200 kWh
So I can get consumption/time like - 50/5 => 10 kWh/day for time from 1.1. to 5.1.
I guess I need some resolution, for every day for example (better for every hour), and add the value of consumption in every hour from 1.1. to 5.1.. But then I need to have that resolution on x-axis labels, 1,2,3...31 day of month etc. But I want to achieve that on zoom out I would have another resolution, means another labels on x-axis. Months. Like 1,2,3..12 And values of consumption with lower resolution, rounded in specific months.
I really don't know how to do that, if it's even possible?
I would like to achieve X-axis label in zoom (better for hours in higher zoom):
And X-axis labels for zoomed out, like on this graph:
Do I need to make my map of x-axis labels for whole times (where I have data of consumption) and then fill it with counted values somehow?
PS: I want to achieve this X-axis labels with Bar chart or Cubic line (cube) chart.
Thanks for any tips

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 !

Achartengine X labels with uneven interval of time

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

Categories

Resources