As part of the standard chart types, Chart FX for Java provides support for three different types of financial charts: Hi-Low-Close, Open-Hi-Low-Close and Candlestick charts. Financial charts also provide support for Multi-Gallery charts, so you can plot an Open-Hi-Low-Close combined with a line or a volume (bar) chart. Please refer to a sample later in this section.
The method of passing data to a financial chart is exactly the same as with other charts: opening a communication channel (openData method), passing the numerical information and finally closing the communication channel.
Each marker is defined by several values. For a Hi-Low-Close chart you'll need three series and for Open-Hi-Low-Close you will need four. Finally, you'll need to pass special constants in the Value property to instruct Chart FX for Java which numerical values go with the Open, Hi, Low and Close values.
The first step you need to do when plotting a financial chart is to handle the Gallery property either at design or run time to specify the type of chart you'll be handling, as follows:
chart1.setGallery(Gallery.HI_LOW_CLOSE);
|
To pass data to an Open-Hi-Lo-Close chart you must specify the appropriate constant in the Value property as follows:
chart1.openData(COD.VALUES, 4, 5);
for (int j=0;j<5;j++) { chart1.setValue(Ohlc.LOW,j,<Low value as double>); chart1.setValue(Ohlc.OPEN,j,<Open value as double>); chart1.setValue(Ohlc.CLOSE,j,<Close value as double>); chart1.setValue(Ohlc.HIGH,j,<High value as double>); }
chart1.closeData(COD.VALUES);
|

MultiType Financial Charts
It is a common practice to combine a financial chart with another chart (i.e. Lines or Bar) to display other relevant information (i.e. Volume Traded). The Gallery property provided by the Series object can be used to achieve this. Another Chart FX for Java feature that can be used with combined financial charts is the double Y-axis because the volume traded moves in a different range of scale than the price of a stock.
In the following sample, we will create a Open-Hi-Low-Close chart with a volume bar chart and associate the volume series with a secondary Y-axis:
chart1.setGallery(Gallery.OPEN_HI_LOW_CLOSE);
chart1.openData(COD.VALUES, 5, nPoints)
for (int j=0;j<nPoints-1;j++) { chart1.setValue(Ohlc.LOW,j,<Low value as double>); chart1.setValue(Ohlc.OPEN,j,<Open value as double>); chart1.setValue(Ohlc.CLOSE,j,<Close value as double>); chart1.setValue(Ohlc.HIGH,j,<High value as double>);
chart1.setValue(4,j,<Volume Traded in day as double>); }
chart1.closeData(COD.VALUES);
SeriesAttributes series = chart1.getSeries(4); series.setGallery(Gallery.BAR);
series.setYAxis(YAxis.SECONDARY);
|

|