Skip to content

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

@csanchez-aureum

Description

@csanchez-aureum

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions