feat: support mulit y axis
This commit is contained in:
parent
c0bb1654c2
commit
fd05250305
16 changed files with 393 additions and 96 deletions
27
bar_chart.go
27
bar_chart.go
|
|
@ -37,7 +37,7 @@ func barChartRender(opt ChartOption, result *basicRenderResult) (*Draw, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
yRange := result.yRange
|
||||
// yRange := result.yRange
|
||||
xRange := result.xRange
|
||||
x0, x1 := xRange.GetRange(0)
|
||||
width := int(x1 - x0)
|
||||
|
|
@ -50,7 +50,7 @@ func barChartRender(opt ChartOption, result *basicRenderResult) (*Draw, error) {
|
|||
// 总的宽度-两个margin-(总数-1)的barMargin
|
||||
barWidth := (width - 2*margin - barMargin*(seriesCount-1)) / len(opt.SeriesList)
|
||||
|
||||
barMaxHeight := yRange.Size
|
||||
barMaxHeight := result.getYRange(0).Size
|
||||
theme := NewTheme(opt.Theme)
|
||||
|
||||
seriesNames := opt.Legend.Data
|
||||
|
|
@ -58,6 +58,9 @@ func barChartRender(opt ChartOption, result *basicRenderResult) (*Draw, error) {
|
|||
r := d.Render
|
||||
|
||||
for i, series := range opt.SeriesList {
|
||||
yRange := result.getYRange(series.YAxisIndex)
|
||||
points := make([]Point, len(series.Data))
|
||||
seriesColor := theme.GetSeriesColor(i)
|
||||
for j, item := range series.Data {
|
||||
x0, _ := xRange.GetRange(j)
|
||||
x := int(x0)
|
||||
|
|
@ -67,26 +70,32 @@ func barChartRender(opt ChartOption, result *basicRenderResult) (*Draw, error) {
|
|||
}
|
||||
|
||||
h := int(yRange.getHeight(item.Value))
|
||||
fillColor := theme.GetSeriesColor(i)
|
||||
fillColor := seriesColor
|
||||
if !item.Style.FillColor.IsZero() {
|
||||
fillColor = item.Style.FillColor
|
||||
}
|
||||
|
||||
top := barMaxHeight - h
|
||||
d.Bar(chart.Box{
|
||||
Top: barMaxHeight - h,
|
||||
Top: top,
|
||||
Left: x,
|
||||
Right: x + barWidth,
|
||||
Bottom: barMaxHeight - 1,
|
||||
}, BarStyle{
|
||||
FillColor: fillColor,
|
||||
})
|
||||
// 用于生成marker point
|
||||
points[j] = Point{
|
||||
// 居中的位置
|
||||
X: x + barWidth>>1,
|
||||
Y: top,
|
||||
}
|
||||
if !series.Label.Show {
|
||||
continue
|
||||
}
|
||||
text := NewValueLabelFormater(seriesNames, series.Label.Formatter)(i, item.Value, -1)
|
||||
labelStyle := chart.Style{
|
||||
FontColor: theme.GetTextColor(),
|
||||
FontSize: 10,
|
||||
FontSize: labelFontSize,
|
||||
Font: opt.Font,
|
||||
}
|
||||
if !series.Label.Color.IsZero() {
|
||||
|
|
@ -96,6 +105,12 @@ func barChartRender(opt ChartOption, result *basicRenderResult) (*Draw, error) {
|
|||
textBox := r.MeasureText(text)
|
||||
d.text(text, x+(barWidth-textBox.Width())>>1, barMaxHeight-h-5)
|
||||
}
|
||||
markPointRender(d, markPointRenderOption{
|
||||
FillColor: seriesColor,
|
||||
Font: opt.Font,
|
||||
Points: points,
|
||||
Series: &series,
|
||||
})
|
||||
}
|
||||
|
||||
return result.d, nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue