Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Features: Area & Bar series types, Grouping [Line,Histogram,Area,Bar] series under 1 Legend item using optional 'group' and 'legend_symbol' parameters. #473

Open
wants to merge 32 commits into
base: main
Choose a base branch
from

Conversation

EsIstJosh
Copy link

@EsIstJosh EsIstJosh commented Oct 27, 2024

image
`
import pandas as pd
from lightweight_charts import Chart

if name == 'main':
chart1 = Chart(inner_width=0.333, inner_height=1,position='left',debug=True)
chart2 = chart1.create_subchart(position='left' , width=0.333, height=1)
chart3 = chart1.create_subchart(position='left' , width=0.333, height=1)

df = pd.read_csv('./ohlcv.csv')
df['line1'] = df['close'].rolling(window=10, min_periods=1).mean()
df['line2'] = df['close'].rolling(window=20, min_periods=1).mean()
df['line3'] = df['close'].rolling(window=30, min_periods=1).mean()

chart3.legend(True,font_size=12)



#Bar Chart 
bar = chart1.create_bar('bar_chart')
bar.set(df)
area = chart2.create_area('area_chart')


#Area Chart
area_data = pd.DataFrame()
area_data['time'] = df['time']
area_data['area_chart'] = df['close']
area.set(area_data)

#Legend Groups
data1 = pd.DataFrame({'time': df['time'], 'line1':  df['line1']})
data2 = pd.DataFrame({'time': df['time'], 'line2':  df['line2']})
data3 = pd.DataFrame({'time': df['time'], 'line3':  df['line3']})

line1 = chart3.create_line('line1',color='#ff0000',group='Group')
line2 = chart3.create_line('line2',color='#acfb00',group='Group')
line3 = chart3.create_line('line3',color='#ffffff')


line1.set(data1)
line2.set(data2) 
line3.set(data3)



chart1.show(block=True)

`

Use existing line/histogram logic to implement area charts
Add methods to plot area chart.
Fix: Area line coloring  
Feat: Implement bar series
Feat: Implement bar series
Feat: Implement Area and Bar series types
Fix: Bar update method
Add functionality to group lines under a single legend item following example shown by @esteban2006 louisnw01#452 (comment)
Implement logic to handle LegendGroup creation when creating a line series.
Add group parameter (str) to make a line appear in the legend under a LegendGroup
@EsIstJosh EsIstJosh changed the title Implement Area & Bar series types Add Features: Area & Bar series types, Grouping lines under 1 Legend item. Oct 30, 2024
@EsIstJosh
Copy link
Author

image

@EsIstJosh EsIstJosh changed the title Add Features: Area & Bar series types, Grouping lines under 1 Legend item. Add Features: Area & Bar series types, Grouping [Line,Histogram,Area,Bar] series under 1 Legend item using optional 'group' and 'legend_symbol' parameters. Oct 31, 2024
EsIstJosh and others added 12 commits October 31, 2024 05:17
Cleaned up, restructured for easier interaction adding/removing
Fix wick position for combined candles
For those who think the default candles are too thick.
Enhance flexibility by enabling the configuration of lineStyle, lineWidth, and the shape of individual bars through corresponding columns in the DataFrame, similar to the existing options for color, borderColor, and wickColor. Also improve performance by separating data aggregation from rendering.
@80sVectorz
Copy link

@EsIstJosh I've tried installing your fork, but it'm experiencing the following issue:

Traceback (most recent call last):
  File "C:\...\visualize.py", line 42, in <module>
    chart = Chart()
            ^^^^^^^
  File "C:\...\venv_trading_2\Lib\site-packages\lightweight_charts\chart.py", line 185, in __init__
    super().__init__(window, inner_width, inner_height, scale_candles_only, toolbox, position=position)
  File "C:\...\venv_trading_2\Lib\site-packages\lightweight_charts\abstract.py", line 1087, in __init__
    from lightweight_charts_.polygon import PolygonAPI
ModuleNotFoundError: No module named 'lightweight_charts_'

I've installed it using the following command with Python 3.11.4:
pip install -U git+https://github.com/EsIstJosh/lightweight-charts-python
Maybe I'm not doing it right. But if you could help in any way, that would be great.

@EsIstJosh
Copy link
Author

@EsIstJosh I've tried installing your fork, but it'm experiencing the following issue:

Traceback (most recent call last):
  File "C:\...\visualize.py", line 42, in <module>
    chart = Chart()
            ^^^^^^^
  File "C:\...\venv_trading_2\Lib\site-packages\lightweight_charts\chart.py", line 185, in __init__
    super().__init__(window, inner_width, inner_height, scale_candles_only, toolbox, position=position)
  File "C:\...\venv_trading_2\Lib\site-packages\lightweight_charts\abstract.py", line 1087, in __init__
    from lightweight_charts_.polygon import PolygonAPI
ModuleNotFoundError: No module named 'lightweight_charts_'

I've installed it using the following command with Python 3.11.4:
pip install -U git+https://github.com/EsIstJosh/lightweight-charts-python
Maybe I'm not doing it right. But if you could help in any way, that would be great.

I think it has to do with me having an underscore after this : ModuleNotFoundError: No module named 'lightweight_charts_',

In my setup I have the project in my working directory so I could just reference it like that but it should probably be renamed back.

@80sVectorz
Copy link

80sVectorz commented Jan 7, 2025

@EsIstJosh I've tried installing your fork, but it'm experiencing the following issue:

Traceback (most recent call last):
  File "C:\...\visualize.py", line 42, in <module>
    chart = Chart()
            ^^^^^^^
  File "C:\...\venv_trading_2\Lib\site-packages\lightweight_charts\chart.py", line 185, in __init__
    super().__init__(window, inner_width, inner_height, scale_candles_only, toolbox, position=position)
  File "C:\...\venv_trading_2\Lib\site-packages\lightweight_charts\abstract.py", line 1087, in __init__
    from lightweight_charts_.polygon import PolygonAPI
ModuleNotFoundError: No module named 'lightweight_charts_'

I've installed it using the following command with Python 3.11.4:
pip install -U git+https://github.com/EsIstJosh/lightweight-charts-python
Maybe I'm not doing it right. But if you could help in any way, that would be great.

I think it has to do with me having an underscore after this : ModuleNotFoundError: No module named 'lightweight_charts_',

In my setup I have the project in my working directory so I could just reference it like that but it should probably be renamed back.

Alright I'll make a local edit until you've changed it in the repo. Thanks for the reply!
Edit:
For anyone interested, changing from:

from lightweight_charts_.polygon import PolygonAPI

To

from .polygon import PolygonAPI

Fixed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants