Drawing gaps in a TimeSeries Plot
Drawing gaps in a TimeSeries Plot
Hi all,
At the moment, when there are time gaps in my time series (when drawing a TimeSeries Plot), JFreeChart bridges these gaps by rendering a straight line. Is there a way to stop this so that gaps are accounted for in drawing time series plots?
Thank you
Stuart
At the moment, when there are time gaps in my time series (when drawing a TimeSeries Plot), JFreeChart bridges these gaps by rendering a straight line. Is there a way to stop this so that gaps are accounted for in drawing time series plots?
Thank you
Stuart
Re: Drawing gaps in a TimeSeries Plot
Hi Stuart,
It is my intention for JFreeChart to support the use of null to indicate missing data. Unfortunately in the current version, if your XYDataset returns a null value you will get null pointer exceptions. I've just made a change to the code so that it will now leave a gap in the line for the series...that will be included in version 0.8.1.
Regards,
Dave Gilbert
It is my intention for JFreeChart to support the use of null to indicate missing data. Unfortunately in the current version, if your XYDataset returns a null value you will get null pointer exceptions. I've just made a change to the code so that it will now leave a gap in the line for the series...that will be included in version 0.8.1.
Regards,
Dave Gilbert
Re: Drawing gaps in a TimeSeries Plot
David,
Did the above change went in 0.8.1 release ? I've same problem. I've two days of intraday data for stocks. The data is from 9:30am to 4:30pm. I see a solid line from end of 1st day which is 4:30pm to begin of next day which is 9:30am. The time continues on X axis from 4:30pm till midnight and then from 12:00am to 9:30am next day.
Anyway to not show the solid line ? I want the next day to start right when the first day ends at 4:30pm.
Thanks
Mudit
Did the above change went in 0.8.1 release ? I've same problem. I've two days of intraday data for stocks. The data is from 9:30am to 4:30pm. I see a solid line from end of 1st day which is 4:30pm to begin of next day which is 9:30am. The time continues on X axis from 4:30pm till midnight and then from 12:00am to 9:30am next day.
Anyway to not show the solid line ? I want the next day to start right when the first day ends at 4:30pm.
Thanks
Mudit
Re: Drawing gaps in a TimeSeries Plot
Hi Mudit,
Yes, I believe the change did go in. If you add a data item to your dataset with a null value at 4.31pm, then you will see a gap in your chart between the market closing and the market opening the next day.
At the moment you can't exclude segments of time from the axis. If you don't want 4.30pm to 9am the next day to show at all, then you will have to modify the date axis code...I'm not sure of a general way to do it, although I do understand your requirement.
Regards,
DG.
Yes, I believe the change did go in. If you add a data item to your dataset with a null value at 4.31pm, then you will see a gap in your chart between the market closing and the market opening the next day.
At the moment you can't exclude segments of time from the axis. If you don't want 4.30pm to 9am the next day to show at all, then you will have to modify the date axis code...I'm not sure of a general way to do it, although I do understand your requirement.
Regards,
DG.
Re: Drawing gaps in a TimeSeries Plot
David,
Does the TimeSeries tries to fill the gaps between the time if there is no data ? My last data for yesterday is at 4:30pm and the next data point is today at 9:30am. Then why does TimeSeries has to go thru all the points between 4:30pm and 9:30am when none exists ? It should just plot it as x/y pairs.
Also, if I plot hilow dataset, will I find same problem ? I guess because again its plotting time on the x-axis.
Anyone else using JFreeChart found a solution/workaround for this problem ?
Thanks
Mudit
Does the TimeSeries tries to fill the gaps between the time if there is no data ? My last data for yesterday is at 4:30pm and the next data point is today at 9:30am. Then why does TimeSeries has to go thru all the points between 4:30pm and 9:30am when none exists ? It should just plot it as x/y pairs.
Also, if I plot hilow dataset, will I find same problem ? I guess because again its plotting time on the x-axis.
Anyone else using JFreeChart found a solution/workaround for this problem ?
Thanks
Mudit
Re: Drawing gaps in a TimeSeries Plot
David,
Please point me to the code where it increments the time from 4:30pm to 4:31pm and since there is no corresponding y element (price) associated with the new time, it interpolates it with the 9:30am next day data.
Thanks
Mudit
Please point me to the code where it increments the time from 4:30pm to 4:31pm and since there is no corresponding y element (price) associated with the new time, it interpolates it with the 9:30am next day data.
Thanks
Mudit
Re: Drawing gaps in a TimeSeries Plot
Mudit Wahal wrote:
> Please point me to the code where it increments the time from
> 4:30pm to 4:31pm and since there is no corresponding y
> element (price) associated with the new time, it interpolates
> it with the 9:30am next day data.
All the drawing is done in the drawItem(...) method of the StandardXYItemRenderer class. If the value is non-null, then this renderer draws a line from the previous point to the current point (unless the previous point was null, in which case no line is drawn).
Hope that helps,
DG.
> Please point me to the code where it increments the time from
> 4:30pm to 4:31pm and since there is no corresponding y
> element (price) associated with the new time, it interpolates
> it with the 9:30am next day data.
All the drawing is done in the drawItem(...) method of the StandardXYItemRenderer class. If the value is non-null, then this renderer draws a line from the previous point to the current point (unless the previous point was null, in which case no line is drawn).
Hope that helps,
DG.
Re: Drawing gaps in a TimeSeries Plot
David,
My understanding is that in BasicTimeSeries, the data is stored in pairs. First element is the time and second is the value. Time is plotted on the horizontal axis and value is plotted along the vertical axis.
Say the data is stored as
.........
April 10 2002 16:30:00 , 100.00
April 11 2002 09:30:00 , 101.00
.........
If I plot it using createTimeSeriesChart, it plots all the data till 16:30:00 correctly and the plots a solid line 100 to 101 for the time after 16:30:00 and 9:30:00 next day. It is getting these time values by incrementing the time after 16:30:00 and adding null data. It does that till it finds a valid data at 9:30:00 next morning.
Isn't it possible to add just one method in the class which is incrementing the time to not do it ?
I'm interested in finding the place where it increments the time and plots a line if it has not data. May be I'll try to find it again.
In the StandardXYItemRender->drawItem method, I see its getting x1,y1 and x0,y0 pairs from the data->getXValue , data->getYValue. And then it plots the line between x0,y0 and x1,y1 if y0 and y1 are not null.
the XValues are stored as the time, so I believe x0 will be 4:30:00pm and x1 should be 9:30:00am next day. But since its not the case, somewhere new values of x (which is the time) are being introduced when the dateaxis is being plotted. May be the data is being changed/manipulated before it is being passed to the drawItem method.
Thanks
Mudit
My understanding is that in BasicTimeSeries, the data is stored in pairs. First element is the time and second is the value. Time is plotted on the horizontal axis and value is plotted along the vertical axis.
Say the data is stored as
.........
April 10 2002 16:30:00 , 100.00
April 11 2002 09:30:00 , 101.00
.........
If I plot it using createTimeSeriesChart, it plots all the data till 16:30:00 correctly and the plots a solid line 100 to 101 for the time after 16:30:00 and 9:30:00 next day. It is getting these time values by incrementing the time after 16:30:00 and adding null data. It does that till it finds a valid data at 9:30:00 next morning.
Isn't it possible to add just one method in the class which is incrementing the time to not do it ?
I'm interested in finding the place where it increments the time and plots a line if it has not data. May be I'll try to find it again.
In the StandardXYItemRender->drawItem method, I see its getting x1,y1 and x0,y0 pairs from the data->getXValue , data->getYValue. And then it plots the line between x0,y0 and x1,y1 if y0 and y1 are not null.
the XValues are stored as the time, so I believe x0 will be 4:30:00pm and x1 should be 9:30:00am next day. But since its not the case, somewhere new values of x (which is the time) are being introduced when the dateaxis is being plotted. May be the data is being changed/manipulated before it is being passed to the drawItem method.
Thanks
Mudit
Re: Drawing gaps in a TimeSeries Plot
Mudit Wahal wrote:
> My understanding is that in BasicTimeSeries, the data is
> stored in pairs. First element is the time and second is the
> value. Time is plotted on the horizontal axis and value is
> plotted along the vertical axis.
Correct.
> Say the data is stored as
>
> .........
> April 10 2002 16:30:00 , 100.00
> April 11 2002 09:30:00 , 101.00
> .........
My suggestion is to add one item to your data:
April 10 2002 16:30:00 , 100.00
April 10 2002 16:31:00 , null
April 11 2002 09:30:00 , 101.00
> If I plot it using createTimeSeriesChart, it plots all the
> data till 16:30:00 correctly and the plots a solid line 100
> to 101 for the time after 16:30:00 and 9:30:00 next day. It
> is getting these time values by incrementing the time after
> 16:30:00 and adding null data. It does that till it finds a
> valid data at 9:30:00 next morning.
No, it just reads the two data values you supplied and draws a line between them.
> Isn't it possible to add just one method in the class which
> is incrementing the time to not do it ?
>
> I'm interested in finding the place where it increments the
> time and plots a line if it has not data. May be I'll try to
> find it again.
You found it just below...
> In the StandardXYItemRender->drawItem method, I see its
> getting x1,y1 and x0,y0 pairs from the data->getXValue ,
> data->getYValue. And then it plots the line between x0,y0 and
> x1,y1 if y0 and y1 are not null.
>
> the XValues are stored as the time, so I believe x0 will be
> 4:30:00pm and x1 should be 9:30:00am next day. But since its
> not the case, somewhere new values of x (which is the time)
> are being introduced when the dateaxis is being plotted. May
> be the data is being changed/manipulated before it is being
> passed to the drawItem method.
In the BasicTimeSeries the date-time is stored as some subclass of TimePeriod (probably Minute or Second in your case). The way the TimeSeriesCollection class implements the XYDataset interface, when it is asked for an X-value it returns a Long representing the number of milliseconds from midnight GMT, 1 Jan 1970 to the *middle* of the TimePeriod. That makes it easy to plot on a numerical axis (the date axis really is numerical, but the tick labels are dates which makes it look as though it is not numerical).
Hope this helps,
DG.
> My understanding is that in BasicTimeSeries, the data is
> stored in pairs. First element is the time and second is the
> value. Time is plotted on the horizontal axis and value is
> plotted along the vertical axis.
Correct.
> Say the data is stored as
>
> .........
> April 10 2002 16:30:00 , 100.00
> April 11 2002 09:30:00 , 101.00
> .........
My suggestion is to add one item to your data:
April 10 2002 16:30:00 , 100.00
April 10 2002 16:31:00 , null
April 11 2002 09:30:00 , 101.00
> If I plot it using createTimeSeriesChart, it plots all the
> data till 16:30:00 correctly and the plots a solid line 100
> to 101 for the time after 16:30:00 and 9:30:00 next day. It
> is getting these time values by incrementing the time after
> 16:30:00 and adding null data. It does that till it finds a
> valid data at 9:30:00 next morning.
No, it just reads the two data values you supplied and draws a line between them.
> Isn't it possible to add just one method in the class which
> is incrementing the time to not do it ?
>
> I'm interested in finding the place where it increments the
> time and plots a line if it has not data. May be I'll try to
> find it again.
You found it just below...
> In the StandardXYItemRender->drawItem method, I see its
> getting x1,y1 and x0,y0 pairs from the data->getXValue ,
> data->getYValue. And then it plots the line between x0,y0 and
> x1,y1 if y0 and y1 are not null.
>
> the XValues are stored as the time, so I believe x0 will be
> 4:30:00pm and x1 should be 9:30:00am next day. But since its
> not the case, somewhere new values of x (which is the time)
> are being introduced when the dateaxis is being plotted. May
> be the data is being changed/manipulated before it is being
> passed to the drawItem method.
In the BasicTimeSeries the date-time is stored as some subclass of TimePeriod (probably Minute or Second in your case). The way the TimeSeriesCollection class implements the XYDataset interface, when it is asked for an X-value it returns a Long representing the number of milliseconds from midnight GMT, 1 Jan 1970 to the *middle* of the TimePeriod. That makes it easy to plot on a numerical axis (the date axis really is numerical, but the tick labels are dates which makes it look as though it is not numerical).
Hope this helps,
DG.
Re: Drawing gaps in a TimeSeries Plot
David,
Thanks for quick responses !
I put a null after the end of the first day and before being of the next day. Now I dont see long lines joining the prev day end and next day begin. But I still see the gaps in the time. The 4:31pm to 9:30am time is still being plotted on the x-axis. Its even bad when the data is across a weekend. Then you have a long x-axis with nothing on the chart.
There has to be some way to do it. All the chart packages (windows/unix/etc etc) do take care of this sitaution. Because I've not seen gapped charts for intraday stocks anywhere.
If I use HighLowData set will it make any difference ? Because then I wont be plotting lines between the two points. Just drawing bars. Or the date/time algorithm is still the same ?
Thanks
Mudit
Thanks for quick responses !
I put a null after the end of the first day and before being of the next day. Now I dont see long lines joining the prev day end and next day begin. But I still see the gaps in the time. The 4:31pm to 9:30am time is still being plotted on the x-axis. Its even bad when the data is across a weekend. Then you have a long x-axis with nothing on the chart.
There has to be some way to do it. All the chart packages (windows/unix/etc etc) do take care of this sitaution. Because I've not seen gapped charts for intraday stocks anywhere.
If I use HighLowData set will it make any difference ? Because then I wont be plotting lines between the two points. Just drawing bars. Or the date/time algorithm is still the same ?
Thanks
Mudit
Re: Drawing gaps in a TimeSeries Plot
I tried using your sample in DemoDataSet->createSampleHiLowDataSet().
I did some experimentation. If I use all 47 bars, I get same chart as yours. But if I use only the first 3 bars i.e. I get 3 bars separated by 24 hours of gap on the x-axis. Just modify the decl where you have 47 to 2 and then put the init of all date[3] onwards in if (false). You will see what I'm talking about.
this is what i've done
-----------------------
int nbar = 3;
Date[] date = new Date[nbar];
double[] high = new double[nbar];
double[] low = new double[nbar];
double[] open = new double[nbar];
double[] close = new double[nbar];
double[] volume = new double[nbar];
......
if (false) {
date[3] = createDate(2001, Calendar.JANUARY,7);
.......
and then
--------------------------
volume[46] = 100.0;
}
---------------------------
The labels on x-axis are 4 Jan 12:00, 4 Jan 18:00, 5 Jan 6:00, and so on ...
There are only 3 bars plotted, all around 12:00 which is middle of the day. Other times are just blank 18:00, 0:00, 6:00, etc etc)
Once you plot it, you will get the picture. I believe this is serious problem. I hope there is a work around for it.
Thanks
Mudit
So, instead of dates (yyyy-mm-dd) as being printed on the x-axis, its printing the time in 24 hours for the 3 days.
I dont think this should be the case. If there are three data points for three dates, then there should be three bars only with 3 x-axis tick points (dont know how to describe them). I should not be looking at blank data points.
I did some experimentation. If I use all 47 bars, I get same chart as yours. But if I use only the first 3 bars i.e. I get 3 bars separated by 24 hours of gap on the x-axis. Just modify the decl where you have 47 to 2 and then put the init of all date[3] onwards in if (false). You will see what I'm talking about.
this is what i've done
-----------------------
int nbar = 3;
Date[] date = new Date[nbar];
double[] high = new double[nbar];
double[] low = new double[nbar];
double[] open = new double[nbar];
double[] close = new double[nbar];
double[] volume = new double[nbar];
......
if (false) {
date[3] = createDate(2001, Calendar.JANUARY,7);
.......
and then
--------------------------
volume[46] = 100.0;
}
---------------------------
The labels on x-axis are 4 Jan 12:00, 4 Jan 18:00, 5 Jan 6:00, and so on ...
There are only 3 bars plotted, all around 12:00 which is middle of the day. Other times are just blank 18:00, 0:00, 6:00, etc etc)
Once you plot it, you will get the picture. I believe this is serious problem. I hope there is a work around for it.
Thanks
Mudit
So, instead of dates (yyyy-mm-dd) as being printed on the x-axis, its printing the time in 24 hours for the 3 days.
I dont think this should be the case. If there are three data points for three dates, then there should be three bars only with 3 x-axis tick points (dont know how to describe them). I should not be looking at blank data points.
Re: Drawing gaps in a TimeSeries Plot
David,
Another approach is that I use XYDataSet without timeseries if its possible. Then I give x values as 1,2,3 etc, y values as my prices. And I create my own x-tic labels to create the chart. Is it possible ?
Also, similarily I want to create charts using HighLowDataset BUT instead of Date I will use increasing numbers and again use my own labels for x-tics. If I create my own labels, then I can generate charts with discontinous time gaps but JFreeChart doesn't have to know it. May be I need to a class similar to DefaultHighLowDataset where instead of date, I'll have numbers.
How does it know that it has to plot Date on the x-axix ? I hope its not hard coded for the HighLowDataset.
Is there some sample code to create x-tics and plot then on the x-axis ?
Thanks
Mudit
Another approach is that I use XYDataSet without timeseries if its possible. Then I give x values as 1,2,3 etc, y values as my prices. And I create my own x-tic labels to create the chart. Is it possible ?
Also, similarily I want to create charts using HighLowDataset BUT instead of Date I will use increasing numbers and again use my own labels for x-tics. If I create my own labels, then I can generate charts with discontinous time gaps but JFreeChart doesn't have to know it. May be I need to a class similar to DefaultHighLowDataset where instead of date, I'll have numbers.
How does it know that it has to plot Date on the x-axix ? I hope its not hard coded for the HighLowDataset.
Is there some sample code to create x-tics and plot then on the x-axis ?
Thanks
Mudit
Re: Drawing gaps in a TimeSeries Plot
Mudit Wahal wrote:
> How does it know that it has to plot Date on the x-axix ? I
> hope its not hard coded for the HighLowDataset.
The horizontal axis will interpret the x-values returned by the HighLowDataset as:
1) Numbers if you use a HorizontalNumberAxis on the XYPlot;
2) Dates (coded as milliseconds since 1-Jan-1970) if you use the HorizontalDateAxis in the XYPlot;
You can change the axis at any time using the setHorizontalAxis(...) method (in the Plot class).
Regards,
DG.
> How does it know that it has to plot Date on the x-axix ? I
> hope its not hard coded for the HighLowDataset.
The horizontal axis will interpret the x-values returned by the HighLowDataset as:
1) Numbers if you use a HorizontalNumberAxis on the XYPlot;
2) Dates (coded as milliseconds since 1-Jan-1970) if you use the HorizontalDateAxis in the XYPlot;
You can change the axis at any time using the setHorizontalAxis(...) method (in the Plot class).
Regards,
DG.
Re: Drawing gaps in a TimeSeries Plot
Mudit Wahal wrote:
> I put a null after the end of the first day and before being
> of the next day. Now I dont see long lines joining the prev
> day end and next day begin. But I still see the gaps in the
> time. The 4:31pm to 9:30am time is still being plotted on the
> x-axis. Its even bad when the data is across a weekend. Then
> you have a long x-axis with nothing on the chart.
The axes that have been implemented so far (HorizontalNumberAxis and HorizontalDateAxis) both preserve the scale, so that you can plot data with irregular intervals.
It would be possible to develop another axis that shows only intervals along a scale (say 9.30am to 4.00pm, Monday to Friday). I'm going to add that to the to-do list, because I can see the applications that it would be useful for.
Regards,
DG.
> I put a null after the end of the first day and before being
> of the next day. Now I dont see long lines joining the prev
> day end and next day begin. But I still see the gaps in the
> time. The 4:31pm to 9:30am time is still being plotted on the
> x-axis. Its even bad when the data is across a weekend. Then
> you have a long x-axis with nothing on the chart.
The axes that have been implemented so far (HorizontalNumberAxis and HorizontalDateAxis) both preserve the scale, so that you can plot data with irregular intervals.
It would be possible to develop another axis that shows only intervals along a scale (say 9.30am to 4.00pm, Monday to Friday). I'm going to add that to the to-do list, because I can see the applications that it would be useful for.
Regards,
DG.