feat: support stroke width of line chart

This commit is contained in:
vicanso 2022-07-28 20:49:00 +08:00
parent 817fceff73
commit e530adccb6
4 changed files with 15 additions and 5 deletions

View file

@ -64,6 +64,8 @@ type ChartOption struct {
BackgroundColor Color
// The flag for show symbol of line, set this to *false will hide symbol
SymbolShow *bool
// The stroke width of line chart
LineStrokeWidth float64
// The child charts
Children []ChartOption
}

View file

@ -377,10 +377,11 @@ func Render(opt ChartOption, opts ...OptionFunc) (*Painter, error) {
if len(lineSeriesList) != 0 {
handler.Add(func() error {
_, err := NewLineChart(p, LineChartOption{
Theme: opt.theme,
Font: opt.font,
XAxis: opt.XAxis,
SymbolShow: opt.SymbolShow,
Theme: opt.theme,
Font: opt.font,
XAxis: opt.XAxis,
SymbolShow: opt.SymbolShow,
StrokeWidth: opt.LineStrokeWidth,
}).render(renderResult, lineSeriesList)
return err
})

View file

@ -96,6 +96,7 @@ func main() {
Bottom: 10,
}
opt.SymbolShow = charts.FalseFlag()
opt.LineStrokeWidth = 1
},
)

View file

@ -62,6 +62,8 @@ type LineChartOption struct {
Legend LegendOption
// The flag for show symbol of line, set this to *false will hide symbol
SymbolShow *bool
// The stroke width of line
StrokeWidth float64
// background is filled
backgroundIsFilled bool
}
@ -95,12 +97,16 @@ func (l *lineChart) render(result *defaultRenderResult, seriesList SeriesList) (
markPointPainter,
markLinePainter,
}
strokeWidth := opt.StrokeWidth
if strokeWidth == 0 {
strokeWidth = defaultStrokeWidth
}
for index := range seriesList {
series := seriesList[index]
seriesColor := opt.Theme.GetSeriesColor(series.index)
drawingStyle := Style{
StrokeColor: seriesColor,
StrokeWidth: defaultStrokeWidth,
StrokeWidth: strokeWidth,
}
seriesPainter.SetDrawingStyle(drawingStyle)