VladimirMarkelov / clui

Command Line User Interface (Console UI inspired by TurboVision)
MIT License
670 stars 50 forks source link

Barchart question #106

Closed mbolder closed 5 years ago

mbolder commented 6 years ago

Hello, i am trying to add a currency chart to my app. Pulling data from quandl works fine, creating the chart object as well. But due to my inexperience with go i am stuck at adding the data to the BarData Object. if i do this only the last price is displayed as bar :

func getHistData(ric string){
    chart := ui.AddWindow(10, 10, 20, 20, "GBP-EUR (daily)")
    bch := ui.CreateBarChart(chart, 40, 12, 1)  
    var FXclose float64
    d:=[]ui.BarData{{Value:FXclose, Fg:ui.ColorGreen}}
    quandl.APIKey = "QuandlKey"
    data, _ := quandl.GetSymbol(ric, nil)
    for _, item := range data.Data {
        FXclose = item[2].(float64)
        d=[]ui.BarData{{Value:FXclose, Fg:ui.ColorGreen}}
    }
    bch.SetData(d)
    ui.PutEvent(ui.Event{Type: ui.EventRedraw})
}

How do add the values instead of replacing them ?

Found it, looks now like this:

func getHistData(ric string){
    chart := ui.AddWindow(10, 10, 20, 20, ric)
    bch := ui.CreateBarChart(chart, 130, 50, 1)
    bch.SetBarGap(0)    
    var FXclose float64
    d:=[]ui.BarData{}
    v := quandl.Options{}
    v.Set("trim_start", "2017-01-01")
    v.Set("trim_end", "2018-09-12")
    v.Set("collapse","weekly")
    quandl.APIKey = "QuandlKey"
    data, _ := quandl.GetSymbol(ric, v)
    for _, item := range data.Data {
        if item[2].(float64)>0 {
            FXclose = item[2].(float64)
            d=append(d,ui.BarData{Value:FXclose, Title:item[0].(string), Fg:ui.ColorGreen})
        }
    }

    bch.SetData(d)
    bch.SetValueWidth(5)
    bch.SetAutoSize(true)
    ui.PutEvent(ui.Event{Type: ui.EventRedraw})
}

But, is there a way to adjust the scale of the axis / steps, since my values range between 0,88 and 0.91 , not a lot is changing in the bars ?? For example set range from min value to maximum instead of whole bar.

VladimirMarkelov commented 6 years ago

I see. At this moment there is no way to set scale. The only way is to prepare data before pushing it to the BarChart that can be inconvenient sometimes.

Let's discuss what way is the best. The first idea is to provide a way to limit display range. E.g, set range to 0.87-0.92 and then all values will be difference between 0.87 and real value. Maybe it would be good to mark somehow values that exceeds or below limits, e.g. with special char 'V' - below, '^' - above.

Or maybe I do not understand the problem correctly and my solution does not work for you. Do you have any suggestions or ideas?