hellocharts-android
hellocharts-android copied to clipboard
Time series support?
Hello ,
I wanted to start using this library but i dont see any support for time series chart?
I want to make time series in the X axis and custom Y labels. is it possible? Thanks.
I am not 100% sure if this is the same issue... I am facing the problem that I want to put multiple time series data as lines into one chart. Now my data has different time ranges such as:
- First data set: Tuesday to Thursday
- Second data set: Monday to Friday
I noticed that I can add the timestamp as a label - which is nothing more as a string which aligns with the x-value in the data line (not shown in the screenshot). When I add the data lines to the chart they both start at the far left as shown in the screenshot.
Is the line chart actually aware of the date data type? At the moment all data points have the same horizontal distance from each other - which is simply wrong.
Thanks for the answer looks like it's something similar but still i just want to create a graph with time series on x axis. any ideas?
Currently, I put the timestamp from each data item onto the x-axis. Here is how:
List<PointValue> yValues = new ArrayList<PointValue>();
List<AxisValue> axisValues = new ArrayList<AxisValue>();
for (int x = 0; x < mData.size(); ++x) {
DataItem dataItem = mData.getItem(x);
DateTime recordedAt = dataItem.getRecordedAt();
String formattedRecordedAt = DateTimeFormatter.getFormattedDateTime(recordedAt);
int yValue = dataItem.getYValue();
yValues.add(new PointValue(x, yValue));
AxisValue axisValue = new AxisValue(x);
axisValue.setLabel(formattedRecordedAt);
axisValues.add(axisValue);
}
// then later ...
LineChartData lineChartData = new LineChartData();
lineChartData.setLines(mLines);
lineChartData.setAxisXBottom(new Axis(axisValues));
As mentioned it is nothing but a string label. All data points have the same distance from each other which is not what the timestamps aka. x-values say.
Thanks i will try that !
Issue #12 of MPAndroidChart describes the same problem - they do not support time series by now.
yeah its pretty bad.. this library would be perfect if time series was supported
@lecho Please notice that @kenaiX mentioned here that AChartEngine supports time series ... This might be a source for you.
yes i already used AChartEngine but the problem that it's very slow for big data set and you may not be able to zoom/scroll
Hi, yea, hellocharts doesn't have dedicated methods for time series. Instead for now you need to use string labels. I will look into AChartEngine implementation to see how they did that.
@johnjohndoe I think you could use timestamps as X values to display points with different X distances from each other.
List<PointValue> yValues = new ArrayList<PointValue>();
List<AxisValue> axisValues = new ArrayList<AxisValue>();
for (int i = 0; i < mData.size(); ++i) {
DataItem dataItem = mData.getItem(i);
DateTime recordedAt = dataItem.getRecordedAt();
String formattedRecordedAt = DateTimeFormatter.getFormattedDateTime(recordedAt);
int yValue = dataItem.getYValue();
yValues.add(new PointValue(recordedAt.toMiliseconds(), yValue)); //use recordedAt timestamp/day of the year number or something like that as x value
AxisValue axisValue = new AxisValue(recordedAt.toMiliseconds());
axisValue.setLabel(formattedRecordedAt);
axisValues.add(axisValue);
}
// then later ...
LineChartData lineChartData = new LineChartData();
lineChartData.setLines(mLines);
lineChartData.setAxisXBottom(new Axis(axisValues));
@lecho Thank you. This seems to be a good workaround.
@lecho Is there an ETA for time series support?
Hi, no, I am not going to add time series any time soon
Honestly, believe it or not, this works pretty reliably for me, and faster than any other library I've tried
- Decrement all the X in PointValue ArrayList by 1
- Add the new point in the PointValue ArrayList
- Call setLineChartData for the chartView.
If you want to "scroll", remove the PointValues that have the new X value less than your requirement.
I haven't played with viewport for timeseries data but maybe I will later and then the timeseries data will be "pannable".
@lecho I am using the following code to implement the time stamp fro the plot
> List<PointValue> yValues = new ArrayList<PointValue>();
> List<AxisValue> axisValues = new ArrayList<AxisValue>();
> for (int i = 0; i < mData.size(); ++i) {
> DataItem dataItem = mData.getItem(i);
> DateTime recordedAt = dataItem.getRecordedAt();
> String formattedRecordedAt = DateTimeFormatter.getFormattedDateTime(recordedAt);
> int yValue = dataItem.getYValue();
> yValues.add(new PointValue(recordedAt.toMiliseconds(), yValue)); //use recordedAt timestamp/day of the year number or something like that as x value
> AxisValue axisValue = new AxisValue(recordedAt.toMiliseconds());
> axisValue.setLabel(formattedRecordedAt);
> axisValues.add(axisValue);
> }
>
> // then later ...
>
> LineChartData lineChartData = new LineChartData();
> lineChartData.setLines(mLines);
> lineChartData.setAxisXBottom(new Axis(axisValues));
Its the same code @johnjohndoe suggested. I'm quite new to this, I did not understand how DataItem
and DateTimeFormatter
is being retrieved. It would really helpful if you could provide with some information regarding the same.
I have the same issue. How do we implement time series and is its support added now? @
@adarsh-tm Please note that you can wrap code snippets in triple backticks ``` to enable nice syntax highlighting. The quote signs > can be omitted then.
I have added the real time graph with time in x axis for Line chart. The drawback for this is that the interval of adding data has to be uniform Create a variable which holds the current time. This should be initialized when you add the first entry to the Line data graphStartTime = System.currentTimeMillis(); Now use the stored value in the valueformatter
xAxis.setValueFormatter(new IAxisValueFormatter() { private SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss", Locale.getDefault()); @Override public String getFormattedValue(float value, AxisBase axis) { long currentTime = graphStartTime + ((int)value * intervalAtWhichYouUpdateTheLineData);
return dateFormat.format(new Date(currentTime));
}
});
xAxis.setLabelCount(maxXAxisLabelCount); // Add a limit otherwise the labels overlap
Can you please post a small demo code for multi line graphs as shown in the above image.?
@rishabhtech1994 A dataset entry can hold a custom object, I created a class to hold my time data with some other information and created the entry set. when overriding getFormattedValue for xAxis I can retrieve the data object from the entry. There own you have to just format the time as you need it and return the string