gizak / termui

Golang terminal dashboard
MIT License
13.07k stars 783 forks source link

when there is not much point, line chart x labels do not match the y point #202

Closed jeffrey4l closed 5 years ago

jeffrey4l commented 5 years ago

Here is the testing code

package main

import (
    "math"

    ui "github.com/gizak/termui"
)

func main() {
    err := ui.Init()
    if err != nil {
        panic(err)
    }
    defer ui.Close()

    lc0 := ui.NewLineChart()
    lc0.BorderLabel = "Line Chart"
    lc0.Data["default"] = (func() []float64 {
        n := 10
        ps := make([]float64, n)
        for i := 0; i < n; i++ {
            ps[i] = 1 + math.Sin(float64(i)/5)

        }
        return ps
    })()
    lc0.Mode = "dot"
    lc0.Width = 50
    lc0.Height = 12
    lc0.X = 0
    lc0.Y = 0
    lc0.AxesColor = ui.ColorWhite
    lc0.LineColor["first"] = ui.ColorGreen

    ui.Render(lc0)

    uiEvents := ui.PollEvents()
    for {
        e := <-uiEvents
        switch e.ID {
        case "q", "<C-c>":
            return
        }
    }

}

And i got following graph 065

the labels on x axis do not match the points. if i increase the points from n:=10 to n := 50 , it works as expected. 066

The question is: could we fix the graph when there is no much points? or did u use it in wrong?

thanks.

cjbassi commented 5 years ago

Hi, this should be fixed in 958a28575d7411492d25e42da3ad5a6e5947d9a4 on master. Do note that a lot of breaking changes have been introduced in that commit.