Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vishnukumarkvs opened this issue Jan 1, 2024 · 0 comments
Labels
need investigation Need investigation about this issue

Comments

@vishnukumarkvs
Copy link

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 Koooooo-7 added the need investigation Need investigation about this issue label Jan 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need investigation Need investigation about this issue
Projects
None yet
Development

No branches or pull requests

2 participants