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] horizontal line can NOT be edited on the chart if async using #518

Open
barl0g opened this issue Feb 8, 2025 · 0 comments
Open

[BUG] horizontal line can NOT be edited on the chart if async using #518

barl0g opened this issue Feb 8, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@barl0g
Copy link

barl0g commented Feb 8, 2025

Expected Behavior

I use a default example https://lightweight-charts-python.readthedocs.io/en/latest/tutorials/events.html#live-data-topbar-events

Added only

# @barl0g:
def on_horizontal_line_move(chart, line):
    print(f'Horizontal line moved to: {line.price}')
# :@barl0g

and

chart.horizontal_line(160, func=on_horizontal_line_move) # @barl0g

Expected: horizontal line can be edited on the chart

Current Behaviour

horizontal line can NOT be edited on the chart

Reproducible Example

import asyncio
import pandas as pd
from lightweight_charts import Chart


async def data_loop(chart):
    ticks = pd.read_csv('ticks.csv')
    
    for i, tick in ticks.iterrows():
        if not chart.is_alive:
            return
        chart.update_from_tick(ticks.iloc[i])
        await asyncio.sleep(0.03)
        
        
def on_new_bar(chart):
    print('New bar event!')
    
    
def on_timeframe_selection(chart):
    print(f'Selected timeframe of {chart.topbar["timeframe"].value}')

# @barl0g:
def on_horizontal_line_move(chart, line):
    print(f'Horizontal line moved to: {line.price}')
# :@barl0g

async def main():
    chart = Chart()
    chart.events.new_bar += on_new_bar
    
    chart.topbar.switcher('timeframe', ('1min', '5min'), func=on_timeframe_selection)
    
    df = pd.read_csv('ohlc.csv')
    
    chart.horizontal_line(160, func=on_horizontal_line_move) # @barl0g
    chart.set(df)
    await asyncio.gather(chart.show_async(), data_loop(chart))
    

if __name__ == '__main__':
    asyncio.run(main())

Environment

- OS:GNU Linux Ubuntu 22.04.5 LTS
- Library: 2.1
@barl0g barl0g added the bug Something isn't working label Feb 8, 2025
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