Skip to content

Legend group#1

Merged
EsIstJosh merged 3 commits into
mainfrom
LegendGroup
Oct 30, 2024
Merged

Legend group#1
EsIstJosh merged 3 commits into
mainfrom
LegendGroup

Conversation

@EsIstJosh
Copy link
Copy Markdown
Owner

Add functionality to group lines under a single legend item, following example shown by @esteban2006 in
issue louisnw01#452 : (louisnw01#452 (comment))

image
`import pandas as pd
import lightweight_charts_
import time

if name == 'main':
# Load OHLCV data
df = pd.read_csv('./ohlcv.csv')

# Calculate SMAs using rolling method
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()

chart = lightweight_charts.Chart(inner_width=1, inner_height=1, position='left', debug=True)
chart.legend(True,font_size=12)


# Prepare SMA data for MultiLine
# Correct way to create the DataFrames for each SMA
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']})

# Create MultiLine instance and set initial SMA data
line1 = chart.create_line('line1',color='#ff0000',group='Group')
line2 = chart.create_line('line2',color='#acfb00',group='Group')
line3 = chart.create_line('line3',color='#ffffff')


line1.set(data1)
line2.set(data2) 
line3.set(data3)
# Display the chart
chart.show(block=True)

`

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 merged commit 541296f into main Oct 30, 2024
@EsIstJosh EsIstJosh deleted the LegendGroup branch January 24, 2025 23:38
@esteban2006
Copy link
Copy Markdown

esteban2006 commented May 3, 2025

Hi there @EsIstJosh thank you for the effort, I have seen your post a bit late but from the screenshot above, that was a very nice approach to combine a solution for both necesities, grouping and one name for multiple lines. thank you!

Now I still belive that having a way to group names for indicators such BB, super trend and which a user could individually manipulate values and other settings from the chart would be awesome,

keep up the good work, guys!

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