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 BackgroundColor Color
// The flag for show symbol of line, set this to *false will hide symbol // The flag for show symbol of line, set this to *false will hide symbol
SymbolShow *bool SymbolShow *bool
// The stroke width of line chart
LineStrokeWidth float64
// The child charts // The child charts
Children []ChartOption Children []ChartOption
} }

View file

@ -381,6 +381,7 @@ func Render(opt ChartOption, opts ...OptionFunc) (*Painter, error) {
Font: opt.font, Font: opt.font,
XAxis: opt.XAxis, XAxis: opt.XAxis,
SymbolShow: opt.SymbolShow, SymbolShow: opt.SymbolShow,
StrokeWidth: opt.LineStrokeWidth,
}).render(renderResult, lineSeriesList) }).render(renderResult, lineSeriesList)
return err return err
}) })

View file

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

View file

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