Add line chart type
This commit is contained in:
parent
c0f32f4f9c
commit
db0182faed
19
line_chart.py
Normal file
19
line_chart.py
Normal file
@ -0,0 +1,19 @@
|
||||
from chart import Chart
|
||||
from pandas import Series
|
||||
from plotly.graph_objects import Scatter
|
||||
|
||||
class LineChart(Chart):
|
||||
|
||||
def __init__(self, x: Series, y: Series, name: str):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.name = name
|
||||
|
||||
def trace(self) -> Scatter:
|
||||
return Scatter(
|
||||
x = self.x,
|
||||
y = self.y,
|
||||
name = self.name,
|
||||
mode = 'lines',
|
||||
line=dict(color = 'yellow') # TODO: Make this configurable.
|
||||
)
|
16
line_chart_example.py
Normal file
16
line_chart_example.py
Normal file
@ -0,0 +1,16 @@
|
||||
from database.ohlc import ohlc
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from line_chart import LineChart
|
||||
from plot import plot
|
||||
|
||||
end_date = datetime.today().date()
|
||||
start_date = (end_date - timedelta(days=90))
|
||||
data = ohlc('SPX.XO', '1d', start_date = start_date, end_date = end_date)
|
||||
|
||||
line_chart = LineChart(
|
||||
x = data['Timestamp'],
|
||||
y = data['Close'],
|
||||
name = 'SPX'
|
||||
)
|
||||
plot(line_chart).show()
|
Loading…
Reference in New Issue
Block a user