Git Product home page Git Product logo

Comments (4)

yuankunzhang avatar yuankunzhang commented on May 21, 2024

Hi, the candlestick examples are still there. Please check this section in readme - https://github.com/yuankunzhang/charming/#candlestick-charts

from charming.

pferreira8 avatar pferreira8 commented on May 21, 2024

thanks! I will close the issue, was checking out the project on docs.rs and that might be why I didn't see it

from charming.

wangjiawen2013 avatar wangjiawen2013 commented on May 21, 2024

@pferreira8
Hi,
Do you know how to use polars dataframe in charming ? Is it compatible with charming dataframe ?

from charming.

pferreira8 avatar pferreira8 commented on May 21, 2024

@pferreira8 Hi, Do you know how to use polars dataframe in charming ? Is it compatible with charming dataframe ?

It is compatible once you convert the Dataframe into a Vec<Vec>
I have the logic split between two functions, it could be cleaned up for sure but this was my hacky method that worked.

// pass df into this function, assuming column names below or edit them to match properly
fn parse_ohlc_data(data: DataFrame) -> Result< (Vec<Vec<f64>>, Vec<String> ), Box<dyn std::error::Error> > {
       let d_open: Vec<f64> = data.column("open")?.f64()?.into_iter().map(|x| x.unwrap()).collect();
       let d_high: Vec<f64> = data.column("high")?.f64()?.into_iter().map(|x| x.unwrap()).collect();
       let d_low: Vec<f64> = data.column("low")?.f64()?.into_iter().map(|x| x.unwrap()).collect();
       let d_close: Vec<f64> = data.column("close")?.f64()?.into_iter().map(|x| x.unwrap()).collect();
       let dt: Vec<String> = data.column("date")?.iter().map(|x| x.to_string()).collect(); 
       let mut ohlc_vec: Vec<Vec<f64>> = Vec::new();
       for i in 0..d_open.len() {
            let array: [f64;4] = [d_open[i], d_high[i], d_low[i], d_close[i]]; 
            ohlc_vec.push(array.to_vec());
        }
        Ok((ohlc_vec, dt)) 
}
pub fn build_symbol_chart(symbol_name: &str, ohlc: (Vec<Vec<f64>>, Vec<String>)) -> Result<(), EchartsError> {
    let chart = Chart::new()
        .x_axis(Axis::new().show(true).data(ohlc.1))
        .y_axis(Axis::new().show(true).scale(true))
        .data_zoom(
            DataZoom::new()
                .type_(DataZoomType::Slider)
                .min_value_span(5),
        )
        .series(Candlestick::new().data(
            ohlc.0
        )).background_color("6E7468");

    let mut rend = HtmlRenderer::new("OHLCV", 1000, 800).theme(Westeros);
    let dir_file = format!("./html/charts/{}.html", symbol_name);
    HtmlRenderer::render(&rend, &chart)?;
    rend.save(&chart, std::path::Path::new(&dir_file))?;
    // println!("saving chart to html");
    
    Ok(())
}
// EXAMPLE
//converts polars df to work with charming
let ohlc = parse_ohlc_data(data).unwrap();

// creates an html file for candlestick charts
tools::chart::build_symbol_chart(YOUR_FILE_NAME_HERE, ohlc)?;

from charming.

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.