Import XML into TimeSeries?
Import XML into TimeSeries?
Hi,
I need to import XML data to a TimeSeries, but see that this has not yet been implemented officially.
If anyone has any suggestions for methods on doing so, or even has actually done so, and would be willing to share it would be much appreciated, by myself and many others.
Specific questions include: What form need the XML be in? How much of the current code can be re-used?
I need to import XML data to a TimeSeries, but see that this has not yet been implemented officially.
If anyone has any suggestions for methods on doing so, or even has actually done so, and would be willing to share it would be much appreciated, by myself and many others.
Specific questions include: What form need the XML be in? How much of the current code can be re-used?
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
I didn't get around to handling this because the format for the time periods needs to be able to handle internationalization, and that's no easy problem. The existing XML dataset readers are fairly simple, you could model a time series reader on the same code, but still the date handling is the largest problem.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


I guess my XML ought to be in the following format:
to save on some code re-writing.
However, it would be great if I could instead use something like:
Which of these will be easier to implement for?
(naturally, the latter is far preferable, less prone to error, and more compact, though the java code may be harder to create)
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<dataset>
<Series name="Series 1">
<Item>
<Key>2004-12-01</Key>
<Value>8.48</Value>
</Item>
...
</Series>
...
</dataset>
However, it would be great if I could instead use something like:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<dataset>
<Item>
<Key>2004-12-01</Key>
<Value Series="1">8.48</Value>
<Value Series="2">12.5</Value>
...
</Item>
...
</dataset>
(naturally, the latter is far preferable, less prone to error, and more compact, though the java code may be harder to create)
Success!
I have now successfully re-written code which accepts XML in the following format and places it in a TimeSeriesCollection.
I tried to keep as close to the other formats as possible, but to avoid needlessly expanding the file, I included more than one series' value with each Key.
However, each Value tag replaces the previous value, hence only the one value is stored for each key (in each Series).
If anyone (David?) can help me use the Series attribute to store in a different series it would be greatly appreciated.
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<TimeSeriesCollection>
<Series>
<Item>
<Key>2004-12-01</Key>
<Value Series="1">8.48</Value>
<Value Series="2">8.55</Value>
<Value Series="3">8.63</Value>
...
</Item>
...
</Series>
(...)
</TimeSeriesDataset>
However, each Value tag replaces the previous value, hence only the one value is stored for each key (in each Series).
If anyone (David?) can help me use the Series attribute to store in a different series it would be greatly appreciated.
:?:
It seems I actually misunderstood what was happening with the Values - in fact it simply uses the first Value and skips the rest.
I can't see what needs to be changed to force it to process them all (I want to be able to pass it a comparable to select which Value to insert.)
If anyone can help me with that I might actually be finished!
I can't see what needs to be changed to force it to process them all (I want to be able to pass it a comparable to select which Value to insert.)
If anyone can help me with that I might actually be finished!
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Can you post the code you have so far? I may not have time to look at it (away on holiday soon!) but someone else might be able to help.
One comment I would make - the XML format you have chosen assumes that all series share the same x-values (dates), which isn't a *general* requirement for the TimeSeriesCollection. And also it assumes the x-values are days, and not some other time period. That's no problem if it meets your requirements, but I'd like to find an XML format that works for both reading and writing (that is, *any* TimeSeriesCollection could be written to the format).
I'm not trying to put you off, though. Because the special case you are handling is probably the most common one - so if you get the code working, I'm sure there are others that will find it useful.
One comment I would make - the XML format you have chosen assumes that all series share the same x-values (dates), which isn't a *general* requirement for the TimeSeriesCollection. And also it assumes the x-values are days, and not some other time period. That's no problem if it meets your requirements, but I'd like to find an XML format that works for both reading and writing (that is, *any* TimeSeriesCollection could be written to the format).
I'm not trying to put you off, though. Because the special case you are handling is probably the most common one - so if you get the code working, I'm sure there are others that will find it useful.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Hi, thanks for the encouragement.
I was expecting that there could be missing values (e.g. today's includes values for series 1&2, and tomorrow's item has values for series 2&3), so that might allow the scenario you suggest.
I've not seen a java class for properly handling string dates, which ought to be straightforward enough for ISO8601, so I just use a SimpleDateFormat.
The code is, of course, based on the CategoryDataset handling included with JFreeChart, with an extra variable passed to choose which series to gather data for.
I realise it probably would be better to dynamically create series to fit the data, but I think that would require a more significant change to the structure of the parsing classes.
(My current code to follow...)
I was expecting that there could be missing values (e.g. today's includes values for series 1&2, and tomorrow's item has values for series 2&3), so that might allow the scenario you suggest.
I've not seen a java class for properly handling string dates, which ought to be straightforward enough for ISO8601, so I just use a SimpleDateFormat.
The code is, of course, based on the CategoryDataset handling included with JFreeChart, with an extra variable passed to choose which series to gather data for.
I realise it probably would be better to dynamically create series to fit the data, but I think that would require a more significant change to the structure of the parsing classes.
(My current code to follow...)
Re: Import XML into TimeSeries?
Hi there,
I know I am exhuming that subject but I am looking at solutions to use XML file as input to create a TimeSeries.
My project aims at providing user with UI that control different types of input (JDBC, XML...) and therefore I would be interested to know if someone already managed to solve this kind of input.
Another question is that I have my date as strings on my current dataset but I understood TimeSeries uses internationalization so how can I convert to the appropriate Double value programmatically?
Kindest regards
I know I am exhuming that subject but I am looking at solutions to use XML file as input to create a TimeSeries.
My project aims at providing user with UI that control different types of input (JDBC, XML...) and therefore I would be interested to know if someone already managed to solve this kind of input.
Another question is that I have my date as strings on my current dataset but I understood TimeSeries uses internationalization so how can I convert to the appropriate Double value programmatically?
Kindest regards
Re: Import XML into TimeSeries?
thats good point jassel The code is, of course, based on the CategoryDataset handling included with JFreeChart, with an extra variable passed to choose which series to gather data for.keep it up