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.
Related
I'm using MPAndroid chart to display a line chart.
The chart is updated with different data and of course, when the data changes, the y-axis lines and the zoom level is changed because of the different sets of input data.
Is there any way to maintain the position of the y-axis lines and only change their labels according to the new data?
Thanks!
After a lot of tries and investigations, it seems that I found a solution just after posting the question.
Just in case someone else needs this, I used the setLabelCount function before but never the one with the force parameter.
The solution is:
mChart.getAxisLeft().setLabelCount(visibleYCount, true);
Forcing the label count will assure the number of y-axis lines and thus, their position is stable with different data sets.
I am making an app which retrieves data from a database and shows it on a barchart. I have defined a limit line using the provided methods at 30f (on the Y axis).
The problem is, that I want that limit line to be always shown and it only becomes visible when one of the Graph's Bars raises above that value (30f).
Is there a way to always show it?
I have tried with the zoom functions with no luck.
Modify the YAxis display range to your needs: https://github.com/PhilJay/MPAndroidChart/wiki/YAxis-(YLabels)
Especially those methods should help:
setAxisMaxValue(float max): Set a custom maximum value for this axis. If set, this value will not be calculated automatically depending on the provided data.
setAxisMinValue(float min): Set a custom minimum value for this axis. If set, this value will not be calculated automatically depending on the provided data.
SOLUTION
Instead of using setInitialRange() I had to set the initial x-values using setXAxisMin() as well as setXAxisMax(). A little bit confusing, I think.
ORIGINAL QUESTION
I'm currently working on a project involving the acharteninge library for drawing time diagrams which works excellent so far. The user is capable of switching between various graphs (one XYMultipleSeriesDataset plus one TimeSeries per graph) via separate buttons. So far, achartengine displays all x values when the graph is shown.
However, I was asked to display only the data captured in the first three hours when the graph is shown, as this information is most relevant. Nevertheless, the user should still be able to scroll to data captured after the first three hours meaning that limiting the x-axis maximum value is not an option.
For example: There are two curves. The first curve is drawn using data captured over a period of 4 hours, while the second curve is created out of data captured over 18 hours.
In the current version my programme initially displays all data of the graph which gets displayed meaning the first curve shows three hours of very relevant data while 1 hour of not so important information is shown too. The "ratio" of the second curve is 3 to 15 (highly significant data vs regular data). As a result, a different amount of high important information is shown when the user compares the two curves making it harder for the user to compare this data, as he has to adjust the zoom manually.
EDIT 01.04.2015 15:46
For setting the initial range I use the XYMultipleSeriesRenderer instance's method setInitialRange(double[] initialRange); which does not affect the graph at all. Below you can see my statement (currentlyProcessedCurve.getRecordStart() is an instance of Joda's DateTime and furhtermore it's the x value of the first displayed point):
public static final int CHART_X_AXIS_INITIAL_MAX = 3;
public static final int CHART_MARGIN_PAN = 45;
...
double[] initialRange = { currentlyProcessedCurve.getRecordStart().minusMinutes(ApplicationSettings.CHART_MARGIN_PAN).toDate().getTime(), currentlyProcessedCurve.getRecordStart().plusHours(ApplicationSettings.CHART_X_AXIS_INITIAL_MAX).toDate().getTime(), 0, 600 };
currentDatasetRenderer.setInitialRange(initialRange);
TIDE (Edit end)
The screenshot below approximately shows how the curve should look initially (Just for making it clear: Please only consider the graphs' shapes, as they should look equal --> What I'm trying to say: I know that the x-axis and the y-axis label of the two screenshots different, but I don't have better pictures yet):
desired initial range
Finally, the following screenshot shows how the curve looks when displayed:
For enabling the user to compare the curves I have locked the y-axis zoom.
Any help is highly appreciated. Thanks in advance!
Have you consider pan option?
With this option you can limit axis maximum, and your chart will show the important data on start, while user can scroll left or right (wherever you have less important data points).
All you need to do is:
set pan enabled for axis you need
set pan limits (so user can't scroll past the last data point)
Hope this helps,
Cheers.
Instead of using XYMultipleSeriesRendererInstance.setInitialRange() I had to set the initial x-values using XYMultipleSeriesRendererInstance.setXAxisMin() as well as XYMultipleSeriesRendererInstance.setXAxisMax().
double xMinValue = ...;
double xMaxValue = ...;
currentDatasetRenderer.setXAxisMin(xMinValue);
currentDatasetRenderer.setXAxisMax(xMaxValue);
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.
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