This is how I did Dates on x-axis !

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Mudit Wahal

This is how I did Dates on x-axis !

Post by Mudit Wahal » Tue Apr 16, 2002 7:22 pm

http://66.1.158.202:82/mystocks/CSCO.jpg

For those who want to know, here's how I did it.

My problem: I'm getting daily and intraday data of stock from my sqlserver. When I plotted it using DefaultHighLowDataset, it's showing gaps because of weekends and holidays.

1.0 Created a new class similar to DefaultHighLowDataset

So, I created a class similar to DefaultHighLowDataset. In that class I added another array index[] where I store increasing numbers starting from 2 (why 2, because I need some space on left side, default is 0 and I dont know how to change that YET .. using JFC since last 1 week only .. lot of learning etc etc).

2.0 Created a new class COPY of HorizontalNumberAxis

Copied HorizontalNumberAxis to another class. Tried to extend it but failed in some constructor issues. (I'm a Java lame, started learning java since last 3 weeks only. So if anyone wants to show me, that'll be great).

In this new HorizontalDateTimeLabelAxis class, I left everything as is except the refreshTicks method.

In the refreshTicks method, where it gets currentValue in the for loop, I added a call to my method in my modified defaultHighLowdataset where I return the string I want to print.
....................
String tl = dataset.getDateTimeLabel(1, currentTickValue);
...................

1 is meaningless as the dataset only store 1 series. Since all other getmethods in this are coded like that, so I left it that way.

Now, use this String "tl" to add to the Tick Label.

............................
Rectangle2D tickLabelBounds = tickLabelFont.getStringBounds(tl, g2.getFontRenderContext());
............................

3.0 Created a new method to create candlestickCharts

Except using the new HorizontalDateTimeLabelAxis. Also, we want to deal with integers when trying to access Date[] in the dataset. So, make sure to call setStandardTickUnits(TickUnits.createIntegerTickUnits()) for your horizontalaxis.

I'm also printing x-ticks vertical as its taking up too much space. Also, I may need to fudge with TickUnits so that I see less ticks on the horizontal axis. I see too many of them even when I make the chart small.


-------------------------------------------------------------------
Finally, a great many thanks to David ! Without whom this is not possible !

Hope this helps !!!

Mudit
p.s. : excuse my english and grammer. i code better than i type.

David Gilbert

Re: This is how I did Dates on x-axis !

Post by David Gilbert » Tue Apr 16, 2002 9:49 pm

Hi Mudit,

Good perserverance! I'm glad you got it working, and thanks for sharing the info with others.

Regards,

DG.

Mudit Wahal

Re: This is how I did Dates on x-axis !

Post by Mudit Wahal » Tue Apr 16, 2002 11:13 pm

David,

I'm trying to create a new class HorizontalDateTimeLabelAxis. I'm able to finally extend HorizontalNumberAxis class to do the job except for one thing in refreshTicks(). Got all the quirks out.

I had comment these lines because selectAutoTickUnit() is private to the method. Is it possible to make it public so that HorizontalNumberAxis can be fully extended.

// if (super.autoTickUnitSelection) {
// super.selectAutoTickUnit(g2, drawArea, plotArea);
// }

Without this, the chart is always stuck at the 1 unit on x-axis.

Thanks

Mudit

Mudit Wahal

Re: This is how I did Dates on x-axis !

Post by Mudit Wahal » Tue Apr 16, 2002 11:18 pm

David,

Right now I've two constructors and two methods (refreshTicks and selectAutoTickUnit) in this new class. Everything else is inherited.

So, I need to take care of two methods when a new release is announced.

Please see if selectAutoTickUnit() can be made public in future releases.

Thanks

Mudit

Amit Kulkarni

Re: This is how I did Dates on x-axis !

Post by Amit Kulkarni » Wed Apr 17, 2002 1:50 am

Mudit:

I would appreciate it if you can post the code it here.

Thanks

clam61
Posts: 66
Joined: Tue Jul 03, 2007 9:59 pm

Post by clam61 » Mon Jul 30, 2007 3:53 am

bump

jwenting
Posts: 157
Joined: Sat Jul 15, 2006 7:46 am

Post by jwenting » Mon Jul 30, 2007 9:22 am

5 years later and you're bumping a thread created by someone else?

Locked