Coder Social home page Coder Social logo

Comments (4)

louisnw01 avatar louisnw01 commented on May 10, 2024 1

Hi, and Thank you!

I took a look at the intraday.json you are using and I see a few issues with it:

  • It is not chronological
  • It contains duplicate times
  • It does not occur at regular intervals

Lightweight Charts is quite picky with the data it recieves, so its important to address these before setting the data. For example:

from lightweight_charts import Chart
import pandas as pd

if __name__ == '__main__':
    raw_df = pd.read_json("intraday.json", lines = True)
    df = pd.DataFrame({
            "time" : pd.to_datetime(raw_df.TradingDate + ' ' + raw_df.Time, format = "%d/%m/%Y %H:%M:%S"),
            "open" : raw_df.Open,
            "high" : raw_df.High,
            "low" : raw_df.Low,
            "close" : raw_df.Close,
            "volume" : raw_df.LastVol
        })

    df = df.drop_duplicates(subset='time')
    df_sorted = df.sort_values('time')
    df_filtered = df_sorted[df_sorted['time'].dt.second % 2 == 0]

    chart = Chart(volume_enabled=False)
    chart.set(df_filtered)
    chart.show(block=True)

This removes the duplicate times, sorts them in chronological order, and filters them so that only times with even seconds are used.

from lightweight-charts-python.

tariusagi avatar tariusagi commented on May 10, 2024

Btw, I've printed the first few rows of the data frame which I put into the chart object, for a quick reference:

                 time    open    high     low   close  volume
0 2023-05-17 11:30:12  1065.8  1074.7  1065.5  1072.5       1
1 2023-05-17 13:00:03  1065.8  1074.7  1065.5  1072.2     195
2 2023-05-17 13:00:05  1065.8  1074.7  1065.5  1072.2     195
3 2023-05-17 13:00:07  1065.8  1074.7  1065.5  1072.2     195
4 2023-05-17 13:00:06  1065.8  1074.7  1065.5  1072.2       1

from lightweight-charts-python.

anurag-py avatar anurag-py commented on May 10, 2024

@tariusagi the problem is with the datetime object of the dataframe. In my case this, was a series object and worked fine. you can try converting the datetime object into series.

from lightweight-charts-python.

tariusagi avatar tariusagi commented on May 10, 2024

@louisnw01 Thank you very much, I've got it working perfectly now.

from lightweight-charts-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.