(Candle Stick)Trim the Non-Market Trading Day of X-axis

Discussion about JFreeChart related to stockmarket charts.
wzwei28
Posts: 105
Joined: Wed Mar 16, 2005 9:17 am
Location: Malaysia, Earth
Contact:

(Candle Stick)Trim the Non-Market Trading Day of X-axis

Post by wzwei28 » Thu May 12, 2005 12:50 pm

MMM :oops: ... I have a problem.
I use Candle Stick sample from demo named 'CandlestickChartDemo1'.

For easy understand of the question, I modify this sample's dataset and make it more like a real world trading mode. (which will not have any value in Saturday,Sunday and Public Holiday).
Here is my code:

Code: Select all

package demo;

import java.awt.Dimension;
import java.util.Date;
import javax.swing.JPanel;
import org.jfree.chart.*;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.xy.DefaultHighLowDataset;
import org.jfree.data.xy.OHLCDataset;
import org.jfree.date.DateUtilities;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

public class JCandlestickChartDemo2 extends ApplicationFrame
{

    public JCandlestickChartDemo2(String s)
    {
        super(s);
        OHLCDataset ohlcdataset = createDataset();
        JFreeChart jfreechart = createChart(ohlcdataset);
        jfreechart.getXYPlot().setOrientation(PlotOrientation.VERTICAL);
        ChartPanel chartpanel = new ChartPanel(jfreechart);
        chartpanel.setPreferredSize(new Dimension(500, 270));
        setContentPane(chartpanel);
    }
	
    private static JFreeChart createChart(OHLCDataset ohlcdataset)
    {
        JFreeChart jfreechart = ChartFactory.createCandlestickChart("Candlestick Demo", "Time", "Value", ohlcdataset, true);
        return jfreechart;
    }

