Keel v0.5.1 中文 GitHub

CandlestickChart

Live example: a real Keel application compiled to WebAssembly. Interact with it here. The initial download is about 10 MB.Open full screen
Example sourceGo · Copyable

This is the complete source for the gallery example above.examples/components/candlestick_chart.go

Reuse the component construction and Render methods in a scaffolded project. The example’s registerSection and shared helpers are provided by the component gallery.

package main

import (
	"github.com/dyike/keel/ui/core"
	"github.com/dyike/keel/ui/el"
	"github.com/dyike/keel/ui/kit"
)

func init() {
	registerSection("candlestick_chart", "charts", func() core.Widget {
		chart := kit.CandlestickChart(
			kit.Candle{Label: demoText("Monday", "周一"), Open: 100, High: 112, Low: 98, Close: 108},
			kit.Candle{Label: demoText("Tuesday", "周二"), Open: 108, High: 115, Low: 103, Close: 105},
			kit.Candle{Label: demoText("Wednesday", "周三"), Open: 105, High: 109, Low: 99, Close: 105},
			kit.Candle{Label: demoText("Thursday", "周四"), Open: 105, High: 121, Low: 104, Close: 118},
			kit.Candle{Label: demoText("Friday", "周五"), Open: 118, High: 120, Low: 106, Close: 109},
		).Title(demoText("OHLC · Hollow rising / filled falling", "开高低收 · 空心上涨 / 实心下跌")).Height(280)
		return el.Embed(el.ViewFunc(func(cx *el.Context) el.Element {
			return el.Div().P(24).W(el.Dp(600)).MaxW(el.Full).Child(chart.Render(cx))
		}))
	})
}

Displays the opening, high, low and closing values in the order they are passed in.

chart := kit.CandlestickChart(
    kit.Candle{Label: "Monday", Open: 10, High: 14, Low: 8, Close: 12},
    kit.Candle{Label: "Tuesday", Open: 12, High: 15, Low: 9, Close: 10},
).Title("Price").Height(240)

Use the success-colored hollow real body when rising, use the dangerous-colored solid real body when falling, and display horizontal lines when flat. Direction is also expressed by shape. The original OHLC value can be read by hovering, and the data table can be read by keyboard operation and Agent.

SetData Copy data. The four values must be limited and meet the requirement that the lowest value is not higher than the opening and closing prices, and the highest value is not lower than the opening and closing prices; a gap is left for invalid data, and the table displays —. Negative values are supported; chart does not assume data comes from stocks. Format(fn) modifies the numerical format, SetDisabled disables interaction.

Dense data is bucketed by horizontal pixels, retaining the first valid opening, the last valid closing, the highest price and the lowest price. All invalid buckets are left empty; buckets containing some invalid data are aggregated according to valid data. Data tables and hovers still use the original data and are not affected by plot aggregation.

Agent: Outer layer figure, the name is the title, and each row of the table is arranged by category, open, high, low, and close. Frame column names follow the locale.

Verify: go run ./examples/components -section candlestick_chart, add -theme dark to check the dark theme. Tests cover data copying, illegal relationships, non-finite numbers, negative extreme value aggregation, hover, disable and Agent data tables.