From db0182faedf0c8a140fa02fb4ac0b7d2b505857d Mon Sep 17 00:00:00 2001 From: moshferatu Date: Sat, 30 Dec 2023 06:15:30 -0800 Subject: [PATCH] Add line chart type --- line_chart.py | 19 +++++++++++++++++++ line_chart_example.py | 16 ++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 line_chart.py create mode 100644 line_chart_example.py diff --git a/line_chart.py b/line_chart.py new file mode 100644 index 0000000..6907023 --- /dev/null +++ b/line_chart.py @@ -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. + ) \ No newline at end of file diff --git a/line_chart_example.py b/line_chart_example.py new file mode 100644 index 0000000..8759834 --- /dev/null +++ b/line_chart_example.py @@ -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() \ No newline at end of file