JRuby 1.1, JFreeChart 1.0.9 を使用。
include Java
import java.util.Date
import javax.swing.JFrame
import java.util.GregorianCalendar
import org.jfree.chart.JFreeChart
import org.jfree.chart.ChartPanel
import org.jfree.chart.plot.XYPlot
import org.jfree.chart.renderer.xy.CandlestickRenderer
import org.jfree.data.xy.DefaultHighLowDataset
import org.jfree.chart.axis.DateAxis
import org.jfree.chart.axis.NumberAxis
date_axis = DateAxis.new()
price_axis = NumberAxis.new()
# 適当にデータを作成
cal = GregorianCalendar.new(2008, GregorianCalendar::JANUARY, 1)
dates = java.util.Date[5].new()
5.times do |i|
dates[i] = cal.getTime()
cal.add(GregorianCalendar::DAY_OF_MONTH, 1)
end
# to_java(:double)で、RubyのArrayをJavaのdouble型の配列に変換
opens = [100, 125, 150, 200, 150].to_java(:double)
highs = [120, 140, 160, 200, 150].to_java(:double)
lows = [100, 120, 130, 180, 130].to_java(:double)
closes = [115, 140, 155, 180, 135].to_java(:double)
volumes = [1000, 1500, 2500, 5000, 3000].to_java(:double)
dataset = DefaultHighLowDataset.new("Candle", dates, highs, lows, opens, closes, volumes)
renderer = CandlestickRenderer.new()
plot = XYPlot.new(dataset, date_axis, price_axis, renderer)
frame = JFrame.new("example")
chart = JFreeChart.new(plot)
panel = ChartPanel.new(chart)
frame.getContentPane().add(panel)
frame.pack()
frame.show()
0 件のコメント:
コメントを投稿