Show CandlestickChart using jfreechart
Code: "plot_CandleStick.py". Programming language: Python
DMelt Version 1. Last modified: 12/18/2016. License: Pro
https://datamelt.org/code/cache/plot_CandleStick_1856.py
To run this script using the DMelt IDE,
copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.
from java.util import *
from org.jfree.chart import ChartFactory,ChartPanel
from org.jfree.data.xy import DefaultHighLowDataset
from org.jfree.ui import RefineryUtilities
from java.lang import Math
from java.awt import *
from javax.swing import *
def createData(year, month, date):
calendar = Calendar.getInstance()
calendar.set(year, month - 1, date)
return calendar.getTime()
date = []; high = []; low = []; open = []; close = []; volume = []
calendar = Calendar.getInstance();
calendar.set(2008, 5, 1);
for i in range(15):
date.append(createData(2008, 8, i + 1))
high.append(30 + Math.round(10) + (Math.random() * 20.0))
low.append(30 + Math.round(10) + (Math.random() * 20.0))
open.append(10 + Math.round(10) + (Math.random() * 20.0))
close.append(10 + Math.round(10) + (Math.random() * 20.0))
volume.append(10.0 + (Math.random() * 20.0))
data = DefaultHighLowDataset("", date, high, low, open, close, volume)
# create a chart
chart = ChartFactory.createCandlestickChart( "Candlestick Demo", "Time", "Price", data, False)
chartPanel = ChartPanel(chart)
chartPanel.setPreferredSize(Dimension(600, 350))
# put it into a frame
frame=JFrame("CandlestickChart")
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)
frame.setContentPane(chartPanel)
frame.pack()
RefineryUtilities.centerFrameOnScreen(frame)
frame.setVisible(True)
You see the box below because you did not login.