feat: support mark point for line chart

This commit is contained in:
vicanso 2022-02-08 23:16:30 +08:00
parent 524eb79a8e
commit c0bb1654c2
11 changed files with 148 additions and 16 deletions

View file

@ -23,6 +23,8 @@
package charts
import (
"strings"
"github.com/wcharczuk/go-chart/v2"
)
@ -33,6 +35,8 @@ type YAxisOption struct {
Max *float64
// Hidden y axis
Hidden bool
// Formatter for y axis text value
Formatter string
}
const YAxisWidth = 40
@ -40,7 +44,15 @@ const YAxisWidth = 40
func drawYAxis(p *Draw, opt *ChartOption, xAxisHeight int, padding chart.Box) (*Range, error) {
theme := NewTheme(opt.Theme)
yRange := opt.getYRange(0)
data := NewAxisDataListFromStringList(yRange.Values())
values := yRange.Values()
formatter := opt.YAxis.Formatter
if len(formatter) != 0 {
for index, text := range values {
values[index] = strings.ReplaceAll(formatter, "{value}", text)
}
}
data := NewAxisDataListFromStringList(values)
style := AxisOption{
Position: PositionLeft,
BoundaryGap: FalseFlag(),