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

[BUG] Precision is not updated in line legends #504

Open
csanchez-aureum opened this issue Dec 30, 2024 · 1 comment
Open

[BUG] Precision is not updated in line legends #504

csanchez-aureum opened this issue Dec 30, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@csanchez-aureum
Copy link

csanchez-aureum commented Dec 30, 2024

Expected Behavior

When I set chart.precision(5) I expect a 5 digits number be shown in the line legend

Current Behaviour

Even when I set the precision I always see a 2 digits number instead.

I've made a temporal fix by changing:
this.legendItemFormat(s.value,t.precision)
by
this.legendItemFormat(s.value,this.handler.precision)

But I'm not sure if this is the "right" fix and this fix also depends on this PR to me merged #500

Reproducible Example

import pandas as pd
from lightweight_charts import Chart

def calculate_sma(df, period: int = 50):
    return pd.DataFrame({
        'time': df['date'],
        f'SMA {period}': df['close'].rolling(window=period).mean()
    }).dropna()

if __name__ == '__main__':
    chart = Chart()
    line = chart.create_line(name='SMA 50')

    df = pd.read_csv('ohlcv.csv')
    sma_df = calculate_sma(df, period=50)

    chart.precision(5)
    chart.legend(visible=True)

    chart.set(df)
    line.set(sma_df)
    
    chart.show(block=True)

Environment

- OS: Windows and Mac
- Library: 2.1
@csanchez-aureum csanchez-aureum added the bug Something isn't working label Dec 30, 2024
@csanchez-aureum
Copy link
Author

I should have called line.precision(5) and the code works.

Maybe it will be a good idea to use the chart's precision when the line is created by for example calling:
self.precision(chart.num_decimals)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant