Add line chart type

This commit is contained in:
moshferatu 2023-12-30 06:15:30 -08:00
parent c0f32f4f9c
commit db0182faed
2 changed files with 35 additions and 0 deletions

19
line_chart.py Normal file
View 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
View 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()