go-echarts / go-echarts

🎨 The adorable charts library for Golang.
https://go-echarts.github.io/go-echarts/
MIT License
6.53k stars 558 forks source link

Not able to change candlestick color (in Kline chart) using WithItemStyleOpts option #320

Open vishnukumarkvs opened 9 months ago

vishnukumarkvs commented 9 months ago

kline candlestick colors are not changing even though changing colors in WithItemStyleOpts option

Part of code

charts.WithItemStyleOpts(opts.ItemStyle{
        Color:        "#0F22C2",
        Color0:       "#C2BA0F",
        BorderColor:  "#0F22C2",
        BorderColor0: "#C2BA0F", 
        BorderWidth: 4,
    }),

image

As you can see, border colors are changing but not color and color0, which represent inside colors

Full code below:-

func Kline(company string, data []dto.OHLC) string{
    kline := charts.NewKLine()

    x := make([]string, 0)
    y := make([]opts.KlineData, 0)
    kd := ConvertOHLCtoKlineData(data)

    // Improvement: Uneccessary reverse order
    for i, j := 0, len(kd)-1; i < j; i, j = i+1, j-1 {
        kd[i], kd[j] = kd[j], kd[i]
    }
    for i := 0; i < len(kd); i++ {
        x = append(x, kd[i].Date)
        y = append(y, opts.KlineData{Value: kd[i].Data})
    }

    kline.SetGlobalOptions(
        charts.WithTitleOpts(opts.Title{
            Title: company,
        }),
        charts.WithXAxisOpts(opts.XAxis{
            SplitNumber: 20,
        }),
        charts.WithYAxisOpts(opts.YAxis{
            Scale: true,
        }),  
        charts.WithDataZoomOpts(opts.DataZoom{
            Type:       "inside",
            Start:      50,
            End:        100,
            XAxisIndex: []int{0},
        }),
        charts.WithDataZoomOpts(opts.DataZoom{
            Type:       "slider",
            Start:      50,
            End:        100,
            XAxisIndex: []int{0},
        }),
        charts.WithTooltipOpts(opts.Tooltip{Show: true}),
        charts.WithLegendOpts(opts.Legend{Show: true, Right: "80px"}),
    )

    kline.SetXAxis(x).AddSeries("kline", y).
        SetSeriesOptions(
            charts.WithMarkPointNameTypeItemOpts(opts.MarkPointNameTypeItem{
                Name:     "highest value",
                Type:     "max",
                ValueDim: "highest",
            }),
            charts.WithMarkPointNameTypeItemOpts(opts.MarkPointNameTypeItem{
                Name:     "lowest value",
                Type:     "min",
                ValueDim: "lowest",
            }),
            charts.WithMarkPointStyleOpts(opts.MarkPointStyle{
                Label: &opts.Label{
                    Show: true,
                },
            }),
            charts.WithItemStyleOpts(opts.ItemStyle{
                Color:        "#0F22C2",
                Color0:       "#C2BA0F",
                BorderColor:  "#0F22C2",
                BorderColor0: "#C2BA0F", 
                BorderWidth: 4,
            }),
        )

    kline.SetXAxis(x).AddSeries("kline", y)
    f, _ := os.Create("kline_all.html")
    kline.Render(f)
    var b bytes.Buffer
    err := kline.Render(&b)
    if err != nil {
        log.Fatal(err)
    }

    return b.String()

}
Koooooo-7 commented 1 month ago

Hi @vishnukumarkvs ,plz upgrade to the latest version and try again, it should work after I tested in #461 .