Import XML into TimeSeries?

Discussion about JFreeChart related to stockmarket charts.
Locked
jazzle
Posts: 23
Joined: Wed Jun 15, 2005 10:31 am
Location: Liverpool, UK
Contact:

Import XML into TimeSeries?

Post by jazzle » Fri Jul 08, 2005 2:32 pm

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?

jazzle
Posts: 23
Joined: Wed Jun 15, 2005 10:31 am
Location: Liverpool, UK
Contact:

Post by jazzle » Mon Jul 11, 2005 2:55 pm

bump?

If anyone has any suggestions/ideas they will be very much apprecitated.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Wed Jul 13, 2005 2:31 pm

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

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

jazzle
Posts: 23
Joined: Wed Jun 15, 2005 10:31 am
Location: Liverpool, UK
Contact:

Post by jazzle » Wed Jul 13, 2005 3:06 pm

that's a good point.
I already have to transform (xslt) the xml I'm using, so at the same time changed the dates to ISO 8601 (e.g. 2005-07-13).

I'm not entirely sure where to start still, so any pointers would be much appreciated.

jazzle
Posts: 23
Joined: Wed Jun 15, 2005 10:31 am
Location: Liverpool, UK
Contact:

Post by jazzle » Fri Jul 15, 2005 2:14 pm

I guess my XML ought to be in the following format:

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>
to save on some code re-writing.

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>
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)

jazzle
Posts: 23
Joined: Wed Jun 15, 2005 10:31 am
Location: Liverpool, UK
Contact:

Success!

Post by jazzle » Tue Jul 19, 2005 11:09 am

I have now successfully re-written code which accepts XML in the following format and places it in a TimeSeriesCollection.

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>
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.

jazzle
Posts: 23
Joined: Wed Jun 15, 2005 10:31 am
Location: Liverpool, UK
Contact:

:?:

Post by jazzle » Thu Jul 21, 2005 10:48 am

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!

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Tue Jul 26, 2005 10:18 am

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.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

jazzle
Posts: 23
Joined: Wed Jun 15, 2005 10:31 am
Location: Liverpool, UK
Contact:

Post by jazzle » Tue Jul 26, 2005 10:32 am

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...)

jazzle
Posts: 23
Joined: Wed Jun 15, 2005 10:31 am
Location: Liverpool, UK
Contact:

Post by jazzle » Mon Aug 08, 2005 5:34 pm

I think I've traced my major stumbling block to the fact that startElement() only gets called for the first <Value> even though endElement() gets called for each one.

If someone could tell me why this is the case then I think I'll be there.

jazzle
Posts: 23
Joined: Wed Jun 15, 2005 10:31 am
Location: Liverpool, UK
Contact:

Post by jazzle » Thu Sep 01, 2005 12:08 pm

bumpage.
that's bump-age, not bum-page - that would just be weird.

hAlej
Posts: 1
Joined: Wed Jul 24, 2013 9:15 am
antibot: No, of course not.

Re: Import XML into TimeSeries?

Post by hAlej » Wed Jul 24, 2013 9:25 am

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

ricky87
Posts: 2
Joined: Wed Oct 02, 2013 4:43 am
antibot: No, of course not.

Re: Import XML into TimeSeries?

Post by ricky87 » Wed Oct 02, 2013 5:03 am

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

Locked