Add the ability to set the color of a line
This commit is contained in:
parent
aa06e17dcf
commit
865a578e08
9
line.py
Normal file
9
line.py
Normal file
@ -0,0 +1,9 @@
|
||||
from pandas import Series
|
||||
from typing import List
|
||||
|
||||
class Line():
|
||||
|
||||
def __init__(self, values: List[Series], name: str = '', color: str = 'yellow'):
|
||||
self.values = values
|
||||
self.name = name
|
||||
self.color = color
|
@ -1,22 +1,24 @@
|
||||
from chart import Chart
|
||||
from line import Line
|
||||
from pandas import Series
|
||||
from plotly.graph_objects import Scatter
|
||||
from typing import List
|
||||
|
||||
class LineChart(Chart):
|
||||
|
||||
def __init__(self, x: Series, values: List[Series], title: str = ''):
|
||||
def __init__(self, x: Series, lines: List[Line], title: str = ''):
|
||||
self.x = x
|
||||
self.values = values
|
||||
self.lines = lines
|
||||
self.title = title
|
||||
|
||||
def traces(self) -> List[Scatter]:
|
||||
traces = []
|
||||
for value in self.values:
|
||||
for line in self.lines:
|
||||
traces.append(Scatter(
|
||||
x = self.x,
|
||||
y = value,
|
||||
y = line.values,
|
||||
mode = 'lines',
|
||||
line=dict(color = 'yellow') # TODO: Make this configurable.
|
||||
name = line.name,
|
||||
line = dict(color = line.color)
|
||||
))
|
||||
return traces
|
@ -1,6 +1,7 @@
|
||||
from database.ohlc import ohlc
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from line import Line
|
||||
from line_chart import LineChart
|
||||
from plot import plot
|
||||
|
||||
@ -10,7 +11,7 @@ data = ohlc('SPX.XO', '1d', start_date = start_date, end_date = end_date)
|
||||
|
||||
line_chart = LineChart(
|
||||
x = data['Timestamp'],
|
||||
values = [data['Close']],
|
||||
lines = [Line(data['Close'], name = 'Close')],
|
||||
title = 'SPX (Close)'
|
||||
)
|
||||
plot(line_chart)
|
@ -1,6 +1,7 @@
|
||||
from database.ohlc import ohlc
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from line import Line
|
||||
from line_chart import LineChart
|
||||
from plot import plot
|
||||
|
||||
@ -10,7 +11,10 @@ data = ohlc('SPX.XO', '1d', start_date = start_date, end_date = end_date)
|
||||
|
||||
line_chart = LineChart(
|
||||
x = data['Timestamp'],
|
||||
values = [data['High'], data['Low']],
|
||||
lines = [
|
||||
Line(data['High'], name = 'High', color = 'limegreen'),
|
||||
Line(data['Low'], name = 'Low', color = 'red')
|
||||
],
|
||||
title = 'SPX (High, Low)'
|
||||
)
|
||||
plot(line_chart)
|
Loading…
Reference in New Issue
Block a user