1

I am using jfree chart to graphically represent data in a time line basis. Now there is a problem where the user can select data on a time stamp basis such as weekly, hourly, daily etc.

Now is there a way in jfree chart which automatically does summarization for us i.e if we have daily data and want to view that graph on a monthly basis? I want the data to be summarized on a monthly basis. I tried this using tick unit but it doesn't summarize the data accordingly but simply shows the tick unit.

It would be of great help if there is such a feature in JFree chart.

Kai
  • 38,985
  • 14
  • 88
  • 103
Madusudanan
  • 1,017
  • 1
  • 15
  • 36

1 Answers1

2

The traditional approach is to update the model to reflect the chosen interval, but you can use the zoom methods of ChartPanel to achieve a similar effect. In either case, the DateAxis will adjust automatically by default. This example may be useful for experimenting.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • For example...when I use a time series chart using values for three months such as jan,feb,march.Now I specify a tick unit "month", will the results automatically be summarized monthly i.e the values will be added for all the 31 days for jan and then the average value will be displayed in accordance and the same for other months also.. – Madusudanan Dec 28 '11 at 13:23
  • The default tick units will adjust to a given zoom state; try it on the example cited. – trashgod Dec 28 '11 at 13:35
  • Thanks for your example..it was great.But one more thing,if the user specifies the tick unit manually will the graph display accordingly...because my front end is a JSF page actually where the user specifies the time..such as per day basis,per month basis etc.,say the user specifies per month,will the program display the graph rightly for the specified time frame?? – Madusudanan Dec 28 '11 at 13:46
  • Yes, the axis adjusts when changing either the model or the zoom. – trashgod Dec 28 '11 at 14:14
  • Thats great,will test it out and get back. – Madusudanan Dec 28 '11 at 14:24
  • Hi.Your example is working good,but now I have data on a monthly basis,and I have to use this to prepare data for a weekly,daily,last 24 hrs etc.Do you have any idea on how could this be implemented,either I could hard code the zoom factors,which I dont think will be correct.Is there any other way you can think of? – Madusudanan Jan 10 '12 at 12:32
  • Scaling based on zoomed coordinates can be complicated, but it can be done using the kind of `scale` functions seen [here](http://sites.google.com/site/drjohnbmatthews/scaledview). Alternatively, you may want to fall back to updating the model. – trashgod Jan 10 '12 at 12:51
  • So are you saying that if I use static display such as an image rather than the JFrame window itself,the only way to display is to update the model accordingly using approriate data sets.So it is practically not feasible to implement the zooming concept using the above application?? – Madusudanan Jan 10 '12 at 13:02
  • No, you can change the view dynamically using either approach. The [example](http://sites.google.com/site/drjohnbmatthews/scaledview) shows how to interconvert particular model and view coordinates using [linear interpolation](http://en.wikipedia.org/wiki/Linear_interpolation). Which way are you doing it? – trashgod Jan 10 '12 at 13:12
  • Currently,now I have a separate query which retrieves values for each particular timeframe and which displays the graph accordingly.So my main aim is to reduce the load on the database by getting one result and then use your given example to update the graph accordingly.Anyway ill try using your second example and get back with the updates.Thanks so much for your help :) – Madusudanan Jan 10 '12 at 13:36
  • I'd get the one result and select subsets dynamically, as shown [here](http://stackoverflow.com/a/6849654/230513). – trashgod Jan 10 '12 at 13:43