    public static OHLCDataset createDataset()
    {
        Date adate[] = new Date[27];
        double ad[] = new double[27];
        double ad1[] = new double[27];
        double ad2[] = new double[27];
        double ad3[] = new double[27];
        double ad4[] = new double[27];
        int i = 12;
        int ii = 1;
        //byte byte0 = 1;
        //|hi|lo|open|close|
        adate[0] = DateUtilities.createDate(2001, i, 4, 12, 0);
        ad[0] = 47D;
        ad1[0] = 33D;
        ad2[0] = 35D;
        ad3[0] = 33D;
        ad4[0] = 100D;
        adate[1] = DateUtilities.createDate(2001, i, 5, 12, 0);
        ad[1] = 47D;
        ad1[1] = 32D;
        ad2[1] = 41D;
        ad3[1] = 37D;
        ad4[1] = 150D;
        adate[2] = DateUtilities.createDate(2001, i, 6, 12, 0);
        ad[2] = 49D;
        ad1[2] = 43D;
        ad2[2] = 46D;
        ad3[2] = 48D;
        ad4[2] = 70D;
        adate[3] = DateUtilities.createDate(2001, i, 7, 12, 0);
        ad[3] = 51D;
        ad1[3] = 39D;
        ad2[3] = 40D;
        ad3[3] = 47D;
        ad4[3] = 200D;
        adate[4] = DateUtilities.createDate(2001, i, 8, 12, 0);
        ad[4] = 60D;
        ad1[4] = 40D;
        ad2[4] = 46D;
        ad3[4] = 53D;
        ad4[4] = 120D;
        adate[5] = DateUtilities.createDate(2001, i, 11, 12, 0);
        ad[5] = 62D;
        ad1[5] = 55D;
        ad2[5] = 57D;
        ad3[5] = 61D;
        ad4[5] = 110D;
        adate[6] = DateUtilities.createDate(2001, i, 12, 12, 0);
        ad[6] = 65D;
        ad1[6] = 56D;
        ad2[6] = 62D;
        ad3[6] = 59D;
        ad4[6] = 70D;
        adate[7] = DateUtilities.createDate(2001, i, 13, 12, 0);
        ad[7] = 55D;
        ad1[7] = 43D;
        ad2[7] = 45D;
        ad3[7] = 47D;
        ad4[7] = 20D;
        adate[8] = DateUtilities.createDate(2001, i, 14, 12, 0);
        ad[8] = 54D;
        ad1[8] = 33D;
        ad2[8] = 40D;
        ad3[8] = 51D;
        ad4[8] = 30D;
        adate[9] = DateUtilities.createDate(2001, i, 15, 12, 0);
        ad[9] = 47D;
        ad1[9] = 33D;
        ad2[9] = 35D;
        ad3[9] = 33D;
        ad4[9] = 100D;
        adate[10] = DateUtilities.createDate(2001, i, 18, 12, 0);
        ad[10] = 54D;
        ad1[10] = 38D;
        ad2[10] = 43D;
        ad3[10] = 52D;
        ad4[10] = 50D;
        adate[11] = DateUtilities.createDate(2001, i, 19, 12, 0);
        ad[11] = 48D;
        ad1[11] = 41D;
        ad2[11] = 44D;
        ad3[11] = 41D;
        ad4[11] = 80D;
        adate[12] = DateUtilities.createDate(2001, i, 20, 12, 0);
        ad[12] = 60D;
        ad1[12] = 30D;
        ad2[12] = 34D;
        ad3[12] = 44D;
        ad4[12] = 90D;
        adate[13] = DateUtilities.createDate(2001, i, 21, 12, 0);
        ad[13] = 58D;
        ad1[13] = 44D;
        ad2[13] = 54D;
        ad3[13] = 56D;
        ad4[13] = 20D;
        adate[14] = DateUtilities.createDate(2001, i, 22, 12, 0);
        ad[14] = 54D;
        ad1[14] = 32D;
        ad2[14] = 42D;
        ad3[14] = 53D;
        ad4[14] = 70D;
        adate[15] = DateUtilities.createDate(2001, i, 25, 12, 0);
        ad[15] = 53D;
        ad1[15] = 39D;
        ad2[15] = 50D;
        ad3[15] = 49D;
        ad4[15] = 60D;
        adate[16] = DateUtilities.createDate(2001, i, 26, 12, 0);
        ad[16] = 47D;
        ad1[16] = 33D;
        ad2[16] = 41D;
        ad3[16] = 40D;
        ad4[16] = 30D;
        adate[17] = DateUtilities.createDate(2001, i, 27, 12, 0);
        ad[17] = 55D;
        ad1[17] = 37D;
        ad2[17] = 43D;
        ad3[17] = 45D;
        ad4[17] = 90D;
        adate[18] = DateUtilities.createDate(2001, i, 28, 12, 0);
        ad[18] = 54D;
        ad1[18] = 42D;
        ad2[18] = 50D;
        ad3[18] = 42D;
        ad4[18] = 150D;
        adate[19] = DateUtilities.createDate(2001, i, 29, 12, 0);
        ad[19] = 48D;
        ad1[19] = 37D;
        ad2[19] = 37D;
        ad3[19] = 47D;
        ad4[19] = 120D;
        adate[20] = DateUtilities.createDate(2002, ii, 2, 12, 0);
        ad[20] = 58D;
        ad1[20] = 33D;
        ad2[20] = 39D;
        ad3[20] = 41D;
        ad4[20] = 80D;
        adate[21] = DateUtilities.createDate(2002, ii, 3, 12, 0);
        ad[21] = 47D;
        ad1[21] = 31D;
        ad2[21] = 36D;
        ad3[21] = 41D;
        ad4[21] = 40D;
        adate[22] = DateUtilities.createDate(2002, ii, 4, 12, 0);
        ad[22] = 58D;
        ad1[22] = 44D;
        ad2[22] = 49D;
        ad3[22] = 44D;
        ad4[22] = 20D;
        adate[23] = DateUtilities.createDate(2002, ii, 5, 12, 0);
        ad[23] = 46D;
        ad1[23] = 41D;
        ad2[23] = 43D;
        ad3[23] = 44D;
        ad4[23] = 60D;
        adate[24] = DateUtilities.createDate(2002, ii, 8, 12, 0);
        ad[24] = 56D;
        ad1[24] = 39D;
        ad2[24] = 39D;
        ad3[24] = 51D;
        ad4[24] = 40D;
        adate[25] = DateUtilities.createDate(2002, ii, 9, 12, 0);
        ad[25] = 56D;
        ad1[25] = 39D;
        ad2[25] = 47D;
        ad3[25] = 49D;
        ad4[25] = 70D;
        adate[26] = DateUtilities.createDate(2002, ii, 10, 12, 0);
        ad[26] = 53D;
        ad1[26] = 39D;
        ad2[26] = 52D;
        ad3[26] = 47D;
        ad4[26] = 60D;
     
       
        return new DefaultHighLowDataset("Series 1", adate, ad, ad1, ad2, ad3, ad4);
    }

    public static JPanel createDemoPanel()
    {
        JFreeChart jfreechart = createChart(createDataset());
        return new ChartPanel(jfreechart);
    }

    public static String getDemoDescription()
    {
        return "A candlestick chart.";
    }

    public static void main(String args[])
    {
        JCandlestickChartDemo2 candlestickchartdemo1 = new JCandlestickChartDemo2("Candlestick Demo");
        candlestickchartdemo1.pack();
        RefineryUtilities.centerFrameOnScreen(candlestickchartdemo1);
        candlestickchartdemo1.setVisible(true);
    }
}
Thanks for trying:
My question as follow:

1) I hope I can trim out the non-market day(saturday,sunday and non market day(public holiday). Because my historical feed data do not include non-market day. So when I pass array into new DefaultHighLowDataset("Historical Data", aDate, aHi, aLow, aOpen, aClose, aVol); , the non-market day will also shown in the chart which I want to trim it out.

Summarize of question: Actually I hope I can let the x-axis trim out all null value(non-market day,I didn't pass any value on that Date) and combine the chart as diagram below:(no space/null val for non-market day)

Image

:oops: :oops: :cry: :cry:
Sorry, my english not very fluent, hope experts don't mind.
Thanks for spending valuable time to help me.

regards, wzwei28.[/img][/list]

wzwei28
Posts: 105
Joined: Wed Mar 16, 2005 9:17 am
Location: Malaysia, Earth
Contact:

Post by wzwei28 » Thu May 12, 2005 12:59 pm

the problem is I can't change the x-axis to a value axis(which I can assume the date is a value, and 210105 is larger than 200105(DDMMYYYY), but unlucky I only can use the

Code: Select all

public DefaultHighLowDataset(final String seriesName,
                                 final [color=red]Date[] date[/color],
                                 final double[] high, final double[] low,
                                 final double[] open, final double[] close,
                                 final double[] volume) {

        this.seriesName = seriesName;
        this.date = date;
        this.high = createNumberArray(high);
        this.low = createNumberArray(low);
        this.open = createNumberArray(open);
        this.close = createNumberArray(close);
        this.volume = createNumberArray(volume);

    }
which the red color part must be a Date, and cannot be a value. So I still can;t find solution to trim/filter out the non-market trading day

Any valuable idea?

wzwei28
Posts: 105
Joined: Wed Mar 16, 2005 9:17 am
Location: Malaysia, Earth
Contact:

Post by wzwei28 » Thu May 12, 2005 12:59 pm

:cry: :cry:

wzwei28
Posts: 105
Joined: Wed Mar 16, 2005 9:17 am
Location: Malaysia, Earth
Contact:

Post by wzwei28 » Thu May 12, 2005 1:00 pm

:oops: :oops:

wzwei28
Posts: 105
Joined: Wed Mar 16, 2005 9:17 am
Location: Malaysia, Earth
Contact:

Post by wzwei28 » Thu May 12, 2005 1:00 pm

:( :(

Guest

Post by Guest » Sun May 15, 2005 2:18 pm

I think what you need is to create a date axis with a SegmentedTimeLine and set the portion of the time line that you want to exclude as excluded segment.

wzwei28
Posts: 105
Joined: Wed Mar 16, 2005 9:17 am
Location: Malaysia, Earth
Contact:

Post by wzwei28 » Mon May 16, 2005 3:35 am

Thanks for speed reply. I wil check on it.'SegmentedDateAxis' . :D

wzwei28
Posts: 105
Joined: Wed Mar 16, 2005 9:17 am
Location: Malaysia, Earth
Contact:

Post by wzwei28 » Mon May 16, 2005 3:44 am

anybody face the same problem, please refer to class 'SegmentedTimeline' in 'org.jfree.chart.axis.SegmentedTimeline'. I will research on it. :D (JfreeChart0.9.21)



klsky
Posts: 5
Joined: Fri Aug 12, 2005 3:14 am

Post by klsky » Fri Aug 12, 2005 3:21 am

hi wzwei28,

I have tried on SegmentedTimeline to trim out all non market day. However, my target is the same you that I'd like to trim out all null/time with no tick so that the chart generated is continuous without any gap. I cannot find any answer from SegmentedTimeline. Have you researched out something that reach your target? could you share your findings if you can.

Many thx

wzwei28
Posts: 105
Joined: Wed Mar 16, 2005 9:17 am
Location: Malaysia, Earth
Contact:

Post by wzwei28 » Thu Sep 29, 2005 8:36 am

sorry.... recently I am developing other chart system using flash. forgot to visit the jfree forum.

As I know(my little opinion), u are not able to filter out the null tick(like public holiday on Mon-Friday). And if u success to do so, also not so appropriate, because no standard scale for the chart.

As long as I know of Jfreechart, u only can override the segment from 7-day per week to 5-day per week. And from the author opinion(David Gilbert), this method is not 100% bugs free and is quite complicated. I am sorry because last month I have many other bugs to fix as well as other project. Hence, I currently place this bug to phase III(oct start fix).

But I also developed other java chart systemm (write myself) before. Any with using drawString on X & Y location, we no need to border about the range. As the X-axis is just a label. We just connect every point together. Then for the intraday chart as well, we can easily trim out 1230-1430 non market hour.(Just plot data on specific x & y). The concept is totally different in JFreechart.

However, when I solved it, I will let u know later.(lol, if on october u still need it) :D

regards,
wei wei

klsky
Posts: 5
Joined: Fri Aug 12, 2005 3:14 am

Post by klsky » Thu Oct 06, 2005 11:57 am

icic.. I am still checking how can i trim null data out. see your good news :)

Guest

Post by Guest » Thu Oct 06, 2005 2:32 pm

you are welcome.

wzwei28
Posts: 105
Joined: Wed Mar 16, 2005 9:17 am
Location: Malaysia, Earth
Contact:

Post by wzwei28 » Tue Jul 04, 2006 4:35 am

I had success truncated out the Saturday, Sunday and non-trading/market day.

Although there have some bugs when timezone set wrongly.
I use GMT + 8:00 and it's fine. Sometimes, the label data is overlapping when u zoom too deep.

http://chart.n2nconnect.com/FAChart/NNSP.jsp

Minimum requirements: JRE 1.4.2_04 and above

regards,
Zi Wei.

Locked